@@ -3,7 +3,7 @@ import { Location } from "vscode-languageclient";
33import { LsStereoTypedNode } from "./structure-tree-manager" ;
44
55export class SpringNode {
6- constructor ( readonly children : SpringNode [ ] ) { }
6+ constructor ( public children : SpringNode [ ] , private parent ?: SpringNode ) { }
77
88 getTreeItem ( savedState ?: TreeItemCollapsibleState ) : TreeItem {
99 const defaultState = savedState !== undefined ? savedState : TreeItemCollapsibleState . Collapsed ;
@@ -17,11 +17,27 @@ export class SpringNode {
1717 getNodeId ( ) : string {
1818 return "<base-node>" ;
1919 }
20+
21+ protected getParentPath ( ) : string {
22+ if ( ! this . parent ) {
23+ return "" ;
24+ }
25+
26+ const parentText = this . parent . getNodeText ( ) ;
27+ // Recursively get the full path of all ancestors up to the root
28+ const ancestorPath = this . parent . getParentPath ( ) ;
29+
30+ return ancestorPath ? `${ ancestorPath } /${ parentText } ` : parentText ;
31+ }
32+
33+ protected getNodeText ( ) : string {
34+ return "<node>" ;
35+ }
2036}
2137
2238export class StereotypedNode extends SpringNode {
23- constructor ( private n : LsStereoTypedNode , children : SpringNode [ ] ) {
24- super ( children ) ;
39+ constructor ( private n : LsStereoTypedNode , children : SpringNode [ ] , parent ?: SpringNode ) {
40+ super ( children , parent ) ;
2541 }
2642
2743 getTreeItem ( savedState ?: TreeItemCollapsibleState ) : TreeItem {
@@ -49,16 +65,23 @@ export class StereotypedNode extends SpringNode {
4965 }
5066
5167 getNodeId ( ) : string {
52- // Create a unique identifier based on node attributes
53- // Use text, icon, and location as identifying factors
68+ // Create a unique identifier based on node attributes, excluding icon
69+ // Include parent path in the computation for better uniqueness
5470 const textId = this . n . attributes . text || '' ;
55- const iconId = this . n . attributes . icon || '' ;
5671 const locationId = this . n . attributes . location ?
5772 `${ this . n . attributes . location . uri } :${ this . n . attributes . location . range . start . line } :${ this . n . attributes . location . range . start . character } ` : '' ;
5873 const referenceId = this . n . attributes . reference ? String ( this . n . attributes . reference ) : '' ;
5974
60- // Create a stable ID that can be used to match nodes across refreshes
61- return `${ textId } |${ iconId } |${ locationId } |${ referenceId } ` . replace ( / \| + $ / , '' ) ; // Remove trailing separators
75+ // Build the node-specific part of the ID (without icon)
76+ const nodeSpecificId = `${ textId } |${ locationId } |${ referenceId } ` . replace ( / \| + $ / , '' ) ; // Remove trailing separators
77+
78+ // Include parent path for better uniqueness
79+ const parentPath = this . getParentPath ( ) ;
80+ return parentPath ? `${ parentPath } /${ nodeSpecificId } ` : nodeSpecificId ;
81+ }
82+
83+ protected getNodeText ( ) : string {
84+ return this . n . attributes . text || '' ;
6285 }
6386
6487 getReferenceValue ( ) : any {
0 commit comments