Skip to content

Commit

Permalink
Started migrating typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Nov 19, 2023
1 parent f577cee commit b74b812
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { stringTextFragmentExtractor as htmlStringTextFragmentExtractor } from "
import { stringTextFragmentExtractor as jsonStringTextFragmentExtractor } from "./json";
import { stringTextFragmentExtractor as rubyStringTextFragmentExtractor } from "./ruby";
import { stringTextFragmentExtractor as scssStringTextFragmentExtractor } from "./scss";
import { stringTextFragmentExtractor as typescriptStringTextFragmentExtractor } from "./typescript";

export type TextFragmentExtractor = (
node: SyntaxNode,
Expand Down Expand Up @@ -136,14 +135,6 @@ const textFragmentExtractors: Record<
"java",
constructHackedStringTextFragmentExtractor("java"),
),
javascript: constructDefaultTextFragmentExtractor(
"javascript",
typescriptStringTextFragmentExtractor,
),
javascriptreact: constructDefaultTextFragmentExtractor(
"javascriptreact",
typescriptStringTextFragmentExtractor,
),
jsonc: constructDefaultTextFragmentExtractor(
"jsonc",
jsonStringTextFragmentExtractor,
Expand All @@ -167,14 +158,6 @@ const textFragmentExtractors: Record<
scssStringTextFragmentExtractor,
),
rust: constructDefaultTextFragmentExtractor("rust"),
typescript: constructDefaultTextFragmentExtractor(
"typescript",
typescriptStringTextFragmentExtractor,
),
typescriptreact: constructDefaultTextFragmentExtractor(
"typescriptreact",
typescriptStringTextFragmentExtractor,
),
xml: constructDefaultTextFragmentExtractor(
"xml",
htmlStringTextFragmentExtractor,
Expand Down
31 changes: 1 addition & 30 deletions packages/cursorless-engine/src/languages/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SimpleScopeTypeType } from "@cursorless/common";
import type { SyntaxNode } from "web-tree-sitter";
import { NodeMatcherAlternative, SelectionWithEditor } from "../typings/Types";
import { NodeMatcherAlternative } from "../typings/Types";
import { patternFinder } from "../util/nodeFinders";
import {
argumentMatcher,
Expand All @@ -14,8 +13,6 @@ import {
import {
childRangeSelector,
extendForwardPastOptional,
getNodeInternalRange,
getNodeRange,
unwrapSelectionExtractor,
} from "../util/nodeSelectors";
import { branchMatcher } from "./branchMatcher";
Expand Down Expand Up @@ -70,7 +67,6 @@ const nodeMatchers: Partial<
> = {
map: mapTypes,
list: listTypes,
string: ["string", "template_string"],
collectionItem: "jsx_attribute",
collectionKey: trailingMatcher(
[
Expand All @@ -81,9 +77,6 @@ const nodeMatchers: Partial<
],
[":"],
),
ifStatement: "if_statement",
comment: "comment",
regularExpression: "regex",
className: ["class_declaration[name]", "class[name]"],
functionCall: ["call_expression", "new_expression"],
functionCallee: cascadingMatcher(
Expand Down Expand Up @@ -133,28 +126,6 @@ const nodeMatchers: Partial<
"export_statement.class", // export default class
],
argumentOrParameter: argumentMatcher("formal_parameters", "arguments"),
// XML, JSX
attribute: ["jsx_attribute"],
};

export const patternMatchers = createPatternMatchers(nodeMatchers);

export function stringTextFragmentExtractor(
node: SyntaxNode,
_selection: SelectionWithEditor,
) {
if (
node.type === "string_fragment" ||
node.type === "regex_pattern" ||
node.type === "jsx_text"
) {
return getNodeRange(node);
}

if (node.type === "template_string") {
// Exclude starting and ending quotation marks
return getNodeInternalRange(node);
}

return null;
}
22 changes: 22 additions & 0 deletions queries/javascript.core.scm
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,25 @@
"{" @value.iteration.start.endOf
"}" @value.iteration.end.startOf
)

[
(string)
(template_string)
] @string

(comment) @comment

(if_statement) @ifStatement

(regex) @regularExpression

[
(string_fragment)
(comment)
(regex_pattern)
] @textFragment

(
(template_string) @textFragment
(#child-range! @textFragment 0 -1 true true)
)
4 changes: 4 additions & 0 deletions queries/javascript.jsx.scm
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,7 @@
"<" @value.iteration.start.endOf
">" @value.iteration.end.startOf
)

(jsx_text) @textFragment

(jsx_attribute) @attribute

0 comments on commit b74b812

Please sign in to comment.