Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate snippets support to community snippets, support multiple snippets #2804

Merged
merged 42 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
94a1226
Started working on snippet variants
AndreasArvidsson Feb 1, 2025
7d9cfac
More clean up
AndreasArvidsson Feb 1, 2025
a060a8a
More migrations
AndreasArvidsson Feb 1, 2025
70fde64
Rename
AndreasArvidsson Feb 1, 2025
46b9364
Check if language field exists
AndreasArvidsson Feb 1, 2025
adeb4c7
Added substitutions to list snippet
AndreasArvidsson Feb 1, 2025
bf9e84a
Support placeholder substitution
AndreasArvidsson Feb 1, 2025
37b48f5
Cleanup
AndreasArvidsson Feb 1, 2025
0c6c9e0
Update types
AndreasArvidsson Feb 1, 2025
2071759
Migrating tests
AndreasArvidsson Feb 1, 2025
1774b7f
Update test
AndreasArvidsson Feb 1, 2025
18d504b
Update more tests
AndreasArvidsson Feb 1, 2025
db35ddf
Updated more tests
AndreasArvidsson Feb 1, 2025
35b4d3a
Updated test
AndreasArvidsson Feb 1, 2025
93bb509
Rename name field to type
AndreasArvidsson Feb 1, 2025
854375b
More tests
AndreasArvidsson Feb 1, 2025
de41e41
Added test
AndreasArvidsson Feb 1, 2025
28d3d65
Update test fixtures
AndreasArvidsson Feb 1, 2025
76d8c47
Updated more tests
AndreasArvidsson Feb 1, 2025
7f5d4f6
Added tests
AndreasArvidsson Feb 1, 2025
415945a
More snippet cleanup
AndreasArvidsson Feb 1, 2025
afdea94
Update Talon grammar tests
AndreasArvidsson Feb 1, 2025
390427b
Merge branch 'main' into snippetVariants
AndreasArvidsson Feb 1, 2025
036117b
Rename fixture
AndreasArvidsson Feb 4, 2025
e3f4297
fix
phillco Feb 4, 2025
c8d2ed1
Update cursorless-talon/src/snippets.py
phillco Feb 4, 2025
835d0d3
Update cursorless-talon/src/snippets.py
phillco Feb 4, 2025
c21678c
Update cursorless-talon/src/snippets.py
phillco Feb 4, 2025
1966999
fix
phillco Feb 4, 2025
f12c7f4
Clean up
AndreasArvidsson Feb 4, 2025
a686e19
Merge branch 'snippetVariants' of github.com:cursorless-dev/cursorles…
AndreasArvidsson Feb 4, 2025
6730477
Fix
AndreasArvidsson Feb 4, 2025
725cd1f
Keyword argument
AndreasArvidsson Feb 4, 2025
8c5f44a
fix
phillco Feb 4, 2025
2d6bf5f
Update snippet
AndreasArvidsson Feb 4, 2025
8804054
Merge branch 'snippetVariants' of github.com:cursorless-dev/cursorles…
AndreasArvidsson Feb 4, 2025
6de2e62
Update test
AndreasArvidsson Feb 4, 2025
5d9d5fc
Properly fixed test
AndreasArvidsson Feb 4, 2025
372ff5d
Added that mark
AndreasArvidsson Feb 4, 2025
a12fe77
Merge branch 'main' into snippetVariants
phillco Feb 4, 2025
8bca281
Update test
AndreasArvidsson Feb 4, 2025
67cf59d
Removed that
AndreasArvidsson Feb 4, 2025
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
4 changes: 0 additions & 4 deletions cursorless-talon-dev/src/cursorless_test.talon
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ test api insert snippet:
user.cursorless_insert_snippet("Hello, $foo! My name is $bar!")
test api insert snippet <user.cursorless_destination> :
user.cursorless_insert_snippet("Hello, $foo! My name is $bar!", cursorless_destination, "statement")
test api insert snippet by name:
user.cursorless_insert_snippet_by_name("functionDeclaration")
test api wrap with snippet <user.cursorless_target>:
user.cursorless_wrap_with_snippet("Hello, $foo! My name is $bar!", cursorless_target, "foo", "statement")
test api wrap with snippet by name <user.cursorless_target>:
user.cursorless_wrap_with_snippet_by_name("functionDeclaration", "body", cursorless_target)
test api extract decorated marks <user.cursorless_target>:
user.private_cursorless_test_extract_decorated_marks(cursorless_target)
test api alternate highlight nothing:
Expand Down
16 changes: 0 additions & 16 deletions cursorless-talon-dev/src/spoken_form_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

