Skip to content

Commit eeb5494

Browse files
Migrate lambda
1 parent b3d09fc commit eeb5494

File tree

2 files changed

+29
-49
lines changed

2 files changed

+29
-49
lines changed

packages/cursorless-engine/src/languages/clojure.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -82,35 +82,6 @@ const getValueNodes = (node: Node) => getChildNodesForFieldName(node, "value");
8282
const functionCallPattern = "~quoting_lit.list_lit!";
8383
const functionCallFinder = patternFinder(functionCallPattern);
8484

85-
/**
86-
* Matches a function call if the name of the function is one of the given names
87-
* @param names The acceptable function names
88-
* @returns The function call node if the name matches otherwise null
89-
*/
90-
function functionNameBasedFinder(...names: string[]) {
91-
return (node: Node) => {
92-
const functionCallNode = functionCallFinder(node);
93-
if (functionCallNode == null) {
94-
return null;
95-
}
96-
97-
const functionNode = getValueNodes(functionCallNode)[0];
98-
99-
return names.includes(functionNode?.text) ? functionCallNode : null;
100-
};
101-
}
102-
103-
function functionNameBasedMatcher(...names: string[]) {
104-
return matcher(functionNameBasedFinder(...names));
105-
}
106-
107-
const functionFinder = functionNameBasedFinder("defn", "defmacro");
108-
109-
const functionNameMatcher = chainedMatcher([
110-
functionFinder,
111-
(functionNode) => getValueNodes(functionNode)[1],
112-
]);
113-
11485
const nodeMatchers: Partial<
11586
Record<SimpleScopeTypeType, NodeMatcherAlternative>
11687
> = {
@@ -125,15 +96,11 @@ const nodeMatchers: Partial<
12596
),
12697

12798
functionCall: functionCallPattern,
99+
128100
functionCallee: chainedMatcher([
129101
functionCallFinder,
130102
(functionNode) => getValueNodes(functionNode)[0],
131103
]),
132-
133-
anonymousFunction: cascadingMatcher(
134-
functionNameBasedMatcher("fn"),
135-
patternMatcher("anon_fn_lit"),
136-
),
137104
};
138105

139106
export default createPatternMatchers(nodeMatchers);

queries/clojure.scm

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,6 @@
8080
close: "}" @collectionItem.iteration.end.startOf
8181
) @collectionItem.iteration.domain
8282

83-
;;!! (if true "hello")
84-
;;! ^^^^^^^^^^^^^^^^^
85-
;;! ^^^^
86-
(
87-
(list_lit
88-
value: (_) @_dummy
89-
.
90-
value: (_) @condition
91-
(#text? @_dummy "if" "if-let" "when" "when-let")
92-
) @ifStatement @condition.domain
93-
;; A function call is a list literal which is not quoted
94-
(#not-parent-type? @ifStatement quoting_lit)
95-
)
96-
9783
;;!! (defn foo [] 5)
9884
;;! ^^^^^^^^^^^^^^^
9985
;;! ^^^
@@ -102,8 +88,35 @@
10288
value: (_) @_dummy
10389
.
10490
value: (_) @name @functionName
105-
(#text? @_dummy defn defmacro)
10691
) @namedFunction @name.domain @functionName.domain
92+
(#text? @_dummy defn defmacro)
10793
;; A function call is a list literal which is not quoted
10894
(#not-parent-type? @namedFunction quoting_lit)
10995
)
96+
97+
;;!! (fn [] 5)
98+
;;! ^^^^^^^^^
99+
(
100+
(list_lit
101+
value: (_) @_dummy
102+
) @anonymousFunction
103+
(#text? @_dummy fn)
104+
(#not-parent-type? @anonymousFunction quoting_lit)
105+
)
106+
107+
;;!! #(+ 1 1)
108+
;;! ^^^^^^^^
109+
(anon_fn_lit) @anonymousFunction
110+
111+
;;!! (if true "hello")
112+
;;! ^^^^^^^^^^^^^^^^^
113+
;;! ^^^^
114+
(
115+
(list_lit
116+
value: (_) @_dummy
117+
.
118+
value: (_) @condition
119+
) @ifStatement @condition.domain
120+
(#text? @_dummy "if" "if-let" "when" "when-let")
121+
(#not-parent-type? @ifStatement quoting_lit)
122+
)

0 commit comments

Comments
 (0)