MCPcopy Index your code
hub / github.com/cursorless-dev/cursorless / indexNodeFinder

Function indexNodeFinder

src/languages/clojure.ts:48–77  ·  view source on GitHub ↗

* Creates a node finder which will apply a transformation to the index of a * value node and return the node at the given index of the nodes parent * @param parentFinder A finder which will be applied to the parent to determine * whether it is a match * @param indexTransform A function that will

(
  parentFinder: NodeFinder,
  indexTransform: (index: number) => number
)

Source from the content-addressed store, hash-verified

46 * @returns A node finder based on the given description
47 */
48function indexNodeFinder(
49 parentFinder: NodeFinder,
50 indexTransform: (index: number) => number
51) {
52 return (node: SyntaxNode) => {
53 const parent = node.parent;
54
55 if (parent == null || parentFinder(parent) == null) {
56 return null;
57 }
58
59 const valueNodes = getValueNodes(parent);
60
61 const nodeIndex = valueNodes.findIndex(({ id }) => id === node.id);
62
63 if (nodeIndex === -1) {
64 // TODO: In the future we might conceivably try to handle saying "take
65 // item" when the selection is inside a comment between the key and value
66 return null;
67 }
68
69 const desiredIndex = indexTransform(nodeIndex);
70
71 if (desiredIndex === -1) {
72 return null;
73 }
74
75 return valueNodes[desiredIndex];
76 };
77}
78
79function itemFinder() {
80 return indexNodeFinder(

Callers 3

parityNodeFinderFunction · 0.85
itemFinderFunction · 0.85
clojure.tsFile · 0.85

Calls 1

getValueNodesFunction · 0.85

Tested by

no test coverage detected