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

[iree-prof-tools] Make model-explorer interacting with editor. #246

Merged
merged 1 commit into from
May 15, 2024

Conversation

protobird-git
Copy link
Collaborator

  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.

Copy link
Member

@okkwon okkwon left a 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>();
Copy link
Member

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.

Copy link
Collaborator Author

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) {
Copy link
Member

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?

Copy link
Collaborator Author

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;
Copy link
Member

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.

Copy link
Collaborator Author

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'))) {
Copy link
Member

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.

Copy link
Collaborator Author

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>
@protobird-git protobird-git merged commit c63d1da into iree-org:main May 15, 2024
2 checks passed
@protobird-git protobird-git deleted the wip branch May 15, 2024 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants