-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iree-prof-tools] Make model-explorer interacting with editor. (#246)
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>
- Loading branch information
1 parent
fabe743
commit c63d1da
Showing
6 changed files
with
230 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
// Map either by node id or by node label to nodes. | ||
// Note that node ids are unique while node labels are not, i.e. multiple nodes | ||
// may have the same node labels. | ||
// TODO(byungchul): Check if node IDs are unique within a graph collection or | ||
// within a graph. | ||
export class NodeMap { | ||
private byId: Map<string, any>; | ||
private byLabel: Map<string, any[]>; | ||
|
||
constructor(graphCollection: any) { | ||
this.byId = new Map<string, any>(); | ||
this.byLabel = new Map<string, any[]>(); | ||
for (let graph of graphCollection.graphs) { | ||
for (let node of graph.nodes) { | ||
this.byId.set(node.id, node); | ||
const nodes = this.byLabel.get(node.label); | ||
if (nodes) { | ||
nodes.push(node); | ||
} else { | ||
this.byLabel.set(node.label, [node]); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Gets a node or undefined if not found with node ID. | ||
getNodeById(nodeId: string): any | undefined { | ||
return this.byId.get(nodeId); | ||
} | ||
|
||
// Gets the first node or undefined if not found with node label. | ||
getFirstNodeByLabel(nodeLabel: string): any | undefined { | ||
const nodes = this.byLabel.get(nodeLabel); | ||
return nodes && nodes.length > 0 ? nodes[0] : undefined; | ||
} | ||
} | ||
|
||
// Builds NodeMap from a graph JSON file. | ||
// Returns undefined if it fails to parse graph JSON. | ||
export async function buildNodeMap( | ||
modelFile: string | ||
): Promise<NodeMap | undefined> { | ||
if (!modelFile.endsWith('.json')) { | ||
return undefined; | ||
} | ||
|
||
const blob = await vscode.workspace.fs.readFile(vscode.Uri.file(modelFile)); | ||
const graphCollection = JSON.parse(blob.toString()); | ||
return graphCollection ? new NodeMap(graphCollection) : undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters