From 315e5ef74587bae3aaee7ddde4f26eeaba28d756 Mon Sep 17 00:00:00 2001 From: Samodya Abeysiriwardane Date: Wed, 11 Oct 2023 23:03:59 -0500 Subject: [PATCH] Add click to open file support from stack trace view --- DEVELOPMENT.md | 22 ++++++++++++++++------ README.md | 1 + src/editor-provider.ts | 22 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 578ded2..332c647 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -64,22 +64,32 @@ We use a simple RPC mechanism to communicate between VSCode and Speedscope. ``` Speedscope -> VSCode { -clientEvent: 'ready' + clientEvent: 'ready' } VSCode -> Speedscope { -serverCommand: 'openFile', -filename: 'simple.prof', -docbytes: Uint8Array(...) + serverCommand: 'openFile', + filename: 'simple.prof', + docbytes: Uint8Array(...) } Speedscope -> VSCode { -clientEvent: 'opennedFile', + clientEvent: 'opennedFile', } or { -clientEvent: 'error', + clientEvent: 'error', +} + +Speedscope -> VSCode +{ + clientCommand: 'openFile', + args: { + file: string, + line: number, + col: number, + } } ``` diff --git a/README.md b/README.md index 86b0d50..7e1ec20 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ This extension extends [speedscope](https://github.com/jlfwong/speedscope) to be - Support opening remote files - Use "Open with..." from VSCode File Explorer like a local file - Open a Speedscope view with command: `speedscope-in-vscode.openSpeedscope` +- Click to open linked files in the stacktrace view (if relative path assume it is relative to the file being viewed) ### TODO diff --git a/src/editor-provider.ts b/src/editor-provider.ts index 9156b07..742e11d 100644 --- a/src/editor-provider.ts +++ b/src/editor-provider.ts @@ -123,6 +123,28 @@ export class SpeedscopeEditorProvider } } else if (e.clientEvent === "error") { this.logger.show(); + } else if (e.clientCommand === "openFile") { + let fileUri: vscode.Uri; + if (e.args.file.startsWith("/") || e.args.file[1] === ":") { + fileUri = vscode.Uri.file(e.args.file); + } else { + // If relative path, assume it is relative to the current document + fileUri = vscode.Uri.joinPath(document.uri, "..", e.args.file); + } + await vscode.commands.executeCommand("vscode.open", fileUri, { + preview: false, + }); + let editor = vscode.window.activeTextEditor; + if (!editor) { + return; + } + var position = new vscode.Position( + (e.args.line ?? 1) - 1, + (e.args.col ?? 1) - 1, + ); + editor.selections = [new vscode.Selection(position, position)]; + var range = new vscode.Range(position, position); + editor.revealRange(range); } });