-
Notifications
You must be signed in to change notification settings - Fork 796
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
Extend snippet functionality #1707
Comments
This looks solid to me. And I think we can re-use the code we have floating around in Cursorless for selecting snippet based on context; it has some good tests Re the problems, for 1) I don't have any better ideas; these two fields were the best I could come up with. For 2), that's a good question. Might be worth asking on slack |
Sounds good Could we use something like |
I'm doing some testing
Using a on ready callback to check the registry if the action exists. If it does we can activate a new tag that enables the new context and our action overrides. This sounds like a good way forward. |
After some more digging through the code I don't think we need to context override any new actions. The only thing we need to introduce is a getter actions so that Cursorless Talon can actually get multiple snippets. eg |
Here is my suggestion Here is the Cursorless changes. In essence Cursorless puts its own version off |
* Added actions to get multiple snippets for the same name. Can be used by extensions like Cursorless to make better decisions about which snippet to use. * Simplified the snippet code and added stronger types * Only update Talon lists if they have actually changed. Fixes #1707 Fixes #1373 --------- Co-authored-by: Nicholas Riley <[email protected]> Co-authored-by: Jeff Knaus <[email protected]>
Once cursorless-dev/cursorless#2747 is merged we have a way of migrating Cursorless snippet to the community snippet format. Having one single easy to use format for all Talon users is a nice improvement, but the Cursorless snippet format did have two features that the community format is missing. My intent is to extend the community snippet format to support these.
The two Cursorless snippet features missing from community snippets are:
eg you are in a markdown file and say
"snip air after blue bat"
.blue bat
is in another split and in python. The Cursorless snippet implementation would pick the language for the editor you are inserting the snippet into regardless of what the active/focused editor's language is.eg in javascript a function looks like
function foo() { }
, but a method in a class looks likefoo() { }
. With the Cursorless snippet format you can just say"snip funk"
and Cursorless would figure out which one of the two snippet to use. To do this Cursorless snippets have two extra fieldsscopeTypes
andexcludeDescendantScopeTypes
to make its match with.Proposed solution
For both these features we need to send multiple snippets from Talon to Cursorless. Today community does its snippet insertion using the action
def insert_snippet(body: str)
. What we could do is to add an action likedef insert_snippet_variants(snippets: list[Snippet])
. The default module implementation would just be to pick the first snippet corresponding to the active language and then callinsert_snippet
. Cursorless on the other hand could context overrideinsert_snippet_variants
to send all snippet variants to the Cursorless extension using the command client. After that Cursorless can pick the best snippet. Thanks @phillco for this idea.We still need to figure out how to either implement or replace
scopeTypes
andexcludeDescendantScopeTypes
in the community format.The reason why we need both of these fields is
scopeTypes
would specifyclass
so Cursorless knows to use the method snippet body when you're inside a class andexcludeDescendantScopeTypes
would specifyfunction
so that Cursorless knows to NOT use a method snippet when inside a function.Example snippets
Problems
The text was updated successfully, but these errors were encountered: