Skip to content

Commit 840fc48

Browse files
AndreasArvidssonphillco
authored andcommitted
Migrate snippets support to community snippets, support multiple snippets (#2804)
cursorless-dev/cursorless#2353 The Cursorless side of talonhub/community#1718 Will allow Cursorless to fetch multiple snippets from community and decide which one to use. ## Release notes Cursorless can now get multiple snippets from community. One for each language. Cursorless can then pick the correct snippet for the document language regardless of which document is focused at the moment. --------- Co-authored-by: Phillip Cohen <phillip@phillip.io>
1 parent b2f8842 commit 840fc48

8 files changed

Lines changed: 246 additions & 196 deletions

src/actions/generate_snippet.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import glob
22
from pathlib import Path
33

4-
from talon import Context, Module, actions, registry, settings
4+
from talon import Module, actions, registry, settings
55

66
from ..targets.target_types import CursorlessExplicitTarget
77

88
mod = Module()
99

10-
ctx = Context()
11-
ctx.matches = r"""
12-
tag: user.cursorless_use_community_snippets
13-
"""
14-
1510

1611
@mod.action_class
1712
class Actions:
@@ -33,17 +28,6 @@ def private_cursorless_migrate_snippets():
3328

3429
def private_cursorless_generate_snippet_action(target: CursorlessExplicitTarget): # pyright: ignore [reportGeneralTypeIssues]
3530
"""Generate a snippet from the given target"""
36-
actions.user.private_cursorless_command_no_wait(
37-
{
38-
"name": "generateSnippet",
39-
"target": target,
40-
}
41-
)
42-
43-
44-
@ctx.action_class("user")
45-
class UserActions:
46-
def private_cursorless_generate_snippet_action(target: CursorlessExplicitTarget): # pyright: ignore [reportGeneralTypeIssues]
4731
actions.user.private_cursorless_command_no_wait(
4832
{
4933
"name": "generateSnippet",

src/check_community_repo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
required_actions = [
1111
"user.homophones_get",
12+
"user.insert_snippet_by_name",
1213
"user.reformat_text",
1314
]
1415

src/snippet_cursorless.talon

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/snippet_types.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from dataclasses import dataclass
2+
3+
from .targets.target_types import CursorlessDestination, CursorlessTarget
4+
5+
6+
@dataclass
7+
class ScopeType:
8+
type: str
9+
10+
11+
# Insertion snippets
12+
13+
14+
@dataclass
15+
class CustomInsertionSnippet:
16+
type = "custom"
17+
body: str
18+
scopeTypes: list[ScopeType] | None
19+
languages: list[str] | None
20+
substitutions: dict[str, str] | None
21+
22+
23+
@dataclass
24+
class ListInsertionSnippet:
25+
type = "list"
26+
substitutions: dict[str, str] | None
27+
snippets: list[CustomInsertionSnippet]
28+
29+
30+
@dataclass
31+
class InsertSnippetAction:
32+
name = "insertSnippet"
33+
snippetDescription: CustomInsertionSnippet | ListInsertionSnippet
34+
destination: CursorlessDestination
35+
36+
37+
# Wrapper snippets
38+
39+
40+
@dataclass
41+
class CustomWrapperSnippet:
42+
type = "custom"
43+
body: str
44+
variableName: str | None
45+
scopeType: ScopeType | None
46+
languages: list[str] | None
47+
48+
49+
@dataclass
50+
class ListWrapperSnippet:
51+
type = "list"
52+
snippets: list[CustomWrapperSnippet]
53+
54+
55+
@dataclass
56+
class WrapperSnippetAction:
57+
name = "wrapWithSnippet"
58+
snippetDescription: CustomWrapperSnippet | ListWrapperSnippet
59+
target: CursorlessTarget
60+
61+
62+
# Community types
63+
64+
65+
@dataclass
66+
class CommunityInsertionSnippet:
67+
body: str
68+
languages: list[str] | None = None
69+
scopes: list[str] | None = None
70+
71+
72+
@dataclass
73+
class CommunityWrapperSnippet:
74+
body: str
75+
variable_name: str
76+
languages: list[str] | None
77+
scope: str | None

0 commit comments

Comments
 (0)