Skip to content

Commit 816f936

Browse files
Migrate ruby scope implementations (#2949)
1 parent 7054ef7 commit 816f936

File tree

6 files changed

+272
-201
lines changed

6 files changed

+272
-201
lines changed

data/fixtures/recorded/languages/ruby/chuckArg3.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ initialState:
1919
marks: {}
2020
finalState:
2121
documentContents: |
22-
[1, 2, 3].each_with_the_next { |n, | }
22+
[1, 2, 3].each_with_the_next { |n| }
2323
selections:
24-
- anchor: {line: 0, character: 35}
25-
active: {line: 0, character: 35}
24+
- anchor: {line: 0, character: 33}
25+
active: {line: 0, character: 33}

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, `(#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+
* `(#type? @foo string comment)`.
14+
*/
15+
class Type extends QueryPredicateOperator<Type> {
16+
name = "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 Type(),
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 & 188 deletions
This file was deleted.

0 commit comments

Comments
 (0)