Skip to content

Commit

Permalink
Add click to open file support from stack trace view
Browse files Browse the repository at this point in the history
  • Loading branch information
sransara committed Oct 12, 2023
1 parent 04a08e2 commit 315e5ef
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
22 changes: 16 additions & 6 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
```
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions src/editor-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down

0 comments on commit 315e5ef

Please sign in to comment.