Skip to content

Commit b74b812

Browse files
Started migrating typescript
1 parent f577cee commit b74b812

File tree

4 files changed

+27
-47
lines changed

4 files changed

+27
-47
lines changed

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { stringTextFragmentExtractor as htmlStringTextFragmentExtractor } from "
99
import { stringTextFragmentExtractor as jsonStringTextFragmentExtractor } from "./json";
1010
import { stringTextFragmentExtractor as rubyStringTextFragmentExtractor } from "./ruby";
1111
import { stringTextFragmentExtractor as scssStringTextFragmentExtractor } from "./scss";
12-
import { stringTextFragmentExtractor as typescriptStringTextFragmentExtractor } from "./typescript";
1312

1413
export type TextFragmentExtractor = (
1514
node: SyntaxNode,
@@ -136,14 +135,6 @@ const textFragmentExtractors: Record<
136135
"java",
137136
constructHackedStringTextFragmentExtractor("java"),
138137
),
139-
javascript: constructDefaultTextFragmentExtractor(
140-
"javascript",
141-
typescriptStringTextFragmentExtractor,
142-
),
143-
javascriptreact: constructDefaultTextFragmentExtractor(
144-
"javascriptreact",
145-
typescriptStringTextFragmentExtractor,
146-
),
147138
jsonc: constructDefaultTextFragmentExtractor(
148139
"jsonc",
149140
jsonStringTextFragmentExtractor,
@@ -167,14 +158,6 @@ const textFragmentExtractors: Record<
167158
scssStringTextFragmentExtractor,
168159
),
169160
rust: constructDefaultTextFragmentExtractor("rust"),
170-
typescript: constructDefaultTextFragmentExtractor(
171-
"typescript",
172-
typescriptStringTextFragmentExtractor,
173-
),
174-
typescriptreact: constructDefaultTextFragmentExtractor(
175-
"typescriptreact",
176-
typescriptStringTextFragmentExtractor,
177-
),
178161
xml: constructDefaultTextFragmentExtractor(
179162
"xml",
180163
htmlStringTextFragmentExtractor,

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

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { SimpleScopeTypeType } from "@cursorless/common";
2-
import type { SyntaxNode } from "web-tree-sitter";
3-
import { NodeMatcherAlternative, SelectionWithEditor } from "../typings/Types";
2+
import { NodeMatcherAlternative } from "../typings/Types";
43
import { patternFinder } from "../util/nodeFinders";
54
import {
65
argumentMatcher,
@@ -14,8 +13,6 @@ import {
1413
import {
1514
childRangeSelector,
1615
extendForwardPastOptional,
17-
getNodeInternalRange,
18-
getNodeRange,
1916
unwrapSelectionExtractor,
2017
} from "../util/nodeSelectors";
2118
import { branchMatcher } from "./branchMatcher";
@@ -70,7 +67,6 @@ const nodeMatchers: Partial<
7067
> = {
7168
map: mapTypes,
7269
list: listTypes,
73-
string: ["string", "template_string"],
7470
collectionItem: "jsx_attribute",
7571
collectionKey: trailingMatcher(
7672
[
@@ -81,9 +77,6 @@ const nodeMatchers: Partial<
8177
],
8278
[":"],
8379
),
84-
ifStatement: "if_statement",
85-
comment: "comment",
86-
regularExpression: "regex",
8780
className: ["class_declaration[name]", "class[name]"],
8881
functionCall: ["call_expression", "new_expression"],
8982
functionCallee: cascadingMatcher(
@@ -133,28 +126,6 @@ const nodeMatchers: Partial<
133126
"export_statement.class", // export default class
134127
],
135128
argumentOrParameter: argumentMatcher("formal_parameters", "arguments"),
136-
// XML, JSX
137-
attribute: ["jsx_attribute"],
138129
};
139130

140131
export const patternMatchers = createPatternMatchers(nodeMatchers);
141-
142-
export function stringTextFragmentExtractor(
143-
node: SyntaxNode,
144-
_selection: SelectionWithEditor,
145-
) {
146-
if (
147-
node.type === "string_fragment" ||
148-
node.type === "regex_pattern" ||
149-
node.type === "jsx_text"
150-
) {
151-
return getNodeRange(node);
152-
}
153-
154-
if (node.type === "template_string") {
155-
// Exclude starting and ending quotation marks
156-
return getNodeInternalRange(node);
157-
}
158-
159-
return null;
160-
}

queries/javascript.core.scm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,25 @@
418418
"{" @value.iteration.start.endOf
419419
"}" @value.iteration.end.startOf
420420
)
421+
422+
[
423+
(string)
424+
(template_string)
425+
] @string
426+
427+
(comment) @comment
428+
429+
(if_statement) @ifStatement
430+
431+
(regex) @regularExpression
432+
433+
[
434+
(string_fragment)
435+
(comment)
436+
(regex_pattern)
437+
] @textFragment
438+
439+
(
440+
(template_string) @textFragment
441+
(#child-range! @textFragment 0 -1 true true)
442+
)

queries/javascript.jsx.scm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,7 @@
100100
"<" @value.iteration.start.endOf
101101
">" @value.iteration.end.startOf
102102
)
103+
104+
(jsx_text) @textFragment
105+
106+
(jsx_attribute) @attribute

0 commit comments

Comments
 (0)