diff --git a/extensions/notebook-renderers/src/stackTraceHelper.ts b/extensions/notebook-renderers/src/stackTraceHelper.ts index 3228628029d..a43b431fef4 100644 --- a/extensions/notebook-renderers/src/stackTraceHelper.ts +++ b/extensions/notebook-renderers/src/stackTraceHelper.ts @@ -29,14 +29,16 @@ export function formatStackTrace(stack: string) { return cleaned; } +const fileRegex = /^File\s+(.+):\d+/; +const lineNumberRegex = /([ ->]*?)(\d+)(.*)/; +const cellRegex = /^(Cell\s+In\[(\d+)\])(,\s+line \d+)$/; + function isIpythonStackTrace(stack: string) { + // at least one group will point to the Cell within the notebook const cellIdentifier = /^Cell In\[\d+\], line \d+$/gm; return cellIdentifier.test(stack); } -const fileRegex = /^File\s+(.+):\d+/; -const lineNumberRegex = /([ ->]*?)(\d+)(.*)/; - function linkifyStack(stack: string) { const lines = stack.split('\n'); @@ -49,8 +51,12 @@ function linkifyStack(stack: string) { if (fileRegex.test(original)) { const fileMatch = lines[i].match(fileRegex); fileOrCell = fileMatch![1]; - console.log(`matched file ${fileOrCell}`); // REMOVE continue; + } else if (cellRegex.test(original)) { + lines[i] = original.replace(cellRegex, (_s, cellLabel, executionCount, suffix) => { + fileOrCell = `vscode-notebook-cell:?execution=${executionCount}`; + return `${cellLabel}${suffix}`; + }); } else if (!fileOrCell || original.trim() === '') { // we don't have a location, so don't linkify anything fileOrCell = undefined; diff --git a/extensions/notebook-renderers/src/test/stackTraceHelper.test.ts b/extensions/notebook-renderers/src/test/stackTraceHelper.test.ts index b40ec59e652..045d2ed06c6 100644 --- a/extensions/notebook-renderers/src/test/stackTraceHelper.test.ts +++ b/extensions/notebook-renderers/src/test/stackTraceHelper.test.ts @@ -31,6 +31,8 @@ suite('StackTraceHelper', () => { '----> 2 raise Exception\n'; const formatted = formatStackTrace(stack); + assert.ok(formatted.indexOf('Cell In[3]') > 0, formatted); + assert.ok(formatted.indexOf('2') > 0, formatted); assert.ok(formatted.indexOf('2') > 0, formatted); });