Skip to content

Conversation

nriley
Copy link

@nriley nriley commented Jun 14, 2025

As discussed on the community backlog session today.

It turns out that Cursorless already has support for inserting snippets when you have a forced language, but not when VSCode doesn't support the language that Talon thinks you're using (e.g. via an extension map).

2025-06-14 13:56:05.190    IO > snip if
2025-06-14 13:56:05.212    IO exception: e=Exception("No snippet available for language '...'. Available languages: c, cpp, csharp, elixir, go, java, javascript, javascriptreact, kotlin, lua, php, python, r, ruby, rust, scala, stata, typescript, typescriptreact, vimscript")
2025-06-14 13:56:05.214 ERROR    19:                                   talon/scripting/talon_script.py:734| 
   18:                                   talon/scripting/talon_script.py:326| 
   17:                                        talon/scripting/actions.py:88 | 
   16:                    user/cursorless-talon/src/snippets/snippets.py:114| actions.user.private_cursorless_comman..
   15:                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   14:                                        talon/scripting/actions.py:88 | 
   13:                              user/cursorless-talon/src/command.py:36 | response = actions.user.private_cursor..
   12:                                                                        
   11:                                        talon/scripting/actions.py:88 | 
   10:            user/cursorless-talon/src/cursorless_command_server.py:39 | return actions.user.run_rpc_command_ge..
    9:                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    8:                                        talon/scripting/actions.py:88 | 
    7:        user/talon_community/core/command_client/command_client.py:113| return run_command(
    6:                                                                                       
    5:        user/talon_community/core/command_client/command_client.py:55 | return actions.user.rpc_client_run_com..
    4:                                                                                
    3:                                        talon/scripting/actions.py:88 | 
    2: user/talon_community/core/command_client/rpc_client/rpc_client.py:102| raise Exception(decoded_contents["error"])
    1:                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception: No snippet available for language '...'. Available languages: c, cpp, csharp, elixir, go, java, javascript, javascriptreact, kotlin, lua, php, python, r, ruby, rust, scala, stata, typescript, typescriptreact, vimscript

Forced languages still use RPC to insert a snippet:

[3416.400] user/talon_community/plugin/command_history/command_history.py | IO > snip if else
[3416.400] user/talon_community/plugin/subtitles/on_phrase.py | action speech.enabled()
[3416.401] user/talon_community/core/snippets/snippets.talon | action user.insert_snippet_by_name('ifElseStatement')
[3416.401] user/talon_community/core/snippets/snippets_insert.py | action user.get_snippet('ifElseStatement')
[3416.401] user/talon_community/core/snippets/snippets.py | action user.get_snippets('ifElseStatement')
[3416.401] user/talon_community/core/snippets/snippets.py | action code.language()
[3416.401] user/talon_community/core/snippets/snippets_insert.py | action user.insert_snippet('if $1:\n\t$2\nelse:\n\t$0')
[3416.401] user/talon_community/apps/vscode/vscode.py | action user.run_rpc_command('editor.action.insertSnippet', {'snippet': 'if $1:\n\t$2\nelse:\n\t$0'})
[3416.401] user/talon_community/core/command_client/command_client.py | action user.command_server_directory()
[3416.401] user/talon_community/core/command_client/command_client.py | action user.rpc_client_run_command('vscode-command-server', user.trigger_command_server_command_execution()
    Issue keystroke to trigger command server to execute command that
was written to the file.  For internal use only, 'editor.action.insertSnippet', [{'snippet': 'if $1:\n\t$2\nelse:\n\t$0'}], False, False)
[3416.401] user/talon_community/core/command_client/rpc_client/rpc_client.py | action user.trigger_command_server_command_execution()

It seemed easier to do this on the cursorless-talon side since I'm trying to identify this exception rather than just having a universal fallback — don't want to suppress other exceptions.

@nriley nriley marked this pull request as ready for review June 14, 2025 18:26
@nriley nriley requested a review from a team as a code owner June 14, 2025 18:26
@AndreasArvidsson
Copy link
Member

AndreasArvidsson commented Jun 16, 2025

Unfortunately I don't think this implementation is the best one for a few reasons:

  1. The thrown error triggers aa error pop up in vscode even if you catch it Talon side.
  2. There are three different actions in the same file that tries to insert a snippet from a list. I would want the same fallback behavior for all three.

I have two different suggestions:

  1. If you have a particular application/context that sets an unknown language you could just use the tag user.code_language_forced to circumvent Cursorless list lookup.
  2. If you want something that will work in all context we could add another field to the list snippet with a fallback language.

2 is probably the better solution, but a more complicated. I could make the changes if you prefer.

@nriley
Copy link
Author

nriley commented Jun 16, 2025

Thanks. I didn't see the error messages in testing, oddly enough but maybe I wasn't looking hard enough.

I'd prefer not to force a language unnecessarily. I can close this PR if you want to do #2.

@AndreasArvidsson
Copy link
Member

This is what I was thinking. If you are happy with my suggested solution you can close this pull request.
#2984

@nriley nriley closed this Jun 17, 2025
@AndreasArvidsson
Copy link
Member

@nriley #2984 is merged now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants