Skip to content

Commit d021f0b

Browse files
committed
debugging helpers
1 parent 47d46f5 commit d021f0b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

server/src/utils/vbaSyntaxElements.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff 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

113135
class UnknownElement extends BaseElement {

0 commit comments

Comments
 (0)