mockedGetValue = ""

community_snippets_tag_name = "user.cursorless_use_community_snippets"


@ctx.action_class("user")
class UserActions:
Expand Down Expand Up @@ -99,20 +97,6 @@ def private_cursorless_spoken_form_test_mode(enable: bool): # pyright: ignore [
"Cursorless spoken form tests are done. Talon microphone is re-enabled."
)

def private_cursorless_use_community_snippets(enable: bool): # pyright: ignore [reportGeneralTypeIssues]
"""Enable/disable cursorless community snippets in test mode"""
if enable:
tags = set(ctx.tags)
tags.add(community_snippets_tag_name)
ctx.tags = list(tags)
else:
tags = set(ctx.tags)
tags.remove(community_snippets_tag_name)
ctx.tags = list(tags)
# Note: Test harness hangs if we don't print anything because it's
# waiting for stdout
print(f"Set community snippet enablement to {enable}")

def private_cursorless_spoken_form_test(
phrase: str, # pyright: ignore [reportGeneralTypeIssues]
mockedGetValue_: Optional[str],
Expand Down
18 changes: 1 addition & 17 deletions cursorless-talon/src/actions/generate_snippet.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import glob
from pathlib import Path

from talon import Context, Module, actions, registry, settings
from talon import Module, actions, registry, settings

from ..targets.target_types import CursorlessExplicitTarget

mod = Module()

ctx = Context()
ctx.matches = r"""
tag: user.cursorless_use_community_snippets
"""


@mod.action_class
class Actions:
Expand All @@ -33,17 +28,6 @@ def private_cursorless_migrate_snippets():

def private_cursorless_generate_snippet_action(target: CursorlessExplicitTarget): # pyright: ignore [reportGeneralTypeIssues]
"""Generate a snippet from the given target"""
actions.user.private_cursorless_command_no_wait(
{
"name": "generateSnippet",
"target": target,
}
)


@ctx.action_class("user")
class UserActions:
def private_cursorless_generate_snippet_action(target: CursorlessExplicitTarget): # pyright: ignore [reportGeneralTypeIssues]
actions.user.private_cursorless_command_no_wait(
{
"name": "generateSnippet",
Expand Down
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 @@ -9,6 +9,7 @@

required_actions = [
"user.homophones_get",
"user.insert_snippet_by_name",
"user.reformat_text",
]

Expand Down
14 changes: 0 additions & 14 deletions cursorless-talon/src/snippet_cursorless.talon

This file was deleted.

77 changes: 77 additions & 0 deletions cursorless-talon/src/snippet_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from dataclasses import dataclass

from .targets.target_types import CursorlessDestination, CursorlessTarget


@dataclass
class ScopeType:
type: str


# Insertion snippets


@dataclass
class CustomInsertionSnippet:
type = "custom"
body: str
scopeTypes: list[ScopeType] | None
languages: list[str] | None
substitutions: dict[str, str] | None


@dataclass
class ListInsertionSnippet:
type = "list"
substitutions: dict[str, str] | None
snippets: list[CustomInsertionSnippet]


@dataclass
class InsertSnippetAction:
name = "insertSnippet"
snippetDescription: CustomInsertionSnippet | ListInsertionSnippet
destination: CursorlessDestination


# Wrapper snippets


@dataclass
class CustomWrapperSnippet:
type = "custom"
body: str
variableName: str | None
scopeType: ScopeType | None
languages: list[str] | None


@dataclass
class ListWrapperSnippet:
type = "list"
snippets: list[CustomWrapperSnippet]


@dataclass
class WrapperSnippetAction:
name = "wrapWithSnippet"
snippetDescription: CustomWrapperSnippet | ListWrapperSnippet
target: CursorlessTarget


# Community types


@dataclass
class CommunityInsertionSnippet:
body: str
languages: list[str] | None = None
scopes: list[str] | None = None


@dataclass
class CommunityWrapperSnippet:
body: str
variable_name: str
languages: list[str] | None
scope: str | None
Loading
Loading