Skip to content

Commit bb8a4cf

Browse files
committed
Add function walkTreeCollecting
1 parent 5b55ec8 commit bb8a4cf

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

server/src/server.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,25 @@ function walkTree(
271271
}
272272
}
273273

274+
function walkTreeCollecting<R>(
275+
node: SyntaxNode,
276+
callback: (node: SyntaxNode) => R,
277+
): R[] {
278+
let results: R[] = [];
279+
let stack: SyntaxNode[] = [node];
280+
while (stack.length > 0) {
281+
let node: SyntaxNode = stack.pop() as SyntaxNode;
282+
results.push(callback(node));
283+
for (let i = node.namedChildCount - 1; i >= 0; i--) {
284+
const child = node.namedChild(i);
285+
if (child) {
286+
stack.push(child);
287+
}
288+
}
289+
}
290+
return results;
291+
}
292+
274293
function limitDiagnostics(
275294
diagnostics: Diagnostic[],
276295
maxNumberOfProblems: number

0 commit comments

Comments
 (0)