mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-20 02:08:47 +00:00
linkify stack lines for cell references
This commit is contained in:
committed by
Aaron Munger
parent
2123a011bf
commit
fe8ac3f89e
@@ -29,14 +29,16 @@ export function formatStackTrace(stack: string) {
|
|||||||
return cleaned;
|
return cleaned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fileRegex = /^File\s+(.+):\d+/;
|
||||||
|
const lineNumberRegex = /([ ->]*?)(\d+)(.*)/;
|
||||||
|
const cellRegex = /^(Cell\s+In\[(\d+)\])(,\s+line \d+)$/;
|
||||||
|
|
||||||
function isIpythonStackTrace(stack: string) {
|
function isIpythonStackTrace(stack: string) {
|
||||||
|
// at least one group will point to the Cell within the notebook
|
||||||
const cellIdentifier = /^Cell In\[\d+\], line \d+$/gm;
|
const cellIdentifier = /^Cell In\[\d+\], line \d+$/gm;
|
||||||
return cellIdentifier.test(stack);
|
return cellIdentifier.test(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileRegex = /^File\s+(.+):\d+/;
|
|
||||||
const lineNumberRegex = /([ ->]*?)(\d+)(.*)/;
|
|
||||||
|
|
||||||
function linkifyStack(stack: string) {
|
function linkifyStack(stack: string) {
|
||||||
const lines = stack.split('\n');
|
const lines = stack.split('\n');
|
||||||
|
|
||||||
@@ -49,8 +51,12 @@ function linkifyStack(stack: string) {
|
|||||||
if (fileRegex.test(original)) {
|
if (fileRegex.test(original)) {
|
||||||
const fileMatch = lines[i].match(fileRegex);
|
const fileMatch = lines[i].match(fileRegex);
|
||||||
fileOrCell = fileMatch![1];
|
fileOrCell = fileMatch![1];
|
||||||
console.log(`matched file ${fileOrCell}`); // REMOVE
|
|
||||||
continue;
|
continue;
|
||||||
|
} else if (cellRegex.test(original)) {
|
||||||
|
lines[i] = original.replace(cellRegex, (_s, cellLabel, executionCount, suffix) => {
|
||||||
|
fileOrCell = `vscode-notebook-cell:?execution=${executionCount}`;
|
||||||
|
return `<a href='${fileOrCell}'>${cellLabel}</a>${suffix}`;
|
||||||
|
});
|
||||||
} else if (!fileOrCell || original.trim() === '') {
|
} else if (!fileOrCell || original.trim() === '') {
|
||||||
// we don't have a location, so don't linkify anything
|
// we don't have a location, so don't linkify anything
|
||||||
fileOrCell = undefined;
|
fileOrCell = undefined;
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ suite('StackTraceHelper', () => {
|
|||||||
'----> 2 raise Exception\n';
|
'----> 2 raise Exception\n';
|
||||||
|
|
||||||
const formatted = formatStackTrace(stack);
|
const formatted = formatStackTrace(stack);
|
||||||
|
assert.ok(formatted.indexOf('<a href=\'vscode-notebook-cell:?execution=3\'>Cell In[3]</a>') > 0, formatted);
|
||||||
|
assert.ok(formatted.indexOf('<a href=\'vscode-notebook-cell:?execution=3:2\'>2</a>') > 0, formatted);
|
||||||
assert.ok(formatted.indexOf('<a href=\'C:\\venvs\\myLib.py:2\'>2</a>') > 0, formatted);
|
assert.ok(formatted.indexOf('<a href=\'C:\\venvs\\myLib.py:2\'>2</a>') > 0, formatted);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user