mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-20 10:19:02 +00:00
fix stack trace linking
This commit is contained in:
committed by
Aaron Munger
parent
e0e31d3b61
commit
6afac1d3f7
@@ -31,7 +31,7 @@ export function formatStackTrace(stack: string) {
|
|||||||
|
|
||||||
const formatSequence = /\u001b\[.+?m/g;
|
const formatSequence = /\u001b\[.+?m/g;
|
||||||
const fileRegex = /File\s+(?:\u001b\[.+?m)?(.+):(\d+)/;
|
const fileRegex = /File\s+(?:\u001b\[.+?m)?(.+):(\d+)/;
|
||||||
const lineNumberRegex = /((?:\u001b\[.+?m)?[ ->]*?)(\d+)(.*)/;
|
const lineNumberRegex = /^((?:\u001b\[.+?m)?[ ->]*?)(\d+)(.*)/;
|
||||||
const cellRegex = /(?<prefix>Cell\s+(?:\u001b\[.+?m)?In\s*\[(?<executionCount>\d+)\],\s*)(?<lineLabel>line (?<lineNumber>\d+)).*/;
|
const cellRegex = /(?<prefix>Cell\s+(?:\u001b\[.+?m)?In\s*\[(?<executionCount>\d+)\],\s*)(?<lineLabel>line (?<lineNumber>\d+)).*/;
|
||||||
// older versions of IPython ~8.3.0
|
// older versions of IPython ~8.3.0
|
||||||
const inputRegex = /(?<prefix>Input\s+?(?:\u001b\[.+?m)(?<cellLabel>In\s*\[(?<executionCount>\d+)\]))(?<postfix>.*)/;
|
const inputRegex = /(?<prefix>Input\s+?(?:\u001b\[.+?m)(?<cellLabel>In\s*\[(?<executionCount>\d+)\]))(?<postfix>.*)/;
|
||||||
@@ -41,7 +41,7 @@ function isIpythonStackTrace(stack: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function stripFormatting(text: string) {
|
function stripFormatting(text: string) {
|
||||||
return text.replace(formatSequence, '');
|
return text.replace(formatSequence, '').trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
type cellLocation = { kind: 'cell'; path: string };
|
type cellLocation = { kind: 'cell'; path: string };
|
||||||
|
|||||||
@@ -88,4 +88,16 @@ suite('StackTraceHelper', () => {
|
|||||||
assert.ok(!/<a href=.*>\d<\/a>/.test(formatted), formatted);
|
assert.ok(!/<a href=.*>\d<\/a>/.test(formatted), formatted);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('IPython stack without line numbers are not linkified', () => {
|
||||||
|
const stack =
|
||||||
|
'\u001b[1;36m Cell \u001b[1;32mIn[6], line 1\u001b[1;36m\u001b[0m\n' +
|
||||||
|
'\u001b[1;33m print(\u001b[0m\n' +
|
||||||
|
'\u001b[1;37m ^\u001b[0m\n' +
|
||||||
|
'\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m incomplete input\n';
|
||||||
|
|
||||||
|
const formattedLines = formatStackTrace(stack).split('\n');
|
||||||
|
assert.ok(/<a href='vscode-notebook-cell.*>/.test(formattedLines[0]), 'line should contain a link: ' + formattedLines[0]);
|
||||||
|
formattedLines.slice(1).forEach(line => assert.ok(!/<a href=.*>/.test(line), 'line should not contain a link: ' + line));
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user