Skip to content

Commit 1bf09e8

Browse files
Migrate statement
1 parent 17f2ad0 commit 1bf09e8

File tree

5 files changed

+126
-136
lines changed

5 files changed

+126
-136
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
* The language IDs that we have full tree-sitter support for using our legacy
33
* modifiers.
44
*/
5-
export const legacyLanguageIds = ["clojure", "latex", "ruby", "rust"] as const;
5+
export const legacyLanguageIds = ["clojure", "latex", "rust"] as const;
66

77
export type LegacyLanguageId = (typeof legacyLanguageIds)[number];

packages/cursorless-engine/src/languages/TreeSitterQuery/queryPredicateOperators.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,24 @@ import { QueryPredicateOperator } from "./QueryPredicateOperator";
77
import { q } from "./operatorArgumentSchemaTypes";
88

99
/**
10-
* A predicate operator that returns true if the node is not of the given type.
11-
* For example, `(not-type? @foo string)` will reject the match if the `@foo`
10+
* A predicate operator that returns true if the node is of the given type.
11+
* For example, `(#is-type? @foo string)` will accept the match if the `@foo`
1212
* capture is a `string` node. It is acceptable to pass in multiple types, e.g.
13-
* `(not-type? @foo string comment)`.
13+
* `(#is-type? @foo string comment)`.
14+
*/
15+
class IsType extends QueryPredicateOperator<IsType> {
16+
name = "is-type?" as const;
17+
schema = z.tuple([q.node, q.string]).rest(q.string);
18+
run({ node }: MutableQueryCapture, ...types: string[]) {
19+
return types.includes(node.type);
20+
}
21+
}
22+
23+
/**
24+
* A predicate operator that returns true if the node is NOT of the given type.
25+
* For example, `(#not-type? @foo string)` will reject the match if the `@foo`
26+
* capture is a `string` node. It is acceptable to pass in multiple types, e.g.
27+
* `(#not-type? @foo string comment)`.
1428
*/
1529
class NotType extends QueryPredicateOperator<NotType> {
1630
name = "not-type?" as const;
@@ -22,9 +36,9 @@ class NotType extends QueryPredicateOperator<NotType> {
2236

2337
/**
2438
* A predicate operator that returns true if the node's parent is not of the
25-
* given type. For example, `(not-parent-type? @foo string)` will reject the
39+
* given type. For example, `(#not-parent-type? @foo string)` will reject the
2640
* match if the `@foo` capture is a child of a `string` node. It is acceptable
27-
* to pass in multiple types, e.g. `(not-parent-type? @foo string comment)`.
41+
* to pass in multiple types, e.g. `(#not-parent-type? @foo string comment)`.
2842
*/
2943
class NotParentType extends QueryPredicateOperator<NotParentType> {
3044
name = "not-parent-type?" as const;
@@ -36,7 +50,7 @@ class NotParentType extends QueryPredicateOperator<NotParentType> {
3650

3751
/**
3852
* A predicate operator that returns true if the node is the nth child of its
39-
* parent. For example, `(is-nth-child? @foo 0)` will reject the match if the
53+
* parent. For example, `(#is-nth-child? @foo 0)` will reject the match if the
4054
* `@foo` capture is not the first child of its parent.
4155
*/
4256
class IsNthChild extends QueryPredicateOperator<IsNthChild> {
@@ -49,7 +63,7 @@ class IsNthChild extends QueryPredicateOperator<IsNthChild> {
4963

5064
/**
5165
* A predicate operator that returns true if the node has more than 1 child of
52-
* type {@link type} (inclusive). For example, `(has-multiple-children-of-type?
66+
* type {@link type} (inclusive). For example, `(#has-multiple-children-of-type?
5367
* @foo bar)` will accept the match if the `@foo` capture has 2 or more children
5468
* of type `bar`.
5569
*/
@@ -374,6 +388,7 @@ class EmptySingleMultiDelimiter extends QueryPredicateOperator<EmptySingleMultiD
374388

375389
export const queryPredicateOperators = [
376390
new Log(),
391+
new IsType(),
377392
new NotType(),
378393
new TrimEnd(),
379394
new DocumentRange(),

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { selectionWithEditorFromRange } from "../util/selectionUtils";
1111
import clojure from "./clojure";
1212
import type { LegacyLanguageId } from "./LegacyLanguageId";
1313
import latex from "./latex";
14-
import { patternMatchers as ruby } from "./ruby";
1514
import rust from "./rust";
1615

1716
export function getNodeMatcher(
@@ -44,7 +43,6 @@ export const languageMatchers: Record<
4443
> = {
4544
clojure,
4645
latex,
47-
ruby,
4846
rust,
4947
};
5048

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

Lines changed: 0 additions & 124 deletions
This file was deleted.

queries/ruby.scm

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,108 @@
11
;; https://github.com/tree-sitter/tree-sitter-ruby/blob/master/src/grammar.json
22

3+
;; Generated by the following command:
4+
;; curl https://raw.githubusercontent.com/tree-sitter/tree-sitter-ruby/1ebfdb288842dae5a9233e2509a135949023dd82/src/node-types.json \
5+
;; | jq '[.[] | select((.type == "_statement" or .type == "_simple_statement") and .type != "_expression") | .subtypes[] | select(.type != "_expression") | .type ]'
6+
[
7+
(alias)
8+
(begin_block)
9+
(end_block)
10+
(if_modifier)
11+
(rescue_modifier)
12+
(undef)
13+
(unless_modifier)
14+
(until_modifier)
15+
(while_modifier)
16+
] @statement
17+
18+
;; Generated by the following command:
19+
;; > curl https://raw.githubusercontent.com/tree-sitter/tree-sitter-ruby/1ebfdb288842dae5a9233e2509a135949023dd82/src/node-types.json \
20+
;; | jq '[.[] | select(.type == _expression or .type == _arg or .type == _primary or .type == _lhs or .type == _simple_numeric or .type == _variable or .type == _nonlocal_variable) | .subtypes[].type | select(startswith(_) | not)] | sort | unique'
21+
(
22+
(_
23+
[
24+
(array)
25+
(assignment)
26+
(begin)
27+
(binary)
28+
(break)
29+
(call)
30+
(case)
31+
(case_match)
32+
(chained_string)
33+
(character)
34+
(class)
35+
(class_variable)
36+
(complex)
37+
(conditional)
38+
(constant)
39+
(delimited_symbol)
40+
(element_reference)
41+
(false)
42+
(float)
43+
(for)
44+
(global_variable)
45+
(hash)
46+
(heredoc_beginning)
47+
(identifier)
48+
(if)
49+
(instance_variable)
50+
(integer)
51+
(lambda)
52+
(method)
53+
(module)
54+
(next)
55+
(nil)
56+
(operator_assignment)
57+
(parenthesized_statements)
58+
(range)
59+
(rational)
60+
(redo)
61+
(regex)
62+
(retry)
63+
(return)
64+
(scope_resolution)
65+
(self)
66+
(simple_symbol)
67+
(singleton_class)
68+
(singleton_method)
69+
(string)
70+
(string_array)
71+
(subshell)
72+
(super)
73+
(symbol_array)
74+
(true)
75+
(unary)
76+
(unless)
77+
(until)
78+
(while)
79+
(yield)
80+
] @statement
81+
) @_dummy
82+
(#is-type?
83+
@_dummy
84+
begin_block
85+
begin
86+
block_body
87+
block
88+
body_statement
89+
do_block
90+
do
91+
else
92+
end_block
93+
ensure
94+
heredoc_beginning
95+
interpolation
96+
lambda
97+
method
98+
parenthesized_statements
99+
program
100+
singleton_class
101+
singleton_method
102+
then
103+
)
104+
)
105+
3106
(comment) @comment @textFragment
4107
(hash) @map
5108
(regex) @regularExpression
@@ -238,5 +341,3 @@ operator: [
238341
) @_dummy
239342
(#empty-single-multi-delimiter! @argumentList.start.endOf @_dummy "" ", " ",\n")
240343
) @argumentList.domain @argumentOrParameter.iteration.domain
241-
242-
;; lambda_parameters

0 commit comments

Comments
 (0)