From dbb5fb8505943652257fb7e18f6be20490a97b24 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 15 May 2024 13:55:04 +0200 Subject: [PATCH] Add scope test machinery for remaining languages (#2326) ## 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 --- .../recorded/languages/cpp/takeComment.yml | 19 ------- .../recorded/languages/cpp/takeIf.yml | 29 ---------- .../recorded/languages/cpp/takeIf2.yml | 29 ---------- .../recorded/languages/cpp/takeString.yml | 24 -------- .../languages/latex/changeComment.yml | 23 -------- .../languages/latex/changeComment2.yml | 21 ------- .../languages/markdown/clearComment.yml | 19 ------- .../recorded/languages/ruby/changeComment.yml | 19 ------- .../languages/ruby/changeComment2.yml | 19 ------- .../languages/ruby/changeComment3.yml | 22 ------- .../recorded/languages/scala/clearIfState.yml | 19 ------- .../languages/scala/clearIfState2.yml | 24 -------- data/fixtures/scopes/c/comment.line.scope | 17 ++++++ data/fixtures/scopes/c/ifStatement.scope | 19 +++++++ .../fixtures/scopes/c/string.singleLine.scope | 17 ++++++ .../scopes/clojure/comment.line.scope | 10 ++++ data/fixtures/scopes/cpp/ifStatement.scope | 19 +++++++ data/fixtures/scopes/css/comment.block.scope | 17 ++++++ data/fixtures/scopes/css/comment.line.scope | 10 ++++ .../scopes/css/string.singleLine.scope | 19 +++++++ data/fixtures/scopes/go/comment.line.scope | 10 ++++ .../fixtures/scopes/latex/comment.block.scope | 15 +++++ data/fixtures/scopes/latex/comment.line.scope | 17 ++++++ .../scopes/markdown/comment.block.scope | 17 ++++++ .../scopes/markdown/comment.line.scope | 10 ++++ data/fixtures/scopes/ruby/comment.block.scope | 15 +++++ data/fixtures/scopes/ruby/comment.line.scope | 10 ++++ data/fixtures/scopes/ruby/comment.line2.scope | 17 ++++++ data/fixtures/scopes/rust/ifStatement.scope | 13 +++++ data/fixtures/scopes/scala/ifStatement.scope | 17 ++++++ data/fixtures/scopes/scala/ifStatement2.scope | 31 ++++++++++ packages/common/src/scopeSupportFacets/c.ts | 15 +++++ .../common/src/scopeSupportFacets/clojure.ts | 13 +++++ packages/common/src/scopeSupportFacets/cpp.ts | 15 +++++ packages/common/src/scopeSupportFacets/css.ts | 15 +++++ .../getLanguageScopeSupport.ts | 57 ++++++++++++++++--- packages/common/src/scopeSupportFacets/go.ts | 13 +++++ .../src/scopeSupportFacets/javascript.ts | 3 +- .../src/scopeSupportFacets/javascriptreact.ts | 14 +++++ .../common/src/scopeSupportFacets/jsonc.ts | 14 +++++ .../common/src/scopeSupportFacets/latex.ts | 14 +++++ .../common/src/scopeSupportFacets/markdown.ts | 14 +++++ .../common/src/scopeSupportFacets/ruby.ts | 14 +++++ .../common/src/scopeSupportFacets/rust.ts | 13 +++++ .../common/src/scopeSupportFacets/scala.ts | 13 +++++ .../common/src/scopeSupportFacets/scss.ts | 14 +++++ .../src/scopeSupportFacets/typescript.ts | 2 + .../src/scopeSupportFacets/typescriptreact.ts | 14 +++++ .../src/languages/LanguageDefinitions.ts | 2 +- .../src/languages/LegacyLanguageId.ts | 4 +- .../src/languages/clojure.ts | 3 - .../cursorless-engine/src/languages/cpp.ts | 3 - .../src/languages/getNodeMatcher.ts | 8 +-- .../src/languages/getTextFragmentExtractor.ts | 49 ++++------------ .../cursorless-engine/src/languages/latex.ts | 2 - .../cursorless-engine/src/languages/rust.ts | 1 - .../cursorless-engine/src/languages/scala.ts | 2 - .../cursorless-engine/src/languages/scss.ts | 14 ----- queries/c.scm | 4 ++ queries/clojure.scm | 3 + queries/cpp.scm | 1 + queries/css.scm | 3 + queries/latex.scm | 4 ++ queries/rust.scm | 4 ++ queries/scala.scm | 1 + queries/scss.scm | 3 + 66 files changed, 590 insertions(+), 345 deletions(-) delete mode 100644 data/fixtures/recorded/languages/cpp/takeComment.yml delete mode 100644 data/fixtures/recorded/languages/cpp/takeIf.yml delete mode 100644 data/fixtures/recorded/languages/cpp/takeIf2.yml delete mode 100644 data/fixtures/recorded/languages/cpp/takeString.yml delete mode 100644 data/fixtures/recorded/languages/latex/changeComment.yml delete mode 100644 data/fixtures/recorded/languages/latex/changeComment2.yml delete mode 100644 data/fixtures/recorded/languages/markdown/clearComment.yml delete mode 100644 data/fixtures/recorded/languages/ruby/changeComment.yml delete mode 100644 data/fixtures/recorded/languages/ruby/changeComment2.yml delete mode 100644 data/fixtures/recorded/languages/ruby/changeComment3.yml delete mode 100644 data/fixtures/recorded/languages/scala/clearIfState.yml delete mode 100644 data/fixtures/recorded/languages/scala/clearIfState2.yml create mode 100644 data/fixtures/scopes/c/comment.line.scope create mode 100644 data/fixtures/scopes/c/ifStatement.scope create mode 100644 data/fixtures/scopes/c/string.singleLine.scope create mode 100644 data/fixtures/scopes/clojure/comment.line.scope create mode 100644 data/fixtures/scopes/cpp/ifStatement.scope create mode 100644 data/fixtures/scopes/css/comment.block.scope create mode 100644 data/fixtures/scopes/css/comment.line.scope create mode 100644 data/fixtures/scopes/css/string.singleLine.scope create mode 100644 data/fixtures/scopes/go/comment.line.scope create mode 100644 data/fixtures/scopes/latex/comment.block.scope create mode 100644 data/fixtures/scopes/latex/comment.line.scope create mode 100644 data/fixtures/scopes/markdown/comment.block.scope create mode 100644 data/fixtures/scopes/markdown/comment.line.scope create mode 100644 data/fixtures/scopes/ruby/comment.block.scope create mode 100644 data/fixtures/scopes/ruby/comment.line.scope create mode 100644 data/fixtures/scopes/ruby/comment.line2.scope create mode 100644 data/fixtures/scopes/rust/ifStatement.scope create mode 100644 data/fixtures/scopes/scala/ifStatement.scope create mode 100644 data/fixtures/scopes/scala/ifStatement2.scope create mode 100644 packages/common/src/scopeSupportFacets/c.ts create mode 100644 packages/common/src/scopeSupportFacets/clojure.ts create mode 100644 packages/common/src/scopeSupportFacets/cpp.ts create mode 100644 packages/common/src/scopeSupportFacets/css.ts create mode 100644 packages/common/src/scopeSupportFacets/go.ts create mode 100644 packages/common/src/scopeSupportFacets/javascriptreact.ts create mode 100644 packages/common/src/scopeSupportFacets/jsonc.ts create mode 100644 packages/common/src/scopeSupportFacets/latex.ts create mode 100644 packages/common/src/scopeSupportFacets/markdown.ts create mode 100644 packages/common/src/scopeSupportFacets/ruby.ts create mode 100644 packages/common/src/scopeSupportFacets/rust.ts create mode 100644 packages/common/src/scopeSupportFacets/scala.ts create mode 100644 packages/common/src/scopeSupportFacets/scss.ts create mode 100644 packages/common/src/scopeSupportFacets/typescriptreact.ts create mode 100644 queries/c.scm create mode 100644 queries/clojure.scm create mode 100644 queries/cpp.scm create mode 100644 queries/css.scm create mode 100644 queries/latex.scm create mode 100644 queries/rust.scm create mode 100644 queries/scala.scm create mode 100644 queries/scss.scm diff --git a/data/fixtures/recorded/languages/cpp/takeComment.yml b/data/fixtures/recorded/languages/cpp/takeComment.yml deleted file mode 100644 index 2c83133a9..000000000 --- a/data/fixtures/recorded/languages/cpp/takeComment.yml +++ /dev/null @@ -1,19 +0,0 @@ -languageId: cpp -command: - version: 1 - spokenForm: take comment - action: setSelection - targets: - - type: primitive - modifier: {type: containingScope, scopeType: comment} -initialState: - documentContents: int a; // the comment - selections: - - anchor: {line: 0, character: 20} - active: {line: 0, character: 20} - marks: {} -finalState: - documentContents: int a; // the comment - selections: - - anchor: {line: 0, character: 7} - active: {line: 0, character: 21} diff --git a/data/fixtures/recorded/languages/cpp/takeIf.yml b/data/fixtures/recorded/languages/cpp/takeIf.yml deleted file mode 100644 index e0e472b9a..000000000 --- a/data/fixtures/recorded/languages/cpp/takeIf.yml +++ /dev/null @@ -1,29 +0,0 @@ -languageId: cpp -command: - version: 1 - spokenForm: take if state - action: setSelection - targets: - - type: primitive - modifier: {type: containingScope, scopeType: ifStatement} -initialState: - documentContents: |- - void f() { - if (true) { - - } - } - selections: - - anchor: {line: 2, character: 8} - active: {line: 2, character: 8} - marks: {} -finalState: - documentContents: |- - void f() { - if (true) { - - } - } - selections: - - anchor: {line: 1, character: 4} - active: {line: 3, character: 5} diff --git a/data/fixtures/recorded/languages/cpp/takeIf2.yml b/data/fixtures/recorded/languages/cpp/takeIf2.yml deleted file mode 100644 index 6b6e956b3..000000000 --- a/data/fixtures/recorded/languages/cpp/takeIf2.yml +++ /dev/null @@ -1,29 +0,0 @@ -languageId: cpp -command: - version: 1 - spokenForm: take if state - action: setSelection - targets: - - type: primitive - modifier: {type: containingScope, scopeType: ifStatement} -initialState: - documentContents: |- - void f() { - if constexpr (true) { - - } - } - selections: - - anchor: {line: 2, character: 8} - active: {line: 2, character: 8} - marks: {} -finalState: - documentContents: |- - void f() { - if constexpr (true) { - - } - } - selections: - - anchor: {line: 1, character: 4} - active: {line: 3, character: 5} diff --git a/data/fixtures/recorded/languages/cpp/takeString.yml b/data/fixtures/recorded/languages/cpp/takeString.yml deleted file mode 100644 index ca13958b1..000000000 --- a/data/fixtures/recorded/languages/cpp/takeString.yml +++ /dev/null @@ -1,24 +0,0 @@ -languageId: cpp -command: - version: 1 - spokenForm: take parse tree string - action: setSelection - targets: - - type: primitive - modifier: {type: containingScope, scopeType: string} -spokenFormError: >- - simple scope type type with id string; this is a private spoken form currently - only for internal experimentation -initialState: - documentContents: | - char* a = "hello world"; - selections: - - anchor: {line: 0, character: 21} - active: {line: 0, character: 21} - marks: {} -finalState: - documentContents: | - char* a = "hello world"; - selections: - - anchor: {line: 0, character: 10} - active: {line: 0, character: 23} diff --git a/data/fixtures/recorded/languages/latex/changeComment.yml b/data/fixtures/recorded/languages/latex/changeComment.yml deleted file mode 100644 index daf7eed43..000000000 --- a/data/fixtures/recorded/languages/latex/changeComment.yml +++ /dev/null @@ -1,23 +0,0 @@ -languageId: latex -command: - version: 1 - spokenForm: change comment - action: clearAndSetSelection - targets: - - type: primitive - modifier: {type: containingScope, scopeType: comment, includeSiblings: false} -initialState: - documentContents: | - \iffalse - some comment - \fi - selections: - - anchor: {line: 0, character: 0} - active: {line: 0, character: 0} - marks: {} -finalState: - documentContents: |+ - - selections: - - anchor: {line: 0, character: 0} - active: {line: 0, character: 0} diff --git a/data/fixtures/recorded/languages/latex/changeComment2.yml b/data/fixtures/recorded/languages/latex/changeComment2.yml deleted file mode 100644 index 4ae0b1e40..000000000 --- a/data/fixtures/recorded/languages/latex/changeComment2.yml +++ /dev/null @@ -1,21 +0,0 @@ -languageId: latex -command: - version: 1 - spokenForm: change comment - action: clearAndSetSelection - targets: - - type: primitive - modifier: {type: containingScope, scopeType: comment, includeSiblings: false} -initialState: - documentContents: | - \LaTeX % some comment - selections: - - anchor: {line: 0, character: 8} - active: {line: 0, character: 8} - marks: {} -finalState: - documentContents: | - \LaTeX - selections: - - anchor: {line: 0, character: 7} - active: {line: 0, character: 7} diff --git a/data/fixtures/recorded/languages/markdown/clearComment.yml b/data/fixtures/recorded/languages/markdown/clearComment.yml deleted file mode 100644 index 7e1f23c06..000000000 --- a/data/fixtures/recorded/languages/markdown/clearComment.yml +++ /dev/null @@ -1,19 +0,0 @@ -languageId: markdown -command: - version: 1 - spokenForm: change comment - action: clearAndSetSelection - targets: - - type: primitive - modifier: {type: containingScope, scopeType: comment, includeSiblings: false} -initialState: - documentContents: - selections: - - anchor: {line: 0, character: 16} - active: {line: 0, character: 16} - marks: {} -finalState: - documentContents: "" - selections: - - anchor: {line: 0, character: 0} - active: {line: 0, character: 0} diff --git a/data/fixtures/recorded/languages/ruby/changeComment.yml b/data/fixtures/recorded/languages/ruby/changeComment.yml deleted file mode 100644 index f04f6afbe..000000000 --- a/data/fixtures/recorded/languages/ruby/changeComment.yml +++ /dev/null @@ -1,19 +0,0 @@ -languageId: ruby -command: - version: 1 - spokenForm: change comment - action: clearAndSetSelection - targets: - - type: primitive - modifier: {type: containingScope, scopeType: comment, includeSiblings: false} -initialState: - documentContents: "# Hello World" - selections: - - anchor: {line: 0, character: 9} - active: {line: 0, character: 9} - marks: {} -finalState: - documentContents: "" - selections: - - anchor: {line: 0, character: 0} - active: {line: 0, character: 0} diff --git a/data/fixtures/recorded/languages/ruby/changeComment2.yml b/data/fixtures/recorded/languages/ruby/changeComment2.yml deleted file mode 100644 index 2aea12ad8..000000000 --- a/data/fixtures/recorded/languages/ruby/changeComment2.yml +++ /dev/null @@ -1,19 +0,0 @@ -languageId: ruby -command: - version: 1 - spokenForm: change comment - action: clearAndSetSelection - targets: - - type: primitive - modifier: {type: containingScope, scopeType: comment, includeSiblings: false} -initialState: - documentContents: "a = 0 # Hello World" - selections: - - anchor: {line: 0, character: 8} - active: {line: 0, character: 8} - marks: {} -finalState: - documentContents: "a = 0 " - selections: - - anchor: {line: 0, character: 6} - active: {line: 0, character: 6} diff --git a/data/fixtures/recorded/languages/ruby/changeComment3.yml b/data/fixtures/recorded/languages/ruby/changeComment3.yml deleted file mode 100644 index b20fd0fcf..000000000 --- a/data/fixtures/recorded/languages/ruby/changeComment3.yml +++ /dev/null @@ -1,22 +0,0 @@ -languageId: ruby -command: - version: 1 - spokenForm: change comment - action: clearAndSetSelection - targets: - - type: primitive - modifier: {type: containingScope, scopeType: comment, includeSiblings: false} -initialState: - documentContents: |- - =begin - Hi - =end - selections: - - anchor: {line: 1, character: 3} - active: {line: 1, character: 3} - marks: {} -finalState: - documentContents: "" - selections: - - anchor: {line: 0, character: 0} - active: {line: 0, character: 0} diff --git a/data/fixtures/recorded/languages/scala/clearIfState.yml b/data/fixtures/recorded/languages/scala/clearIfState.yml deleted file mode 100644 index b6689cda8..000000000 --- a/data/fixtures/recorded/languages/scala/clearIfState.yml +++ /dev/null @@ -1,19 +0,0 @@ -languageId: scala -command: - version: 0 - spokenForm: change if state - action: clearAndSetSelection - targets: - - type: primitive - modifier: {type: containingScope, scopeType: ifStatement, includeSiblings: false} -initialState: - documentContents: val test = if (true) true else false - selections: - - anchor: {line: 0, character: 12} - active: {line: 0, character: 12} - marks: {} -finalState: - documentContents: "val test = " - selections: - - anchor: {line: 0, character: 11} - active: {line: 0, character: 11} diff --git a/data/fixtures/recorded/languages/scala/clearIfState2.yml b/data/fixtures/recorded/languages/scala/clearIfState2.yml deleted file mode 100644 index beb7b34bd..000000000 --- a/data/fixtures/recorded/languages/scala/clearIfState2.yml +++ /dev/null @@ -1,24 +0,0 @@ -languageId: scala -command: - version: 0 - spokenForm: change if state - action: clearAndSetSelection - targets: - - type: primitive - modifier: {type: containingScope, scopeType: ifStatement, includeSiblings: false} -initialState: - documentContents: |- - val test = if (true) { - true - } else { - false - } - selections: - - anchor: {line: 0, character: 12} - active: {line: 0, character: 12} - marks: {} -finalState: - documentContents: "val test = " - selections: - - anchor: {line: 0, character: 11} - active: {line: 0, character: 11} diff --git a/data/fixtures/scopes/c/comment.line.scope b/data/fixtures/scopes/c/comment.line.scope new file mode 100644 index 000000000..073c15340 --- /dev/null +++ b/data/fixtures/scopes/c/comment.line.scope @@ -0,0 +1,17 @@ +int a; // the comment +--- + +[Content] = +[Domain] = 0:7-0:21 + >--------------< +0| int a; // the comment + +[Removal] = 0:6-0:21 + >---------------< +0| int a; // the comment + +[Leading delimiter] = 0:6-0:7 + >-< +0| int a; // the comment + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/c/ifStatement.scope b/data/fixtures/scopes/c/ifStatement.scope new file mode 100644 index 000000000..57b5634c5 --- /dev/null +++ b/data/fixtures/scopes/c/ifStatement.scope @@ -0,0 +1,19 @@ +void func() { + if (true) { } +} +--- + +[Content] = +[Domain] = 1:4-1:17 + >-------------< +1| if (true) { } + +[Removal] = 1:0-1:17 + >-----------------< +1| if (true) { } + +[Leading delimiter] = 1:0-1:4 + >----< +1| if (true) { } + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/c/string.singleLine.scope b/data/fixtures/scopes/c/string.singleLine.scope new file mode 100644 index 000000000..fdad82ffd --- /dev/null +++ b/data/fixtures/scopes/c/string.singleLine.scope @@ -0,0 +1,17 @@ +char* a = "hello world"; +--- + +[Content] = +[Domain] = 0:10-0:23 + >-------------< +0| char* a = "hello world"; + +[Removal] = 0:9-0:23 + >--------------< +0| char* a = "hello world"; + +[Leading delimiter] = 0:9-0:10 + >-< +0| char* a = "hello world"; + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/clojure/comment.line.scope b/data/fixtures/scopes/clojure/comment.line.scope new file mode 100644 index 000000000..4a6e1fd6e --- /dev/null +++ b/data/fixtures/scopes/clojure/comment.line.scope @@ -0,0 +1,10 @@ +;; foo +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:6 + >------< +0| ;; foo + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/cpp/ifStatement.scope b/data/fixtures/scopes/cpp/ifStatement.scope new file mode 100644 index 000000000..59f601f63 --- /dev/null +++ b/data/fixtures/scopes/cpp/ifStatement.scope @@ -0,0 +1,19 @@ +void funk() { + if constexpr (true) {} +} +--- + +[Content] = +[Domain] = 1:4-1:26 + >----------------------< +1| if constexpr (true) {} + +[Removal] = 1:0-1:26 + >--------------------------< +1| if constexpr (true) {} + +[Leading delimiter] = 1:0-1:4 + >----< +1| if constexpr (true) {} + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/css/comment.block.scope b/data/fixtures/scopes/css/comment.block.scope new file mode 100644 index 000000000..0bc848174 --- /dev/null +++ b/data/fixtures/scopes/css/comment.block.scope @@ -0,0 +1,17 @@ +/* + foo + bar +*/ +--- + +[Content] = +[Removal] = +[Domain] = 0:0-3:2 + >-- +0| /* +1| foo +2| bar +3| */ + --< + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/css/comment.line.scope b/data/fixtures/scopes/css/comment.line.scope new file mode 100644 index 000000000..aab727ca5 --- /dev/null +++ b/data/fixtures/scopes/css/comment.line.scope @@ -0,0 +1,10 @@ +/* foo */ +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:9 + >---------< +0| /* foo */ + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/css/string.singleLine.scope b/data/fixtures/scopes/css/string.singleLine.scope new file mode 100644 index 000000000..4c61e1ddf --- /dev/null +++ b/data/fixtures/scopes/css/string.singleLine.scope @@ -0,0 +1,19 @@ +* { + color: "foo" +} +--- + +[Content] = +[Domain] = 1:11-1:16 + >-----< +1| color: "foo" + +[Removal] = 1:10-1:16 + >------< +1| color: "foo" + +[Leading delimiter] = 1:10-1:11 + >-< +1| color: "foo" + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/comment.line.scope b/data/fixtures/scopes/go/comment.line.scope new file mode 100644 index 000000000..2856f7134 --- /dev/null +++ b/data/fixtures/scopes/go/comment.line.scope @@ -0,0 +1,10 @@ +// foo +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:6 + >------< +0| // foo + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/latex/comment.block.scope b/data/fixtures/scopes/latex/comment.block.scope new file mode 100644 index 000000000..05e52078e --- /dev/null +++ b/data/fixtures/scopes/latex/comment.block.scope @@ -0,0 +1,15 @@ +\iffalse +some comment +\fi +--- + +[Content] = +[Removal] = +[Domain] = 0:0-2:3 + >-------- +0| \iffalse +1| some comment +2| \fi + ---< + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/latex/comment.line.scope b/data/fixtures/scopes/latex/comment.line.scope new file mode 100644 index 000000000..8269ee28b --- /dev/null +++ b/data/fixtures/scopes/latex/comment.line.scope @@ -0,0 +1,17 @@ +\LaTeX % some comment +--- + +[Content] = +[Domain] = 0:7-0:21 + >--------------< +0| \LaTeX % some comment + +[Removal] = 0:6-0:21 + >---------------< +0| \LaTeX % some comment + +[Leading delimiter] = 0:6-0:7 + >-< +0| \LaTeX % some comment + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/markdown/comment.block.scope b/data/fixtures/scopes/markdown/comment.block.scope new file mode 100644 index 000000000..c0ccd2e76 --- /dev/null +++ b/data/fixtures/scopes/markdown/comment.block.scope @@ -0,0 +1,17 @@ + +--- + +[Content] = +[Removal] = +[Domain] = 0:0-3:3 + >---- +0| + ---< + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/markdown/comment.line.scope b/data/fixtures/scopes/markdown/comment.line.scope new file mode 100644 index 000000000..f63466001 --- /dev/null +++ b/data/fixtures/scopes/markdown/comment.line.scope @@ -0,0 +1,10 @@ + +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:21 + >---------------------< +0| + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/ruby/comment.block.scope b/data/fixtures/scopes/ruby/comment.block.scope new file mode 100644 index 000000000..495bdf759 --- /dev/null +++ b/data/fixtures/scopes/ruby/comment.block.scope @@ -0,0 +1,15 @@ +=begin + Hi +=end +--- + +[Content] = +[Removal] = +[Domain] = 0:0-2:4 + >------ +0| =begin +1| Hi +2| =end + ----< + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/ruby/comment.line.scope b/data/fixtures/scopes/ruby/comment.line.scope new file mode 100644 index 000000000..e13000563 --- /dev/null +++ b/data/fixtures/scopes/ruby/comment.line.scope @@ -0,0 +1,10 @@ +# Hello World +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:13 + >-------------< +0| # Hello World + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/ruby/comment.line2.scope b/data/fixtures/scopes/ruby/comment.line2.scope new file mode 100644 index 000000000..bb3e4355a --- /dev/null +++ b/data/fixtures/scopes/ruby/comment.line2.scope @@ -0,0 +1,17 @@ +a = 0 # Hello World +--- + +[Content] = +[Domain] = 0:6-0:19 + >-------------< +0| a = 0 # Hello World + +[Removal] = 0:5-0:19 + >--------------< +0| a = 0 # Hello World + +[Leading delimiter] = 0:5-0:6 + >-< +0| a = 0 # Hello World + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/rust/ifStatement.scope b/data/fixtures/scopes/rust/ifStatement.scope new file mode 100644 index 000000000..01be0347d --- /dev/null +++ b/data/fixtures/scopes/rust/ifStatement.scope @@ -0,0 +1,13 @@ +if true {} +else {}; +--- + +[Content] = +[Removal] = +[Domain] = 0:0-1:7 + >----------- +0| if true {} +1| else {}; + -------< + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/scala/ifStatement.scope b/data/fixtures/scopes/scala/ifStatement.scope new file mode 100644 index 000000000..2a457b4ea --- /dev/null +++ b/data/fixtures/scopes/scala/ifStatement.scope @@ -0,0 +1,17 @@ +val test = if (true) true else false +--- + +[Content] = +[Domain] = 0:11-0:36 + >-------------------------< +0| val test = if (true) true else false + +[Removal] = 0:10-0:36 + >--------------------------< +0| val test = if (true) true else false + +[Leading delimiter] = 0:10-0:11 + >-< +0| val test = if (true) true else false + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/scala/ifStatement2.scope b/data/fixtures/scopes/scala/ifStatement2.scope new file mode 100644 index 000000000..29f38a40d --- /dev/null +++ b/data/fixtures/scopes/scala/ifStatement2.scope @@ -0,0 +1,31 @@ +val test = if (true) { + true +} else { + false +} +--- + +[Content] = +[Domain] = 0:11-4:1 + >----------- +0| val test = if (true) { +1| true +2| } else { +3| false +4| } + -< + +[Removal] = 0:10-4:1 + >------------ +0| val test = if (true) { +1| true +2| } else { +3| false +4| } + -< + +[Leading delimiter] = 0:10-0:11 + >-< +0| val test = if (true) { + +[Insertion delimiter] = "\n" diff --git a/packages/common/src/scopeSupportFacets/c.ts b/packages/common/src/scopeSupportFacets/c.ts new file mode 100644 index 000000000..9b6990b4b --- /dev/null +++ b/packages/common/src/scopeSupportFacets/c.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const cScopeSupport: LanguageScopeSupportFacetMap = { + ifStatement: supported, + "comment.line": supported, + "string.singleLine": supported, +}; diff --git a/packages/common/src/scopeSupportFacets/clojure.ts b/packages/common/src/scopeSupportFacets/clojure.ts new file mode 100644 index 000000000..2794f98cf --- /dev/null +++ b/packages/common/src/scopeSupportFacets/clojure.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const clojureScopeSupport: LanguageScopeSupportFacetMap = { + "comment.line": supported, +}; diff --git a/packages/common/src/scopeSupportFacets/cpp.ts b/packages/common/src/scopeSupportFacets/cpp.ts new file mode 100644 index 000000000..58984407c --- /dev/null +++ b/packages/common/src/scopeSupportFacets/cpp.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +// import { cScopeSupport } from "./c"; +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const cppScopeSupport: LanguageScopeSupportFacetMap = { + // ...cScopeSupport, + ifStatement: supported, +}; diff --git a/packages/common/src/scopeSupportFacets/css.ts b/packages/common/src/scopeSupportFacets/css.ts new file mode 100644 index 000000000..e30b82cc4 --- /dev/null +++ b/packages/common/src/scopeSupportFacets/css.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const cssScopeSupport: LanguageScopeSupportFacetMap = { + "comment.line": supported, + "comment.block": supported, + "string.singleLine": supported, +}; diff --git a/packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts b/packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts index c20753203..a5923c9c7 100644 --- a/packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts +++ b/packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts @@ -1,36 +1,77 @@ +import { cScopeSupport } from "./c"; +import { clojureScopeSupport } from "./clojure"; +import { cppScopeSupport } from "./cpp"; +import { csharpScopeSupport } from "./csharp"; +import { cssScopeSupport } from "./css"; +import { goScopeSupport } from "./go"; import { htmlScopeSupport } from "./html"; import { javaScopeSupport } from "./java"; import { javascriptScopeSupport } from "./javascript"; import { jsonScopeSupport } from "./json"; -import { pythonScopeSupport } from "./python"; -import { csharpScopeSupport } from "./csharp"; +import { jsoncScopeSupport } from "./jsonc"; +import { latexScopeSupport } from "./latex"; import { luaScopeSupport } from "./lua"; +import { markdownScopeSupport } from "./markdown"; +import { pythonScopeSupport } from "./python"; +import { rubyScopeSupport } from "./ruby"; +import { rustScopeSupport } from "./rust"; +import { scalaScopeSupport } from "./scala"; import { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types"; +import { scssScopeSupport } from "./scss"; import { talonScopeSupport } from "./talon"; import { typescriptScopeSupport } from "./typescript"; +import { typescriptreactScopeSupport } from "./typescriptreact"; export function getLanguageScopeSupport( languageId: string, ): LanguageScopeSupportFacetMap { switch (languageId) { + case "c": + return cScopeSupport; + case "clojure": + return clojureScopeSupport; + case "cpp": + return cppScopeSupport; case "csharp": return csharpScopeSupport; + case "css": + return cssScopeSupport; + case "go": + return goScopeSupport; case "html": return htmlScopeSupport; case "java": return javaScopeSupport; + case "latex": + return latexScopeSupport; + case "markdown": + return markdownScopeSupport; case "javascript": return javascriptScopeSupport; + case "javascriptreact": + return javascriptScopeSupport; case "json": return jsonScopeSupport; - case "python": - return pythonScopeSupport; - case "talon": - return talonScopeSupport; - case "typescript": - return typescriptScopeSupport; + case "jsonc": + return jsoncScopeSupport; case "lua": return luaScopeSupport; + case "python": + return pythonScopeSupport; + case "ruby": + return rubyScopeSupport; + case "rust": + return rustScopeSupport; + case "scala": + return scalaScopeSupport; + case "talon": + return talonScopeSupport; + case "scss": + return scssScopeSupport; + case "typescript": + return typescriptScopeSupport; + case "typescriptreact": + return typescriptreactScopeSupport; } throw Error(`Unsupported language: '${languageId}'`); } diff --git a/packages/common/src/scopeSupportFacets/go.ts b/packages/common/src/scopeSupportFacets/go.ts new file mode 100644 index 000000000..b3d5369d8 --- /dev/null +++ b/packages/common/src/scopeSupportFacets/go.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const goScopeSupport: LanguageScopeSupportFacetMap = { + "comment.line": supported, +}; diff --git a/packages/common/src/scopeSupportFacets/javascript.ts b/packages/common/src/scopeSupportFacets/javascript.ts index 9908bd85f..ba227c6f8 100644 --- a/packages/common/src/scopeSupportFacets/javascript.ts +++ b/packages/common/src/scopeSupportFacets/javascript.ts @@ -5,7 +5,8 @@ import { ScopeSupportFacetLevel, } from "./scopeSupportFacets.types"; -const { supported, notApplicable } = ScopeSupportFacetLevel; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; export const javascriptScopeSupport: LanguageScopeSupportFacetMap = { list: supported, diff --git a/packages/common/src/scopeSupportFacets/javascriptreact.ts b/packages/common/src/scopeSupportFacets/javascriptreact.ts new file mode 100644 index 000000000..635db1039 --- /dev/null +++ b/packages/common/src/scopeSupportFacets/javascriptreact.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { javascriptScopeSupport } from "./javascript"; +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const javascriptreactScopeSupport: LanguageScopeSupportFacetMap = { + ...javascriptScopeSupport, +}; diff --git a/packages/common/src/scopeSupportFacets/jsonc.ts b/packages/common/src/scopeSupportFacets/jsonc.ts new file mode 100644 index 000000000..c0e8f02bb --- /dev/null +++ b/packages/common/src/scopeSupportFacets/jsonc.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { jsonScopeSupport } from "./json"; +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const jsoncScopeSupport: LanguageScopeSupportFacetMap = { + ...jsonScopeSupport, +}; diff --git a/packages/common/src/scopeSupportFacets/latex.ts b/packages/common/src/scopeSupportFacets/latex.ts new file mode 100644 index 000000000..d2f80fb53 --- /dev/null +++ b/packages/common/src/scopeSupportFacets/latex.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const latexScopeSupport: LanguageScopeSupportFacetMap = { + "comment.line": supported, + "comment.block": supported, +}; diff --git a/packages/common/src/scopeSupportFacets/markdown.ts b/packages/common/src/scopeSupportFacets/markdown.ts new file mode 100644 index 000000000..259173abc --- /dev/null +++ b/packages/common/src/scopeSupportFacets/markdown.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const markdownScopeSupport: LanguageScopeSupportFacetMap = { + "comment.line": supported, + "comment.block": supported, +}; diff --git a/packages/common/src/scopeSupportFacets/ruby.ts b/packages/common/src/scopeSupportFacets/ruby.ts new file mode 100644 index 000000000..69a132b70 --- /dev/null +++ b/packages/common/src/scopeSupportFacets/ruby.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const rubyScopeSupport: LanguageScopeSupportFacetMap = { + "comment.line": supported, + "comment.block": supported, +}; diff --git a/packages/common/src/scopeSupportFacets/rust.ts b/packages/common/src/scopeSupportFacets/rust.ts new file mode 100644 index 000000000..4e654e94c --- /dev/null +++ b/packages/common/src/scopeSupportFacets/rust.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const rustScopeSupport: LanguageScopeSupportFacetMap = { + ifStatement: supported, +}; diff --git a/packages/common/src/scopeSupportFacets/scala.ts b/packages/common/src/scopeSupportFacets/scala.ts new file mode 100644 index 000000000..6f5deb3fb --- /dev/null +++ b/packages/common/src/scopeSupportFacets/scala.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const scalaScopeSupport: LanguageScopeSupportFacetMap = { + ifStatement: supported, +}; diff --git a/packages/common/src/scopeSupportFacets/scss.ts b/packages/common/src/scopeSupportFacets/scss.ts new file mode 100644 index 000000000..197e257de --- /dev/null +++ b/packages/common/src/scopeSupportFacets/scss.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { cssScopeSupport } from "./css"; +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const scssScopeSupport: LanguageScopeSupportFacetMap = { + ...cssScopeSupport, +}; diff --git a/packages/common/src/scopeSupportFacets/typescript.ts b/packages/common/src/scopeSupportFacets/typescript.ts index 706c9d96c..afccf1725 100644 --- a/packages/common/src/scopeSupportFacets/typescript.ts +++ b/packages/common/src/scopeSupportFacets/typescript.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ +// import { javascriptScopeSupport } from "./javascript"; import { LanguageScopeSupportFacetMap, ScopeSupportFacetLevel, @@ -8,6 +9,7 @@ import { const { supported } = ScopeSupportFacetLevel; export const typescriptScopeSupport: LanguageScopeSupportFacetMap = { + // ...javascriptScopeSupport, "type.variable": supported, "type.formalParameter": supported, "type.return": supported, diff --git a/packages/common/src/scopeSupportFacets/typescriptreact.ts b/packages/common/src/scopeSupportFacets/typescriptreact.ts new file mode 100644 index 000000000..c33b6b1a7 --- /dev/null +++ b/packages/common/src/scopeSupportFacets/typescriptreact.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; +import { typescriptScopeSupport } from "./typescript"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const typescriptreactScopeSupport: LanguageScopeSupportFacetMap = { + ...typescriptScopeSupport, +}; diff --git a/packages/cursorless-engine/src/languages/LanguageDefinitions.ts b/packages/cursorless-engine/src/languages/LanguageDefinitions.ts index 04467ff5f..d2a069b01 100644 --- a/packages/cursorless-engine/src/languages/LanguageDefinitions.ts +++ b/packages/cursorless-engine/src/languages/LanguageDefinitions.ts @@ -121,7 +121,7 @@ export class LanguageDefinitions { if (definition == null) { throw new Error( - "Expected language definition entry missing for languageId " + + "Expected language definition entry is missing for languageId " + languageId, ); } diff --git a/packages/cursorless-engine/src/languages/LegacyLanguageId.ts b/packages/cursorless-engine/src/languages/LegacyLanguageId.ts index eeddb29d4..9a507df56 100644 --- a/packages/cursorless-engine/src/languages/LegacyLanguageId.ts +++ b/packages/cursorless-engine/src/languages/LegacyLanguageId.ts @@ -6,8 +6,8 @@ export const legacyLanguageIds = [ "c", "clojure", "cpp", - "css", "csharp", + "css", "go", "html", "java", @@ -20,9 +20,9 @@ export const legacyLanguageIds = [ "php", "python", "ruby", + "rust", "scala", "scss", - "rust", "typescript", "typescriptreact", "xml", diff --git a/packages/cursorless-engine/src/languages/clojure.ts b/packages/cursorless-engine/src/languages/clojure.ts index 9f1cb7338..88ab2dbe9 100644 --- a/packages/cursorless-engine/src/languages/clojure.ts +++ b/packages/cursorless-engine/src/languages/clojure.ts @@ -133,7 +133,6 @@ const ifStatementMatcher = matcher(ifStatementFinder); const nodeMatchers: Partial< Record > = { - comment: "comment", map: "map_lit", collectionKey: matcher(mapParityNodeFinder(0)), @@ -164,8 +163,6 @@ const nodeMatchers: Partial< // A list is either a vector literal or a quoted list literal list: ["vec_lit", "quoting_lit.list_lit"], - string: "str_lit", - functionCall: functionCallPattern, functionCallee: chainedMatcher([ functionCallFinder, diff --git a/packages/cursorless-engine/src/languages/cpp.ts b/packages/cursorless-engine/src/languages/cpp.ts index d3ef71114..2ce8355ad 100644 --- a/packages/cursorless-engine/src/languages/cpp.ts +++ b/packages/cursorless-engine/src/languages/cpp.ts @@ -79,10 +79,7 @@ const nodeMatchers: Partial< "union_specifier[name]", "function_definition[declarator][declarator][namespace]", // void ClassName::method() {} ], - ifStatement: "if_statement", ["private.switchStatementSubject"]: "switch_statement[condition][value]", - string: "string_literal", - comment: "comment", anonymousFunction: "lambda_expression", list: "initializer_list", functionCall: ["call_expression", "declaration.init_declarator!"], diff --git a/packages/cursorless-engine/src/languages/getNodeMatcher.ts b/packages/cursorless-engine/src/languages/getNodeMatcher.ts index 39aee32b2..929df4ed4 100644 --- a/packages/cursorless-engine/src/languages/getNodeMatcher.ts +++ b/packages/cursorless-engine/src/languages/getNodeMatcher.ts @@ -52,10 +52,10 @@ export const languageMatchers: Record< Partial> > = { c: cpp, - cpp, - css: scss, - csharp, clojure, + cpp, + csharp, + css: scss, go, java, latex, @@ -63,9 +63,9 @@ export const languageMatchers: Record< php, python, ruby, + rust, scala, scss, - rust, }; function matcherIncludeSiblings(matcher: NodeMatcher): NodeMatcher { diff --git a/packages/cursorless-engine/src/languages/getTextFragmentExtractor.ts b/packages/cursorless-engine/src/languages/getTextFragmentExtractor.ts index cc7eda0ba..400391bdb 100644 --- a/packages/cursorless-engine/src/languages/getTextFragmentExtractor.ts +++ b/packages/cursorless-engine/src/languages/getTextFragmentExtractor.ts @@ -6,7 +6,6 @@ import { getNodeInternalRange, getNodeRange } from "../util/nodeSelectors"; import { LegacyLanguageId } from "./LegacyLanguageId"; import { getNodeMatcher } from "./getNodeMatcher"; import { stringTextFragmentExtractor as rubyStringTextFragmentExtractor } from "./ruby"; -import { stringTextFragmentExtractor as scssStringTextFragmentExtractor } from "./scss"; export type TextFragmentExtractor = ( node: SyntaxNode, @@ -104,39 +103,15 @@ export default function getTextFragmentExtractor( return textFragmentExtractors[languageId as LegacyLanguageId]; } -// NB: For now when we want use the entire file as a text fragment we just -// return null so that the extractor uses it. In the future we should probably -// make a fragment extractor which just pulls out the whole document itself -type FullDocumentTextFragmentExtractor = null; -const fullDocumentTextFragmentExtractor = null; - -const textFragmentExtractors: Record< - LegacyLanguageId, - TextFragmentExtractor | FullDocumentTextFragmentExtractor -> = { - c: constructDefaultTextFragmentExtractor("c"), - clojure: constructDefaultTextFragmentExtractor( - "clojure", - constructHackedStringTextFragmentExtractor("clojure"), - ), - cpp: constructDefaultTextFragmentExtractor("cpp"), - csharp: constructDefaultTextFragmentExtractor("csharp"), - css: constructDefaultTextFragmentExtractor( - "css", - scssStringTextFragmentExtractor, - ), - latex: fullDocumentTextFragmentExtractor, - ruby: constructDefaultTextFragmentExtractor( - "ruby", - rubyStringTextFragmentExtractor, - ), - scala: constructDefaultTextFragmentExtractor( - "scala", - constructHackedStringTextFragmentExtractor("scala"), - ), - scss: constructDefaultTextFragmentExtractor( - "scss", - scssStringTextFragmentExtractor, - ), - rust: constructDefaultTextFragmentExtractor("rust"), -}; +const textFragmentExtractors: Record = + { + ruby: constructDefaultTextFragmentExtractor( + "ruby", + rubyStringTextFragmentExtractor, + ), + scala: constructDefaultTextFragmentExtractor( + "scala", + constructHackedStringTextFragmentExtractor("scala"), + ), + rust: constructDefaultTextFragmentExtractor("rust"), + }; diff --git a/packages/cursorless-engine/src/languages/latex.ts b/packages/cursorless-engine/src/languages/latex.ts index 65ed58b44..983124637 100644 --- a/packages/cursorless-engine/src/languages/latex.ts +++ b/packages/cursorless-engine/src/languages/latex.ts @@ -201,8 +201,6 @@ const nodeMatchers: Partial< collectionItem: matcher(patternFinder("enum_item"), extractItemContent), - comment: ["block_comment", "line_comment"], - part: "part", chapter: "chapter", section: "section", diff --git a/packages/cursorless-engine/src/languages/rust.ts b/packages/cursorless-engine/src/languages/rust.ts index 0efd87ec1..496c8b0b3 100644 --- a/packages/cursorless-engine/src/languages/rust.ts +++ b/packages/cursorless-engine/src/languages/rust.ts @@ -147,7 +147,6 @@ const nodeMatchers: Partial< 1, ), string: ["raw_string_literal", "string_literal"], - ifStatement: ["if_expression", "if_let_expression"], condition: cascadingMatcher( patternMatcher("while_expression[condition]", "if_expression[condition]"), matcher( diff --git a/packages/cursorless-engine/src/languages/scala.ts b/packages/cursorless-engine/src/languages/scala.ts index bc7ef6a45..0aa67b198 100644 --- a/packages/cursorless-engine/src/languages/scala.ts +++ b/packages/cursorless-engine/src/languages/scala.ts @@ -21,8 +21,6 @@ const nodeMatchers: Partial< "trait_definition[name]", ], - ifStatement: "if_expression", - string: ["interpolated_string_expression", "string"], comment: "comment", diff --git a/packages/cursorless-engine/src/languages/scss.ts b/packages/cursorless-engine/src/languages/scss.ts index b0d0f3dfd..ee9180c9a 100644 --- a/packages/cursorless-engine/src/languages/scss.ts +++ b/packages/cursorless-engine/src/languages/scss.ts @@ -17,7 +17,6 @@ import { import { childRangeSelector, delimitedSelector, - getNodeRange, simpleSelectionExtractor, } from "../util/nodeSelectors"; @@ -118,12 +117,10 @@ const nodeMatchers: Partial< childRangeSelector([], ["attribute_name", "string_value"]), ), ), - string: "string_value", functionCall: "call_expression", functionCallee: "call_expression.function_name!", namedFunction: ["mixin_statement", "function_statement"], functionName: ["mixin_statement.name!", "function_statement.name!"], - comment: ["comment", "single_line_comment"], argumentOrParameter: cascadingMatcher( matcher( patternFinder("arguments.*!", "parameters.*!"), @@ -167,14 +164,3 @@ const nodeMatchers: Partial< }; export const patternMatchers = createPatternMatchers(nodeMatchers); - -export function stringTextFragmentExtractor( - node: SyntaxNode, - _selection: SelectionWithEditor, -) { - if (node.type === "string_value") { - return getNodeRange(node); - } - - return null; -} diff --git a/queries/c.scm b/queries/c.scm new file mode 100644 index 000000000..45957f3d2 --- /dev/null +++ b/queries/c.scm @@ -0,0 +1,4 @@ +(if_statement) @ifStatement + +(string_literal) @string @textFragment +(comment) @comment @textFragment diff --git a/queries/clojure.scm b/queries/clojure.scm new file mode 100644 index 000000000..a072a0b01 --- /dev/null +++ b/queries/clojure.scm @@ -0,0 +1,3 @@ +(comment) @comment @textFragment + +(str_lit) @string @textFragment diff --git a/queries/cpp.scm b/queries/cpp.scm new file mode 100644 index 000000000..64cf44ab6 --- /dev/null +++ b/queries/cpp.scm @@ -0,0 +1 @@ +;; import c.scm diff --git a/queries/css.scm b/queries/css.scm new file mode 100644 index 000000000..6516c91ad --- /dev/null +++ b/queries/css.scm @@ -0,0 +1,3 @@ +(string_value) @string @textFragment + +(comment) @comment @textFragment diff --git a/queries/latex.scm b/queries/latex.scm new file mode 100644 index 000000000..0a63c9bfe --- /dev/null +++ b/queries/latex.scm @@ -0,0 +1,4 @@ +[ + (block_comment) + (line_comment) +] @comment diff --git a/queries/rust.scm b/queries/rust.scm new file mode 100644 index 000000000..199c0eade --- /dev/null +++ b/queries/rust.scm @@ -0,0 +1,4 @@ +[ + (if_expression) + (if_let_expression) +] @ifStatement diff --git a/queries/scala.scm b/queries/scala.scm new file mode 100644 index 000000000..d6aa307a5 --- /dev/null +++ b/queries/scala.scm @@ -0,0 +1 @@ +(if_expression) @ifStatement diff --git a/queries/scss.scm b/queries/scss.scm new file mode 100644 index 000000000..38d5be172 --- /dev/null +++ b/queries/scss.scm @@ -0,0 +1,3 @@ +;; import css.scm + +(single_line_comment) @comment @textFragment