From 1ec22db9d907507a545996265e921582c4703a28 Mon Sep 17 00:00:00 2001 From: Greg Savin Date: Fri, 18 Oct 2024 16:28:04 -0700 Subject: [PATCH 1/7] Trying to get 'go to source file' functionality wiggling. --- .../src/messages/vscode-message-manager.ts | 8 +++++++- ...xplorer-properties-view-webview-provider.ts | 18 ++++++++++++++++++ ...vscode-trace-explorer-properties-widget.tsx | 5 +++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/vscode-trace-common/src/messages/vscode-message-manager.ts b/vscode-trace-common/src/messages/vscode-message-manager.ts index 288830d..1fb8ec2 100644 --- a/vscode-trace-common/src/messages/vscode-message-manager.ts +++ b/vscode-trace-common/src/messages/vscode-message-manager.ts @@ -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', + GO_TO_SOURCE_FILE: 'goToSourceFile' }; export class VsCodeMessageManager extends Messages.MessageManager { @@ -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 }); } + + goToSourceFile(path : string, line : number): void { + const data = JSON.stringify({path : path, line : line}); + vscode.postMessage({ command: VSCODE_MESSAGES.GO_TO_SOURCE_FILE, data: data }); + } } diff --git a/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts b/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts index 112c0c6..994e278 100644 --- a/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts +++ b/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts @@ -33,6 +33,24 @@ export class TraceExplorerItemPropertiesProvider extends AbstractTraceExplorerPr } } }); + + this._view?.webview?.onDidReceiveMessage( + (message) => { + const command = message.command; + const data = message.data; + switch (command) { + case VSCODE_MESSAGES.GO_TO_SOURCE_FILE: + vscode.workspace.openTextDocument(data.path).then( + (x) => { + const text = x.getText(); + console.log(text); + } + ); + break; + } + } + ); + signalManager().on(Signals.ITEM_PROPERTIES_UPDATED, this.handleUpdatedProperties); signalManager().on(Signals.EXPERIMENT_SELECTED, this.handleExperimentChanged); signalManager().on(Signals.CLOSE_TRACEVIEWERTAB, this.handleTabClosed); diff --git a/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx b/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx index d793957..aa2746f 100644 --- a/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx +++ b/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx @@ -67,8 +67,9 @@ class TraceExplorerProperties extends React.Component<{}, PropertiesViewState> { const { fileLocation, line }: { fileLocation: string; line: string } = JSON.parse( `${e.currentTarget.getAttribute('data-id')}` ); - console.log('filename: ' + fileLocation + ':' + line); - console.log('Source lookup method not implemented'); + // console.log('filename: ' + fileLocation + ':' + line); + // console.log('Source lookup method not implemented'); + this._signalHandler.goToSourceFile(fileLocation, +line); } } From 81dc12091f8f00b90c2f482da67559dd71fa46ce Mon Sep 17 00:00:00 2001 From: Greg Savin Date: Fri, 18 Oct 2024 17:18:24 -0700 Subject: [PATCH 2/7] Now able to open a file editor when clicking on a valid Source cell in ITEM PROPERTIES view. (Not moving to the associated line number yet, however). --- .../src/messages/vscode-message-manager.ts | 2 +- .../trace-explorer-properties-view-webview-provider.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vscode-trace-common/src/messages/vscode-message-manager.ts b/vscode-trace-common/src/messages/vscode-message-manager.ts index 1fb8ec2..e5b70b0 100644 --- a/vscode-trace-common/src/messages/vscode-message-manager.ts +++ b/vscode-trace-common/src/messages/vscode-message-manager.ts @@ -212,7 +212,7 @@ export class VsCodeMessageManager extends Messages.MessageManager { } goToSourceFile(path : string, line : number): void { - const data = JSON.stringify({path : path, line : line}); + const data = {path : path, line : line}; vscode.postMessage({ command: VSCODE_MESSAGES.GO_TO_SOURCE_FILE, data: data }); } } diff --git a/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts b/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts index 994e278..7bb557d 100644 --- a/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts +++ b/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts @@ -40,10 +40,10 @@ export class TraceExplorerItemPropertiesProvider extends AbstractTraceExplorerPr const data = message.data; switch (command) { case VSCODE_MESSAGES.GO_TO_SOURCE_FILE: - vscode.workspace.openTextDocument(data.path).then( - (x) => { - const text = x.getText(); - console.log(text); + const path : string = data.path; + vscode.workspace.openTextDocument(path).then( + (doc) => { + vscode.window.showTextDocument(doc); } ); break; From 82dfa4cec04b339b05bb5e4ca26558b3913afad8 Mon Sep 17 00:00:00 2001 From: Greg Savin Date: Mon, 21 Oct 2024 10:18:40 -0700 Subject: [PATCH 3/7] after source code is opened, position cursor on the source line --- ...race-explorer-properties-view-webview-provider.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts b/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts index 7bb557d..1d74fe6 100644 --- a/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts +++ b/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts @@ -40,10 +40,18 @@ export class TraceExplorerItemPropertiesProvider extends AbstractTraceExplorerPr const data = message.data; switch (command) { case VSCODE_MESSAGES.GO_TO_SOURCE_FILE: + // 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); + (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; From 771a9ed3b1b89de364194d4035f80a98153add51 Mon Sep 17 00:00:00 2001 From: Greg Savin Date: Mon, 21 Oct 2024 15:01:20 -0700 Subject: [PATCH 4/7] Code cleanup in preparation for pull request. --- vscode-trace-common/src/messages/vscode-message-manager.ts | 6 +++--- .../trace-explorer-properties-view-webview-provider.ts | 2 +- .../properties/vscode-trace-explorer-properties-widget.tsx | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/vscode-trace-common/src/messages/vscode-message-manager.ts b/vscode-trace-common/src/messages/vscode-message-manager.ts index e5b70b0..0a5d779 100644 --- a/vscode-trace-common/src/messages/vscode-message-manager.ts +++ b/vscode-trace-common/src/messages/vscode-message-manager.ts @@ -74,7 +74,7 @@ export const VSCODE_MESSAGES = { OUTPUT_DATA_CHANGED: 'outputDataChanged', CONTRIBUTE_CONTEXT_MENU: 'contributeContextMenu', CONTEXT_MENU_ITEM_CLICKED: 'contextMenuItemClicked', - GO_TO_SOURCE_FILE: 'goToSourceFile' + SOURCE_LOOKUP: 'sourceLookup' }; export class VsCodeMessageManager extends Messages.MessageManager { @@ -211,8 +211,8 @@ export class VsCodeMessageManager extends Messages.MessageManager { vscode.postMessage({ command: VSCODE_MESSAGES.CONTEXT_MENU_ITEM_CLICKED, data: data }); } - goToSourceFile(path : string, line : number): void { + sourceLookup(path : string, line : number): void { const data = {path : path, line : line}; - vscode.postMessage({ command: VSCODE_MESSAGES.GO_TO_SOURCE_FILE, data: data }); + vscode.postMessage({ command: VSCODE_MESSAGES.SOURCE_LOOKUP, data: data }); } } diff --git a/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts b/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts index 1d74fe6..37ef5d9 100644 --- a/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts +++ b/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts @@ -39,7 +39,7 @@ export class TraceExplorerItemPropertiesProvider extends AbstractTraceExplorerPr const command = message.command; const data = message.data; switch (command) { - case VSCODE_MESSAGES.GO_TO_SOURCE_FILE: + 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; diff --git a/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx b/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx index aa2746f..35d868c 100644 --- a/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx +++ b/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx @@ -67,9 +67,8 @@ class TraceExplorerProperties extends React.Component<{}, PropertiesViewState> { const { fileLocation, line }: { fileLocation: string; line: string } = JSON.parse( `${e.currentTarget.getAttribute('data-id')}` ); - // console.log('filename: ' + fileLocation + ':' + line); - // console.log('Source lookup method not implemented'); - this._signalHandler.goToSourceFile(fileLocation, +line); + console.log('filename: ' + fileLocation + ':' + line); + this._signalHandler.sourceLookup(fileLocation, +line); } } From 8d60c60a45bd3ddf1ecf4d6bb1c6ca25d676cf6b Mon Sep 17 00:00:00 2001 From: Greg Savin Date: Mon, 21 Oct 2024 15:31:35 -0700 Subject: [PATCH 5/7] Fix lint issue --- vscode-trace-common/src/messages/vscode-message-manager.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vscode-trace-common/src/messages/vscode-message-manager.ts b/vscode-trace-common/src/messages/vscode-message-manager.ts index 0a5d779..36ad9b7 100644 --- a/vscode-trace-common/src/messages/vscode-message-manager.ts +++ b/vscode-trace-common/src/messages/vscode-message-manager.ts @@ -211,8 +211,8 @@ export class VsCodeMessageManager extends Messages.MessageManager { vscode.postMessage({ command: VSCODE_MESSAGES.CONTEXT_MENU_ITEM_CLICKED, data: data }); } - sourceLookup(path : string, line : number): void { - const data = {path : path, line : line}; - vscode.postMessage({ command: VSCODE_MESSAGES.SOURCE_LOOKUP, data: data }); + sourceLookup(path: string, line: number): void { + const data = { path: path, line: line }; + vscode.postMessage({ command: VSCODE_MESSAGES.SOURCE_LOOKUP, data: data }); } } From 68f7b8e490127a55d3701c972672582bf7e47df8 Mon Sep 17 00:00:00 2001 From: Greg Savin Date: Mon, 21 Oct 2024 15:39:57 -0700 Subject: [PATCH 6/7] Fix another lint issue. --- ...plorer-properties-view-webview-provider.ts | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts b/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts index 37ef5d9..b636e12 100644 --- a/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts +++ b/vscode-trace-extension/src/trace-explorer/properties/trace-explorer-properties-view-webview-provider.ts @@ -34,30 +34,27 @@ 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; - } + 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); From f3be358ae5b6d2b51d9665fce589b96e9bd93c15 Mon Sep 17 00:00:00 2001 From: Greg Savin Date: Wed, 20 Nov 2024 15:25:54 -0800 Subject: [PATCH 7/7] Adjust based on review comments. --- .../properties/vscode-trace-explorer-properties-widget.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx b/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx index 35d868c..a99c72b 100644 --- a/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx +++ b/vscode-trace-webviews/src/trace-explorer/properties/vscode-trace-explorer-properties-widget.tsx @@ -6,6 +6,7 @@ /* eslint-disable @typescript-eslint/ban-types */ import React from 'react'; import '../../style/trace-viewer.css'; +import 'traceviewer-react-components/style/trace-explorer.css'; import { VSCODE_MESSAGES, VsCodeMessageManager } from 'vscode-trace-common/lib/messages/vscode-message-manager'; import { ReactItemPropertiesWidget } from 'traceviewer-react-components/lib/trace-explorer/trace-explorer-properties-widget'; import { signalManager } from 'traceviewer-base/lib/signals/signal-manager'; @@ -67,7 +68,6 @@ class TraceExplorerProperties extends React.Component<{}, PropertiesViewState> { const { fileLocation, line }: { fileLocation: string; line: string } = JSON.parse( `${e.currentTarget.getAttribute('data-id')}` ); - console.log('filename: ' + fileLocation + ':' + line); this._signalHandler.sourceLookup(fileLocation, +line); } }