-
Notifications
You must be signed in to change notification settings - Fork 45
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
[iree-prof-tools] Make model-explorer interacting with editor. #246
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few minor comments.
Looks great. Thanks!
@@ -3,15 +3,23 @@ import {convertMlirToJsonIfNecessary} from './mlirUtil'; | |||
import {WebviewPanelForModelExplorer} from './modelExplorer'; | |||
|
|||
export function activate(context: vscode.ExtensionContext) { | |||
const modelExplorers = new Map<string, WebviewPanelForModelExplorer>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe modelToPanelMap
or just panelMap
better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
constructor(graphCollection: any) { | ||
this.byId = new Map<string, any>(); | ||
this.byLabel = new Map<string, any[]>(); | ||
for (let graph of graphCollection.graphs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended to look up across multiple graphs? Is the map to be unique to a graph? What happens when there is a same ID used by two different graphs?
IOW, is the node ID unique across multiple graphs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear if it should be unique within a graph collection or within a graph. Added a TODO.
// Gets a node or undefined if not found with node label. | ||
getNodeByLabel(nodeLabel: string): any | undefined { | ||
const nodes = this.byLabel.get(nodeLabel); | ||
return nodes && nodes.length > 0 ? nodes[0] : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we return the first node only? We may change the function name by getFirstNodeByLabel
if the user site expects the first node only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// Find all matches with node label. | ||
const document = this.editor.document; | ||
const selections: vscode.Selection[] = []; | ||
for (const match of document.getText().matchAll(RegExp(nodeLabel, 'g'))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may have a performance problem, but you can make it better later.
This is where LSP may be helpful too. (Assuming LSP also bookkeeping the source location in the editor.) Otherwise, we need to come up with a solution that caches the locations of symbols at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I plan to add source line:char info in graph json. This is for the case when json doesn't have that. Added a TODO.
1) Updated README.md with new mode-explorer package name. 2) "Explore Model: Focus" command moves focus on a node in the model explorer whose node label matches with the word at the current cursor's position in the editor. 3) When a node is focused in the model explorer, corresponding areas in the editor are highlighted. Signed-off-by: Byungchul Kim <byungchul@google.com>
explorer whose node label matches with the word at the current
cursor's position in the editor.
the editor are highlighted.