ignore diagnostic-channel-publishers in console.log

This commit is contained in:
Benjamin Pasero 2018-02-27 07:34:09 +01:00
parent edf43bdf45
commit a9b44c2065

View file

@ -69,7 +69,7 @@ export function getFirstFrame(arg0: IRemoteConsoleLog | string): IStackFrame {
// at e.$executeContributedCommand(c:\Users\someone\Desktop\end-js\extension.js:19:17)
const stack = arg0;
if (stack) {
const topFrame = stack.split('\n')[0];
const topFrame = findFirstFrame(stack);
// at [^\/]* => line starts with "at" followed by any character except '/' (to not capture unix paths too late)
// (?:(?:[a-zA-Z]+:)|(?:[\/])|(?:\\\\) => windows drive letter OR unix root OR unc root
@ -88,12 +88,37 @@ export function getFirstFrame(arg0: IRemoteConsoleLog | string): IStackFrame {
return void 0;
}
const IGNORED_FRAMES = [
// this module patches console.log aggressively, (e.g. at Console.originalConsole.(anonymous function)
// [as log] (/Users/bpasero/Development/Microsoft/monaco/extensions/git/node_modules/diagnostic-channel-publishers/dist/src/console.pub.js:42:39))
'diagnostic-channel-publishers'
];
function findFirstFrame(stack: string): string {
if (!stack) {
return stack;
}
let newlineIndex = stack.indexOf('\n');
if (newlineIndex === -1) {
return stack;
}
let candidate = stack.substring(0, newlineIndex);
if (IGNORED_FRAMES.some(frame => candidate.indexOf(frame) >= 0)) {
return findFirstFrame(stack.substr(newlineIndex + 1));
}
return candidate;
}
export function log(entry: IRemoteConsoleLog, label: string): void {
const { args, stack } = parse(entry);
const isOneStringArg = typeof args[0] === 'string' && args.length === 1;
let topFrame = stack && stack.split('\n')[0];
let topFrame = findFirstFrame(stack);
if (topFrame) {
topFrame = `(${topFrame.trim()})`;
}