@@ -4,20 +4,28 @@ import { LsStereoTypedNode } from "./structure-tree-manager";
44
55export class SpringNode {
66 constructor ( readonly children : SpringNode [ ] ) { }
7- getTreeItem ( ) : TreeItem {
8- return new TreeItem ( "<node>" , this . computeState ( TreeItemCollapsibleState . Expanded ) ) ;
7+
8+ getTreeItem ( savedState ?: TreeItemCollapsibleState ) : TreeItem {
9+ const defaultState = savedState !== undefined ? savedState : TreeItemCollapsibleState . Collapsed ;
10+ return new TreeItem ( "<node>" , this . computeState ( defaultState ) ) ;
911 }
10- computeState ( defaultState : TreeItemCollapsibleState . Collapsed | TreeItemCollapsibleState . Expanded ) : TreeItemCollapsibleState {
12+
13+ computeState ( defaultState : TreeItemCollapsibleState ) : TreeItemCollapsibleState {
1114 return Array . isArray ( this . children ) && this . children . length ? defaultState : TreeItemCollapsibleState . None ;
1215 }
16+
17+ getNodeId ( ) : string {
18+ return "<base-node>" ;
19+ }
1320}
1421
1522export class StereotypedNode extends SpringNode {
1623 constructor ( private n : LsStereoTypedNode , children : SpringNode [ ] ) {
1724 super ( children ) ;
1825 }
19- getTreeItem ( ) : TreeItem {
20- const item = super . getTreeItem ( ) ;
26+
27+ getTreeItem ( savedState ?: TreeItemCollapsibleState ) : TreeItem {
28+ const item = super . getTreeItem ( savedState ) ;
2129 item . label = this . n . attributes . text ;
2230 item . iconPath = this . computeIcon ( ) ;
2331
@@ -39,6 +47,19 @@ export class StereotypedNode extends SpringNode {
3947 }
4048 return item ;
4149 }
50+
51+ getNodeId ( ) : string {
52+ // Create a unique identifier based on node attributes
53+ // Use text, icon, and location as identifying factors
54+ const textId = this . n . attributes . text || '' ;
55+ const iconId = this . n . attributes . icon || '' ;
56+ const locationId = this . n . attributes . location ?
57+ `${ this . n . attributes . location . uri } :${ this . n . attributes . location . range . start . line } :${ this . n . attributes . location . range . start . character } ` : '' ;
58+ const referenceId = this . n . attributes . reference ? String ( this . n . attributes . reference ) : '' ;
59+
60+ // Create a stable ID that can be used to match nodes across refreshes
61+ return `${ textId } |${ iconId } |${ locationId } |${ referenceId } ` . replace ( / \| + $ / , '' ) ; // Remove trailing separators
62+ }
4263
4364 getReferenceValue ( ) : any {
4465 return this . n . attributes . reference ;
0 commit comments