Skip to content

Commit 90b6fcf

Browse files
Migrate lambda
1 parent 54905f6 commit 90b6fcf

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { SimpleScopeTypeType } from "@cursorless/common";
2-
import type { Node } from "web-tree-sitter";
32
import type { NodeMatcherAlternative } from "../typings/Types";
43
import { patternFinder } from "../util/nodeFinders";
54
import {
@@ -8,7 +7,6 @@ import {
87
cascadingMatcher,
98
createPatternMatchers,
109
leadingMatcher,
11-
matcher,
1210
patternMatcher,
1311
trailingMatcher,
1412
} from "../util/nodeMatchers";
@@ -130,25 +128,6 @@ const assignmentOperators = [
130128
];
131129
const mapKeyValueSeparators = [":", "=>"];
132130

133-
function blockFinder(node: Node) {
134-
if (node.type !== "call") {
135-
return null;
136-
}
137-
138-
const receiver = node.childForFieldName("receiver");
139-
const method = node.childForFieldName("method");
140-
const block = node.childForFieldName("block");
141-
142-
if (
143-
(receiver?.text === "Proc" && method?.text === "new") ||
144-
(receiver == null && method?.text === "lambda")
145-
) {
146-
return node;
147-
}
148-
149-
return block;
150-
}
151-
152131
const nodeMatchers: Partial<
153132
Record<SimpleScopeTypeType, NodeMatcherAlternative>
154133
> = {
@@ -162,10 +141,6 @@ const nodeMatchers: Partial<
162141
1,
163142
),
164143
),
165-
anonymousFunction: cascadingMatcher(
166-
patternMatcher("lambda", "do_block"),
167-
matcher(blockFinder),
168-
),
169144
argumentOrParameter: argumentMatcher(
170145
"lambda_parameters",
171146
"method_parameters",

queries/ruby.scm

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,36 @@ operator: [
101101
(_
102102
condition: (_) @condition
103103
) @_.domain
104+
105+
;;!! hi = -> { puts "Hi!" }
106+
;;! ^^^^^^^^^^^^^^^^^
107+
(lambda) @anonymousFunction
108+
109+
;;!! [1,2,3].each do |i| end
110+
;;! ^^^^^^^^^^
111+
(do_block) @anonymousFunction
112+
113+
(call
114+
receiver: (_)? @_dummy_receiver
115+
method: (_)? @_dummy_method
116+
block: (_) @anonymousFunction
117+
(#not-eq? @_dummy_receiver Proc)
118+
(#not-eq? @_dummy_method lambda)
119+
(#not-type? @anonymousFunction do_block)
120+
)
121+
122+
;;!! Proc.new { puts "hi" }
123+
;;! ^^^^^^^^^^^^^^^^^^^^^^
124+
(call
125+
receiver: (_) @_dummy_receiver
126+
method: (_) @_dummy_method
127+
(#eq? @_dummy_receiver Proc)
128+
(#eq? @_dummy_method new)
129+
) @anonymousFunction
130+
131+
;;!! lambda { puts "hi" }
132+
;;! ^^^^^^^^^^^^^^^^^^^^
133+
(call
134+
method: (_) @_dummy
135+
(#eq? @_dummy lambda)
136+
) @anonymousFunction

0 commit comments

Comments
 (0)