File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ interface SyntaxElement {
2222 parent ?: SyntaxElement ;
2323 children : SyntaxElement [ ] ;
2424
25+ getAncestorCount ( ) : number ;
2526 hover ( ) : Hover | undefined ;
2627 isChildOf ( element : SyntaxElement ) : boolean ;
2728 symbolInformation ( uri : string ) : SymbolInformation | undefined ;
@@ -108,6 +109,27 @@ abstract class BaseElement implements SyntaxElement {
108109
109110 private isIdentifiable = ( o : any ) : o is Identifiable =>
110111 'ambiguousIdentifier' in o ;
112+
113+ private getParent ( ) : BaseElement | undefined {
114+ if ( this . parent ) {
115+ if ( this . parent instanceof BaseElement ) {
116+ return this . parent ;
117+ }
118+ }
119+ }
120+
121+ getAncestorCount ( n = 0 ) : number {
122+ if ( this . _countAncestors === 0 ) {
123+ const pnt = this . getParent ( ) ;
124+ if ( pnt ) {
125+ this . _countAncestors = pnt . getAncestorCount ( n + 1 ) ;
126+ return this . _countAncestors ;
127+ }
128+ }
129+ return this . _countAncestors + n ;
130+ }
131+
132+ toString = ( ) => `${ "-" . repeat ( this . getAncestorCount ( ) ) } ${ this . constructor . name } : ${ this . context . text } ` ;
111133}
112134
113135class UnknownElement extends BaseElement {
You can’t perform that action at this time.
0 commit comments