Skip to content

Commit

Permalink
Initial tree-sitter support for .scm files
Browse files Browse the repository at this point in the history
  • Loading branch information
pokey committed May 5, 2023
1 parent 96f26c3 commit 3486f5d
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/cursorless-engine/src/languages/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const supportedLanguageIds = [
"python",
"ruby",
"scala",
"scm",
"scss",
"rust",
"typescript",
Expand Down
3 changes: 2 additions & 1 deletion packages/cursorless-engine/src/languages/getNodeMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function getNodeMatcher(

const languageMatchers: Record<
SupportedLanguageId,
Record<SimpleScopeTypeType, NodeMatcher>
Partial<Record<SimpleScopeTypeType, NodeMatcher>>
> = {
c: cpp,
cpp,
Expand All @@ -72,6 +72,7 @@ const languageMatchers: Record<
python,
ruby,
scala,
scm: {},
scss,
rust,
typescript,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const textFragmentExtractors: Record<
"scala",
constructHackedStringTextFragmentExtractor("scala"),
),
scm: null,
scss: constructDefaultTextFragmentExtractor(
"scss",
scssStringTextFragmentExtractor,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: scm
command:
version: 5
spokenForm: clear comment
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: comment}
usePrePhraseSnapshot: true
initialState:
documentContents: ;; aaa
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}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
languageId: scm
command:
version: 5
spokenForm: clear every state
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: everyScope
scopeType: {type: statement}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
(aaa) @bbb
;; ccc
(ddd) @eee
selections:
- anchor: {line: 2, character: 10}
active: {line: 2, character: 10}
marks: {}
finalState:
documentContents: |
;; ccc
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
- anchor: {line: 2, character: 0}
active: {line: 2, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: scm
command:
version: 5
spokenForm: clear item
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: collectionItem}
usePrePhraseSnapshot: true
initialState:
documentContents: ;; (aaa)
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
marks: {}
finalState:
documentContents: ;; ()
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: scm
command:
version: 5
spokenForm: clear round
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: surroundingPair, delimiter: parentheses}
usePrePhraseSnapshot: true
initialState:
documentContents: (aaa)
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}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: scm
command:
version: 5
spokenForm: clear round
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: surroundingPair, delimiter: parentheses}
usePrePhraseSnapshot: true
initialState:
documentContents: ;; (aaa)
selections:
- anchor: {line: 0, character: 3}
active: {line: 0, character: 3}
marks: {}
finalState:
documentContents: ";; "
selections:
- anchor: {line: 0, character: 3}
active: {line: 0, character: 3}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: scm
command:
version: 5
spokenForm: clear round
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: surroundingPair, delimiter: parentheses}
usePrePhraseSnapshot: true
initialState:
documentContents: "\"(aaa)\" @bbb"
selections:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
marks: {}
finalState:
documentContents: "\"\" @bbb"
selections:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
languageId: scm
command:
version: 5
spokenForm: clear state
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: statement}
usePrePhraseSnapshot: true
initialState:
documentContents: ;; aaa
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
thrownError: {name: NoContainingScopeError}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: scm
command:
version: 5
spokenForm: clear state
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: statement}
usePrePhraseSnapshot: true
initialState:
documentContents: (aaa) @bbb
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}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
languageId: scm
command:
version: 5
spokenForm: clear state
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: statement}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
(
(aaa) @bbb
(#ccc? @bbb)
)
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
marks: {}
finalState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
languageId: scm
command:
version: 5
spokenForm: clear state
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: statement}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
(
(aaa) @bbb
(#ccc? @bbb)
)
selections:
- anchor: {line: 2, character: 4}
active: {line: 2, character: 4}
marks: {}
finalState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: scm
command:
version: 5
spokenForm: clear state
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: statement}
usePrePhraseSnapshot: true
initialState:
documentContents: "[(aaa) (bbb)] @ccc"
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}
8 changes: 8 additions & 0 deletions queries/scm.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(
(program
(_) @statement
) @_.iteration
(#not-type? @statement comment)
)
(comment) @comment @textFragment
(anonymous_node) @string @textFragment

0 comments on commit 3486f5d

Please sign in to comment.