talonhub / community

Voice command set for Talon, community-supported.
MIT License
637 stars 782 forks source link

Cannot use 'attribute' snippet in typescriptreact files #1439

Closed jaresty closed 3 months ago

jaresty commented 5 months ago

I tried to use snip attribute in a typescript react file and I got this error:

2024-05-20 07:44:06.559 ERROR cb error topic="phrase" cb=SpeechSystem.engine_event
   16:      lib/python3.11/threading.py:995 * # cron thread
   15:      lib/python3.11/threading.py:1038* 
   14:      lib/python3.11/threading.py:975 * 
   13:                    talon/cron.py:156 | 
   12:                     talon/vad.py:23  | 
   11:                     talon/vad.py:129 | 
   10: talon/scripting/speech_system.py:369 | 
    9:             talon/engines/w2l.py:742 | 
    8:      talon/scripting/dispatch.py:134 | # 'phrase' main:EngineProxy._redispatch()
    7: talon/scripting/speech_system.py:66  | 
    6: -------------------------------------# [stack splice]
    5:      talon/scripting/dispatch.py:134 | # 'phrase' main:SpeechSystem.engine_event()
    4: talon/scripting/speech_system.py:442 | 
    3:      talon/scripting/executor.py:111 | 
    2:  talon/scripting/talon_script.py:707 | 
    1:  talon/scripting/talon_script.py:610 | 
talon.scripting.talon_script.TalonScriptError: 
 in script at /Users/tkma6d4/.talon/user/community/core/snippets/snippets.talon:1:
 > user.insert_snippet_by_name(snippet)
ValueError: Unknown snippet 'html.attribute'

I am on latest (presently this sha) of community and all of my custom snippets can be found here.

Expected behavior: snippet would be inserted Actual behavior: an error in talon logs

AndreasArvidsson commented 3 months ago

I can't find an attribute snippet in your linked directory. For the future is probably better if you link to a specific commit sha instead of master. If you could provide me with the snippet you were using that fails for you I can try to debug this.

jaresty commented 3 months ago

The attribute snippet is coming from stock community: https://github.com/talonhub/community/blob/main/core/snippets/snippets/html.snippet

AndreasArvidsson commented 3 months ago

Does any of the snippets in html work? Does "snip table" work? When you say that you are in a typescript react file. Is the file ending .tsx?

jaresty commented 3 months ago

You're right, it doesn't seem like any html snippets are working. The file does end in .tsx.

AndreasArvidsson commented 3 months ago

Can you try disabling the setting for custom snippets and see if that fixes it?

Also try a restart of Talon just to make sure there are no errors in the log.

jaresty commented 3 months ago

Sorry, which setting? Can't try right now but will when I can.

AndreasArvidsson commented 3 months ago

This one https://github.com/talonhub/community/blob/5b43105de53bae6e489d5b72bf0d6961ae7bb46c/settings.talon#L62

jaresty commented 3 months ago

I removed that and restarted talon and tried running snip attribute again and I got another error:

2024-07-21 21:15:42.772 ERROR     8:                 talon/scripting/talon_script.py:606| 
    7:                 talon/scripting/talon_script.py:308| 
    6:                      talon/scripting/actions.py:88 | 
    5: user/community/core/snippets/snippets_insert.py:19 | snippet: Snippet = actions.user.get_sn..
    4:                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    3:                      talon/scripting/actions.py:88 | 
    2:        user/community/core/snippets/snippets.py:63 | raise ValueError(f"Unknown snippet '{name}'")
    1:                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Unknown snippet 'html.attribute'

[The below error was raised while handling the above exception(s)]
AndreasArvidsson commented 3 months ago

This is really weird I can't recreate this problem. Can you use any javascript snippets in tsx? I assume you are on the latest community version?

jaresty commented 3 months ago

Yes I'm on latest community. I've got other tsx snippets that are working fine. Only the html ones were giving me trouble that I remember, will double check that and let you know.

jaresty commented 3 months ago

In case it helps, I setup my talon installation with this make file: https://github.com/jaresty/mac-dotfiles/blob/master/Makefile using 'make setup'. I've got a separate snippets folder in my dotfiles for JavaScript and typescript snippets but haven't defined my own html snippets.

jaresty commented 3 months ago

My personal talon settings are here: https://github.com/jaresty/mac-dotfiles/tree/master/talon-settings

AndreasArvidsson commented 3 months ago

I don't have the time to debug your make file. Please try this with a unmodified community. I can't recreate the problem on my end and I need to make sure that it's not something with your set up.

jaresty commented 3 months ago

I have not modified community at all. When I remove my settings from the talon folder it does not recognize the snippet command at all. After doing that I see this error in the logs:

2024-07-22 11:06:46.381 ERROR cb error topic="phrase" cb=SpeechSystem.engine_event
   16:      lib/python3.11/threading.py:995 * # cron thread
   15:      lib/python3.11/threading.py:1038* 
   14:      lib/python3.11/threading.py:975 * 
   13:                    talon/cron.py:156 | 
   12:                     talon/vad.py:23  | 
   11:                     talon/vad.py:129 | 
   10: talon/scripting/speech_system.py:369 | 
    9:             talon/engines/w2l.py:742 | 
    8:      talon/scripting/dispatch.py:134 | # 'phrase' main:EngineProxy._redispatch()
    7: talon/scripting/speech_system.py:66  | 
    6: -------------------------------------# [stack splice]
    5:      talon/scripting/dispatch.py:134 | # 'phrase' main:SpeechSystem.engine_event()
    4: talon/scripting/speech_system.py:442 | 
    3:      talon/scripting/executor.py:111 | 
    2:  talon/scripting/talon_script.py:707 | 
    1:  talon/scripting/talon_script.py:610 | 
talon.scripting.talon_script.TalonScriptError: 
 in script at /Users/tkma6d4/.talon/user/community/core/snippets/snippets.talon:1:
 > user.insert_snippet_by_name(snippet)
ValueError: Unknown snippet 'html.attribute'
jaresty commented 3 months ago

This is how the folder is laid out locally:

total 96
-rw-r--r--   1 tkma6d4  staff   1168 Jun 30 23:15 BREAKING_CHANGES.txt
-rw-r--r--   1 tkma6d4  staff   1400 Jul  6 13:22 CONTRIBUTING.md
-rw-r--r--   1 tkma6d4  staff   1125 Feb 14 08:21 LICENSE
-rw-r--r--   1 tkma6d4  staff  21474 Jul  6 11:48 README.md
drwxr-xr-x  74 tkma6d4  staff   2368 Jul  6 14:02 apps/
drwxr-xr-x  34 tkma6d4  staff   1088 Jul 21 19:49 core/
drwxr-xr-x  26 tkma6d4  staff    832 Jun 30 23:15 lang/
drwxr-xr-x  26 tkma6d4  staff    832 Jul  7 18:32 plugin/
-rw-r--r--   1 tkma6d4  staff    194 Feb 14 08:21 pyproject.toml
-rw-r--r--   1 tkma6d4  staff     14 Feb 14 08:21 requirements-dev.txt
lrwxr-xr-x@  1 tkma6d4  staff     42 Jul 22 11:10 settings@ -> /Users/tkma6d4/mac-dotfiles/talon-settings
-rw-r--r--   1 tkma6d4  staff   3810 Jul  6 14:02 settings.talon
drwxr-xr-x  16 tkma6d4  staff    512 Jun 30 23:15 tags/
drwxr-xr-x   7 tkma6d4  staff    224 Feb 14 08:21 test/
❯ git status
On branch main
Your branch is up to date with 'upstream/main'.

nothing to commit, working tree clean
/Users/tkma6d4/.talon/user/community
jaresty commented 3 months ago

I do have this setup in my cursorless configuration in VSCode:

image

jaresty commented 3 months ago

snip for each (coming from community, javascript) works, but the html snippets do not.

jaresty commented 3 months ago

I did a little experiment that I'm pretty sure is the wrong way to solve this problem, but it does seem to work. If I add the language typescript to the existing snippet for HTML, I can then use it in .tsx files: image

AndreasArvidsson commented 3 months ago

Thanks for your testing. Now I think I have a solution. Can you try and uncomment this line? https://github.com/talonhub/community/blob/bcd6a64428d0b5d392dfe91722f09b6385a052f7/core/modes/language_modes.py#L19

I think that will solve your problem. Here is a pr to fix it in community. https://github.com/talonhub/community/pull/1506

jaresty commented 3 months ago

That was it!