handle new URI format from webview

This commit is contained in:
aamunger 2023-10-17 11:18:27 -07:00 committed by Aaron Munger
parent a9ee16c135
commit 55794b6c76
3 changed files with 12 additions and 12 deletions

View file

@ -57,29 +57,29 @@ function linkifyStack(stack: string) {
for (const i in lines) {
const original = lines[i];
console.log(`linkify ${original}`); // REMOVE
if (fileRegex.test(original)) {
const fileMatch = lines[i].match(fileRegex);
fileOrCell = { kind: 'file', path: stripFormatting(fileMatch![1]) };
console.log(`matched file ${fileOrCell}`); // REMOVE
continue;
} else if (cellRegex.test(original)) {
lines[i] = original.replace(cellRegex, (_s, cellLabel, executionCount, suffix) => {
fileOrCell = { kind: 'cell', path: `vscode-notebook-cell:?execution=${stripFormatting(executionCount)}` };
fileOrCell = { kind: 'cell', path: `vscode-notebook-cell:?execution_count=${stripFormatting(executionCount)}` };
return `<a href='${fileOrCell.path}'>${stripFormatting(cellLabel)}</a>${suffix}`;
});
console.log(`matched cell ${fileOrCell}`); // REMOVE
continue;
} else if (inputRegex.test(original)) {
lines[i] = original.replace(inputRegex, (_s, cellLabel, executionCount, suffix) => {
fileOrCell = { kind: 'cell', path: `vscode-notebook-cell:?execution=${stripFormatting(executionCount)}` };
fileOrCell = { kind: 'cell', path: `vscode-notebook-cell:?execution_count=${stripFormatting(executionCount)}` };
return `<a href='${fileOrCell.path}'>${stripFormatting(cellLabel)}</a>${suffix}`;
});
console.log(`matched cell ${fileOrCell}`); // REMOVE
continue;
} else if (!fileOrCell || original.trim() === '') {
// we don't have a location, so don't linkify anything
fileOrCell = undefined;
continue;
} else if (lineNumberRegex.test(original)) {
lines[i] = original.replace(lineNumberRegex, (_s, prefix, num, suffix) => {
@ -87,7 +87,7 @@ function linkifyStack(stack: string) {
`${prefix}<a href='${fileOrCell?.path}:${num}'>${num}</a>${suffix}` :
`${prefix}<a href='${fileOrCell?.path}&line=${num}'>${num}</a>${suffix}`;
});
console.log(`matched line ${lines[i]}`); // REMOVE
continue;
}
}

View file

@ -32,8 +32,8 @@ suite('StackTraceHelper', () => {
'\u001b[1;31mException\u001b[0m\n:';
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&line=2\'>2</a>') > 0, formatted);
assert.ok(formatted.indexOf('<a href=\'vscode-notebook-cell:?execution_count=3\'>Cell In[3]</a>') > 0, formatted);
assert.ok(formatted.indexOf('<a href=\'vscode-notebook-cell:?execution_count=3&line=2\'>2</a>') > 0, formatted);
assert.ok(formatted.indexOf('<a href=\'C:\\venvs\\myLib.py:2\'>2</a>') > 0, formatted);
});
@ -46,8 +46,8 @@ suite('StackTraceHelper', () => {
'\u001b[1;32m----> 2\u001b[0m \u001b[43mmyLib\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mthrowEx\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n';
const formatted = formatStackTrace(stack);
assert.ok(formatted.indexOf('<a href=\'vscode-notebook-cell:?execution=2\'>Input In [2]</a>') > 0, formatted);
assert.ok(formatted.indexOf('<a href=\'vscode-notebook-cell:?execution=2&line=2\'>2</a>') > 0, formatted);
assert.ok(formatted.indexOf('<a href=\'vscode-notebook-cell:?execution_count=2\'>Input In [2]</a>') > 0, formatted);
assert.ok(formatted.indexOf('<a href=\'vscode-notebook-cell:?execution_count=2&line=2\'>2</a>') > 0, formatted);
});
test('IPython stack trace lines without associated location are not linkified', () => {

View file

@ -920,7 +920,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
}
}
const executionMatch = /(?:^|&)execution=([^&]+)/.exec(uri.query);
const executionMatch = /(?:^|&)execution_count=([^&]+)/.exec(uri.query);
const notebookResource = uri.path.length > 0 ? uri : this.documentUri;
if (executionMatch) {
const executionCount = parseInt(executionMatch[1], 10);