Skip to content

Commit 6027600

Browse files
author
Benjamin Pasero
committed
Console.logs from command handler not linked to origin (fixes microsoft#35140)
1 parent c3beb36 commit 6027600

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

src/vs/base/node/console.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,21 @@ export function getFirstFrame(arg0: IRemoteConsoleLog | string): IStackFrame {
5959
return getFirstFrame(parse(arg0).stack);
6060
}
6161

62-
// Parse a source information out of the stack if we have one. Format:
62+
// Parse a source information out of the stack if we have one. Format can be:
6363
// at vscode.commands.registerCommand (/Users/someone/Desktop/test-ts/out/src/extension.js:18:17)
64+
// or
65+
// at /Users/someone/Desktop/test-ts/out/src/extension.js:18:17
66+
// or
67+
// at c:\Users\someone\Desktop\end-js\extension.js:19:17
68+
// or
69+
// at e.$executeContributedCommand(c:\Users\someone\Desktop\end-js\extension.js:19:17)
6470
const stack = arg0;
6571
if (stack) {
66-
const matches = /.+\((.+):(\d+):(\d+)\)/.exec(stack);
72+
// at [^\/]* => line starts with "at" followed by any character except '/' (to not capture unix paths too late)
73+
// (?:(?:[a-zA-Z]+:)|(?:[\/])|(?:\\\\) => windows drive letter OR unix root OR unc root
74+
// (?:.+) => simple pattern for the path, only works because of the line/col pattern after
75+
// :(?:\d+):(?:\d+) => :line:column data
76+
const matches = /at [^\/]*((?:(?:[a-zA-Z]+:)|(?:[\/])|(?:\\\\))(?:.+)):(\d+):(\d+)/.exec(stack);
6777
if (matches.length === 4) {
6878
return {
6979
uri: URI.file(matches[1]),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import * as assert from 'assert';
9+
import { getFirstFrame } from 'vs/base/node/console';
10+
import { normalize } from 'path';
11+
12+
suite('Console', () => {
13+
14+
test('getFirstFrame', function () {
15+
let stack = 'at vscode.commands.registerCommand (/Users/someone/Desktop/test-ts/out/src/extension.js:18:17)';
16+
let frame = getFirstFrame(stack);
17+
18+
assert.equal(frame.uri.fsPath, normalize('/Users/someone/Desktop/test-ts/out/src/extension.js'));
19+
assert.equal(frame.line, 18);
20+
assert.equal(frame.column, 17);
21+
22+
stack = 'at /Users/someone/Desktop/test-ts/out/src/extension.js:18:17';
23+
frame = getFirstFrame(stack);
24+
25+
assert.equal(frame.uri.fsPath, normalize('/Users/someone/Desktop/test-ts/out/src/extension.js'));
26+
assert.equal(frame.line, 18);
27+
assert.equal(frame.column, 17);
28+
29+
stack = 'at c:\\Users\\someone\\Desktop\\end-js\\extension.js:18:17';
30+
frame = getFirstFrame(stack);
31+
32+
assert.equal(frame.uri.fsPath, 'c:\\Users\\someone\\Desktop\\end-js\\extension.js');
33+
assert.equal(frame.line, 18);
34+
assert.equal(frame.column, 17);
35+
36+
stack = 'at e.$executeContributedCommand(c:\\Users\\someone\\Desktop\\end-js\\extension.js:18:17)';
37+
frame = getFirstFrame(stack);
38+
39+
assert.equal(frame.uri.fsPath, 'c:\\Users\\someone\\Desktop\\end-js\\extension.js');
40+
assert.equal(frame.line, 18);
41+
assert.equal(frame.column, 17);
42+
});
43+
});

0 commit comments

Comments
 (0)