Skip to content

Commit 2b6475e

Browse files
Migrate text fragment to scm (#2336)
## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [ ] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet --------- Co-authored-by: Pokey Rule <[email protected]>
1 parent 6523482 commit 2b6475e

File tree

15 files changed

+78
-172
lines changed

15 files changed

+78
-172
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: ruby
2+
command:
3+
version: 7
4+
spokenForm: change round
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: surroundingPair, delimiter: parentheses}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: "# (aaa)"
15+
selections:
16+
- anchor: {line: 0, character: 3}
17+
active: {line: 0, character: 3}
18+
marks: {}
19+
finalState:
20+
documentContents: "# "
21+
selections:
22+
- anchor: {line: 0, character: 2}
23+
active: {line: 0, character: 2}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
leadingMatcher,
77
matcher,
88
trailingMatcher,
9-
typeMatcher,
109
conditionMatcher,
1110
patternMatcher,
1211
} from "../util/nodeMatchers";
@@ -134,7 +133,6 @@ const getMapMatchers = {
134133
(node: SyntaxNode) => node.childForFieldName("initializer"),
135134
]),
136135
),
137-
string: typeMatcher("string_literal"),
138136
};
139137

140138
const nodeMatchers: Partial<
@@ -169,7 +167,6 @@ const nodeMatchers: Partial<
169167
),
170168
namedFunction: NAMED_FUNCTION_TYPES,
171169
functionName: NAMED_FUNCTION_TYPES.map((t) => t + "[name]"),
172-
comment: "comment",
173170
regularExpression: "regex",
174171
type: trailingMatcher(["*[type]"]),
175172
name: [

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function getNodeMatcher(
3737
const matcher = matchers[scopeTypeType];
3838

3939
if (matcher == null) {
40-
return notSupported;
40+
return notSupported(scopeTypeType);
4141
}
4242

4343
if (includeSiblings) {

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

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

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { SimpleScopeTypeType } from "@cursorless/common";
2+
import type { SyntaxNode } from "web-tree-sitter";
3+
import { NodeMatcherAlternative } from "../typings/Types";
4+
import { patternFinder } from "../util/nodeFinders";
15
import {
26
ancestorChainNodeMatcher,
37
argumentMatcher,
@@ -9,11 +13,6 @@ import {
913
patternMatcher,
1014
trailingMatcher,
1115
} from "../util/nodeMatchers";
12-
import { NodeMatcherAlternative, SelectionWithEditor } from "../typings/Types";
13-
import { SimpleScopeTypeType } from "@cursorless/common";
14-
import type { SyntaxNode } from "web-tree-sitter";
15-
import { getNodeRange } from "../util/nodeSelectors";
16-
import { patternFinder } from "../util/nodeFinders";
1716

1817
// Generated by the following command:
1918
// curl https://raw.githubusercontent.com/tree-sitter/tree-sitter-ruby/1ebfdb288842dae5a9233e2509a135949023dd82/src/node-types.json \
@@ -161,7 +160,6 @@ const nodeMatchers: Partial<
161160
1,
162161
),
163162
),
164-
string: "string",
165163
functionName: ["method[name]", "singleton_method[name]"],
166164
anonymousFunction: cascadingMatcher(
167165
patternMatcher("lambda", "do_block"),
@@ -194,14 +192,3 @@ const nodeMatchers: Partial<
194192
collectionItem: argumentMatcher(...mapTypes, ...listTypes),
195193
};
196194
export const patternMatchers = createPatternMatchers(nodeMatchers);
197-
198-
export function stringTextFragmentExtractor(
199-
node: SyntaxNode,
200-
_selection: SelectionWithEditor,
201-
) {
202-
if (node.type === "string_content" || node.type === "heredoc_content") {
203-
return getNodeRange(node);
204-
}
205-
206-
return null;
207-
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ const nodeMatchers: Partial<
146146
],
147147
1,
148148
),
149-
string: ["raw_string_literal", "string_literal"],
150149
condition: cascadingMatcher(
151150
patternMatcher("while_expression[condition]", "if_expression[condition]"),
152151
matcher(
@@ -159,7 +158,6 @@ const nodeMatchers: Partial<
159158
),
160159
functionCall: ["call_expression", "macro_invocation", "struct_expression"],
161160
functionCallee: "call_expression[function]",
162-
comment: ["line_comment", "block_comment"],
163161
list: ["array_expression", "tuple_expression"],
164162
collectionItem: argumentMatcher(
165163
"array_expression",

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ const nodeMatchers: Partial<
2121
"trait_definition[name]",
2222
],
2323

24-
string: ["interpolated_string_expression", "string"],
25-
comment: "comment",
26-
2724
// list.size(), does not count foo.size (field_expression), or foo size (postfix_expression)
2825
functionCall: "call_expression",
2926
namedFunction: "function_definition",

packages/cursorless-engine/src/processTargets/modifiers/surroundingPair/index.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import {
22
ComplexSurroundingPairName,
3-
Selection,
43
SurroundingPairScopeType,
54
} from "@cursorless/common";
65
import type { SyntaxNode } from "web-tree-sitter";
76
import { LanguageDefinitions } from "../../../languages/LanguageDefinitions";
8-
import getTextFragmentExtractor from "../../../languages/getTextFragmentExtractor";
97
import { Target } from "../../../typings/target.types";
108
import { SurroundingPairTarget } from "../../targets";
119
import { getContainingScopeTarget } from "../getContainingScopeTarget";
@@ -117,21 +115,7 @@ function processSurroundingPairCore(
117115
return containingScope?.[0].contentRange;
118116
}
119117

120-
// Then try to use the legacy text fragment extractor if it exists
121-
const textFragmentExtractor = getTextFragmentExtractor(document.languageId);
122-
123-
if (textFragmentExtractor == null) {
124-
// If the text fragment extractor doesn't exist, or if it explicitly is
125-
// set to `null`, then we just use text-based algorithm on entire document
126-
return document.range;
127-
}
128-
129-
const selectionWithEditor = {
130-
editor,
131-
selection: new Selection(range.start, range.end),
132-
};
133-
134-
return textFragmentExtractor(node, selectionWithEditor);
118+
return document.range;
135119
})();
136120

137121
if (textFragmentRange != null) {

packages/cursorless-engine/src/util/nodeMatchers.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,11 @@ export function cascadingMatcher(...matchers: NodeMatcher[]): NodeMatcher {
169169
};
170170
}
171171

172-
export const notSupported: NodeMatcher = (
173-
_selection: SelectionWithEditor,
174-
_node: SyntaxNode,
175-
) => {
176-
throw new Error("Node type not supported");
177-
};
172+
export function notSupported(scopeTypeType: SimpleScopeTypeType): NodeMatcher {
173+
return (_selection: SelectionWithEditor, _node: SyntaxNode) => {
174+
throw new Error(`Node type '${scopeTypeType}' not supported`);
175+
};
176+
}
178177

179178
export function createPatternMatchers(
180179
nodeMatchers: Partial<Record<SimpleScopeTypeType, NodeMatcherAlternative>>,

queries/c.scm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
(if_statement) @ifStatement
22

3-
(string_literal) @string @textFragment
3+
(
4+
(string_literal) @string @textFragment
5+
(#child-range! @textFragment 0 -1 true true)
6+
)
47
(comment) @comment @textFragment

0 commit comments

Comments
 (0)