54
export function getFirstFrame(stack: string | undefined): IStackFrame | undefined;
55
export function getFirstFrame(arg0: IRemoteConsoleLog | string | undefined): IStackFrame | undefined {
57
return getFirstFrame(parse(arg0!).stack);
58
}
60
>
// Parse a source information out of the stack if we have one. Format can be:
61
>
// at vscode.commands.registerCommand (/Users/someone/Desktop/test-ts/out/src/extension.js:18:17)
62
>
// or
63
>
// at /Users/someone/Desktop/test-ts/out/src/extension.js:18:17
64
>
// or
65
>
// at c:\Users\someone\Desktop\end-js\extension.js:19:17
66
>
// or
67
>
// at e.$executeContributedCommand(c:\Users\someone\Desktop\end-js\extension.js:19:17)
68
>
const stack = arg0;
69
>
if (stack) {
70
>
const topFrame = findFirstFrame(stack);
71
>
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(topFrame || '');
77
>
if (matches && matches.length === 4) {
78
>
return {
79
>
uri: URI.file(matches[1]),
80
>
line: Number(matches[2]),
81
>
column: Number(matches[3])
82
>
};
83
>
}
84
>
}
85
86
return undefined;
87
}
88
89
>
function findFirstFrame(stack: string | undefined): string | undefined {
console.ts
90
>
if (!stack) {
91
return stack;
92
}
94
>
const newlineIndex = stack.indexOf('\n');
95
>
if (newlineIndex === -1) {
96
>
return stack;
97
>
}
98
>
99
>
return stack.substring(0, newlineIndex);
100
>
}
101
102
export function log(entry: IRemoteConsoleLog, label: string): void {