Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cursorless-talon/src/check_community_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
]

required_actions = [
"code.language",
"user.homophones_get",
"user.insert_snippet_by_name",
"user.reformat_text",
Expand Down
2 changes: 2 additions & 0 deletions cursorless-talon/src/snippets/snippet_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def create(
@dataclass
class ListInsertionSnippet:
type = "list"
fallbackLanguage: str | None
substitutions: dict[str, str] | None
snippets: list[CustomInsertionSnippet]

Expand Down Expand Up @@ -98,6 +99,7 @@ def create(snippet: CommunityWrapperSnippet):
@dataclass
class ListWrapperSnippet:
type = "list"
fallbackLanguage: str | None
snippets: list[CustomWrapperSnippet]


Expand Down
2 changes: 1 addition & 1 deletion cursorless-talon/src/snippets/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class UserActions:
def insert_snippet_by_name(
name: str, # pyright: ignore [reportGeneralTypeIssues]
# Don't add optional: we need to match the type in community
substitutions: dict[str, str] = None,
substitutions: dict[str, str] = None, # type: ignore
):
action = InsertSnippetAction(
get_list_insertion_snippet(name, substitutions),
Expand Down
9 changes: 9 additions & 0 deletions cursorless-talon/src/snippets/snippets_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def get_list_insertion_snippet(
raise

return ListInsertionSnippet(
get_fallback_language(),
substitutions,
[CustomInsertionSnippet.create(s) for s in snippets],
)
Expand All @@ -49,5 +50,13 @@ def get_list_wrapper_snippet(name: str) -> ListWrapperSnippet | CustomWrapperSni
raise

return ListWrapperSnippet(
get_fallback_language(),
[CustomWrapperSnippet.create(s) for s in snippets],
)


def get_fallback_language():
language = actions.code.language()
if language and isinstance(language, str):
return language
return None
42 changes: 42 additions & 0 deletions data/fixtures/recorded/actions/snippets/ifWrapAir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
languageId: typescript
command:
version: 7
spokenForm: if wrap air
action:
name: wrapWithSnippet
snippetDescription:
type: list
snippets:
- type: custom
body: "if ($1) {\n\t$0\n}"
variableName: "0"
languages: [c, cpp, csharp, java, javascript, typescript, javascriptreact, typescriptreact]
target:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: a}
usePrePhraseSnapshot: true
spokenFormError: list wrap with snippet
initialState:
documentContents: aaa
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks:
default.a:
start: {line: 0, character: 0}
end: {line: 0, character: 3}
finalState:
documentContents: |-
if () {
aaa
}
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
thatMark:
- type: UntypedTarget
contentRange:
start: {line: 0, character: 0}
end: {line: 2, character: 1}
isReversed: false
hasExplicitRange: true
43 changes: 43 additions & 0 deletions data/fixtures/recorded/actions/snippets/ifWrapAir2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
languageId: plaintext
command:
version: 7
spokenForm: if wrap air
action:
name: wrapWithSnippet
snippetDescription:
type: list
fallbackLanguage: typescript
snippets:
- type: custom
body: "if ($1) {\n\t$0\n}"
variableName: "0"
languages: [c, cpp, csharp, java, javascript, typescript, javascriptreact, typescriptreact]
target:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: a}
usePrePhraseSnapshot: true
spokenFormError: list wrap with snippet
initialState:
documentContents: aaa
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks:
default.a:
start: {line: 0, character: 0}
end: {line: 0, character: 3}
finalState:
documentContents: |-
if () {
aaa
}
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
thatMark:
- type: UntypedTarget
contentRange:
start: {line: 0, character: 0}
end: {line: 2, character: 1}
isReversed: false
hasExplicitRange: true
49 changes: 49 additions & 0 deletions data/fixtures/recorded/actions/snippets/snipIf2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
languageId: plaintext
command:
version: 7
spokenForm: snip if
action:
name: insertSnippet
snippetDescription:
type: list
fallbackLanguage: typescript
snippets:
- type: custom
body: "if ($1) {\n\t$0\n}"
scopeTypes:
- {type: statement}
languages: [c, cpp, csharp, java, javascript, typescript, javascriptreact, typescriptreact]
- type: custom
body: "if $1:\n\t$0"
scopeTypes:
- {type: statement}
languages: [python]
- type: custom
body: "if $1 then\n\t$0\nend"
scopeTypes:
- {type: statement}
languages: [lua]
destination: {type: implicit}
usePrePhraseSnapshot: false
spokenFormError: list insertion snippet
initialState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: |-
if () {

}
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
thatMark:
- type: UntypedTarget
contentRange:
start: {line: 0, character: 0}
end: {line: 2, character: 1}
isReversed: false
hasExplicitRange: true
6 changes: 4 additions & 2 deletions packages/common/src/types/command/ActionDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ export interface CustomInsertSnippetArg {
substitutions?: Record<string, string>;
}

interface ListInsertSnippetArg {
export interface ListInsertSnippetArg {
type: "list";
fallbackLanguage?: string;
substitutions?: Record<string, string>;
snippets: CustomInsertSnippetArg[];
}
Expand Down Expand Up @@ -190,8 +191,9 @@ export interface CustomWrapWithSnippetArg {
languages?: string[];
}

interface ListWrapWithSnippetArg {
export interface ListWrapWithSnippetArg {
type: "list";
fallbackLanguage?: string;
snippets: CustomWrapWithSnippetArg[];
}

Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/types/snippet.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { SimpleScopeTypeType } from "./command/PartialTargetDescriptor.types";

// FIXME: Legacy snippets

export interface SnippetScope {
/**
* VSCode language ids where this snippet definition should be active
Expand Down

This file was deleted.

Loading
Loading