MCPcopy Create free account
hub / github.com/cursorless-dev/cursorless / getChildNodesForFieldName

Function getChildNodesForFieldName

src/util/treeSitterUtils.ts:18–38  ·  view source on GitHub ↗
(
  node: SyntaxNode,
  fieldName: string
)

Source from the content-addressed store, hash-verified

16 node.childForFieldName("declarator");
17
18export function getChildNodesForFieldName(
19 node: SyntaxNode,
20 fieldName: string
21): SyntaxNode[] {
22 const treeCursor = node.walk();
23 treeCursor.gotoFirstChild();
24
25 const ret = [];
26
27 let hasNext = true;
28
29 while (hasNext) {
30 if (treeCursor.currentFieldName() === fieldName) {
31 ret.push(treeCursor.currentNode());
32 }
33
34 hasNext = treeCursor.gotoNextSibling();
35 }
36
37 return ret;
38}
39
40/**
41 * Returns a list of the node's ancestors, including the node itself if

Callers 1

getValueNodesFunction · 0.90

Calls 5

gotoFirstChildMethod · 0.80
currentFieldNameMethod · 0.80
currentNodeMethod · 0.80
gotoNextSiblingMethod · 0.80
walkMethod · 0.65

Tested by

no test coverage detected