Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement source lookup in Item Properties view #276

Merged
merged 8 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion vscode-trace-common/src/messages/vscode-message-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export const VSCODE_MESSAGES = {
RESTORE_COMPLETE: 'restoreComplete',
OUTPUT_DATA_CHANGED: 'outputDataChanged',
CONTRIBUTE_CONTEXT_MENU: 'contributeContextMenu',
CONTEXT_MENU_ITEM_CLICKED: 'contextMenuItemClicked'
CONTEXT_MENU_ITEM_CLICKED: 'contextMenuItemClicked',
SOURCE_LOOKUP: 'sourceLookup'
};

export class VsCodeMessageManager extends Messages.MessageManager {
Expand Down Expand Up @@ -209,4 +210,9 @@ export class VsCodeMessageManager extends Messages.MessageManager {
const data = JSON.stringify(payload);
vscode.postMessage({ command: VSCODE_MESSAGES.CONTEXT_MENU_ITEM_CLICKED, data: data });
}

sourceLookup(path: string, line: number): void {
const data = { path: path, line: line };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I troubleshooting a use case with the Trace Compass server and I noticed that the events table data provider for certain trace types will return a list of source in the form [file1:line1, file2:line2]. Even if it's only one file it will provide it with the brackets. I think when we did this prototype, there was only never the brackets. Anyways, I think for now it's ok to not support the list. I'll need to think about more how to support that better.

Is your format always file:line or is it also [file:line]`, i.e. with brackets?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our format is using file:line only (at least currently).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We support [file:line,file:line,...] in tc for
1- SIMD
2- Heterogeonous snapshot events
3- Recycled trace points (bad practice)
4- Callstacks
5- User defined behaviour.

I would argue that file:line is fine, until there's a demand for more. When that comes, @GregSavin I hope we can solve the issue together (i.e we don't want to break your work)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think I've addressed the immediately actionable review comments. The fact that callstacks can carry source annotations (in a list form) is new to me. Going forward, I'll try to learn more about that specific case (how the data flow works for that), but for now, our only usage of "Source" attribute is as an aspect of our ITmfEvent subclass, and it's only file:line.

vscode.postMessage({ command: VSCODE_MESSAGES.SOURCE_LOOKUP, data: data });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ export class TraceExplorerItemPropertiesProvider extends AbstractTraceExplorerPr
}
}
});

this._view?.webview?.onDidReceiveMessage(message => {
const command = message.command;
const data = message.data;
switch (command) {
case VSCODE_MESSAGES.SOURCE_LOOKUP:
// open an editor window with the file contents,
// reveal the line and position the cursor at the beginning of the line
const path: string = data.path;
vscode.workspace
.openTextDocument(path)
.then(doc => vscode.window.showTextDocument(doc))
.then(editor => {
const zeroBasedLine = data.line - 1;
const range = new vscode.Range(zeroBasedLine, 0, zeroBasedLine, 0);
editor.revealRange(range, vscode.TextEditorRevealType.AtTop);
const selection = new vscode.Selection(zeroBasedLine, 0, zeroBasedLine, 0);
editor.selection = selection;
});
break;
}
});

signalManager().on(Signals.ITEM_PROPERTIES_UPDATED, this.handleUpdatedProperties);
signalManager().on(Signals.EXPERIMENT_SELECTED, this.handleExperimentChanged);
signalManager().on(Signals.CLOSE_TRACEVIEWERTAB, this.handleTabClosed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class TraceExplorerProperties extends React.Component<{}, PropertiesViewState> {
`${e.currentTarget.getAttribute('data-id')}`
);
console.log('filename: ' + fileLocation + ':' + line);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need to keep the console log.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I added the import for the CSS, and removed the console.log().

console.log('Source lookup method not implemented');
this._signalHandler.sourceLookup(fileLocation, +line);
}
}

Expand Down
Loading