-
Notifications
You must be signed in to change notification settings - Fork 311
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
Emacs Snippets not working anymore with Tree Sitter Major Modules #1169
Comments
For you you can get in working by adding |
My workaround: (advice-add 'yas--modes-to-activate :around
(defun yas--get-snippet-tables@tree-sitter (orig-fn &optional mode)
(funcall orig-fn
(or (car (rassq (or mode major-mode) major-mode-remap-alist))
mode)))) |
@twlz0ne This is not working for me, at least for C++. Any other workaround? |
In case somebody needs a workaround to work today, I found this that seems to work |
@jvillasante Don't know why not working for you, the advice above just tells yas to use (car (rassq 'c++-ts-mode major-mode-remap-alist))
;; => c++-mode
(and (yas--get-snippet-tables 'c++-mode) t)
;; => t |
Thanks a lot @jvillasante, yasnippet-treesitter-shim looks like a great workaround - although IMHO really this should work out of the box with yasnippet rather than needing a separate package as a bandaid 😞 |
Bandaid to fix yasnippet not working with treesit modes out of the box: joaotavora/yasnippet#1169 fbrosda/yasnippet-treesitter-shim#1
I got the shim working with |
looks like a great workaround - although IMHO really this should work out of
the box with yasnippet rather than needing a separate package as
a bandaid 😞
I just pushed a patch to `master` which should hopefully help.
Can someone confirm it fixes the problem for them?
|
@monnier Thanks so much for working on this! I have just tested, and can confirm it works 🚀 BTW I tested it by setting So I had to set it globally via:
This means that while your commit is working as intended, it won't work out of the box with |
I wrote:
I've filed renzmann/treesit-auto#76 to track this. |
This means that while your commit is working as intended, it won't work out
of the box with `treesit-auto.el` yet.
Hmm... I wonder why my code isn't seeing the buffer-local value that
`treesit-auto` sets for `major-mode-remap-alist`.
AFAICT the yasnippet code should be run inside the buffer and after
`treesit-auto` intervened, so it should see the relevant value.
Could you `M-x trace-function RET` on the following functions:
yas--modes-to-activate
yas-minor-mode
yas--get-snippet-tables
yas--load-pending-jits
treesit-auto--set-major-remap
set-auto-mode-0
and then see what the trace looks like?
|
I will do that when I get a moment (how did I use emacs for 30 years and only just hear about Somehow treesit-auto correctly executes the |
I've commented the same point in renzmann/treesit-auto#76 (comment), so perhaps that would be a better place to continue this conversation for now, since it currently looks like more of an issue with |
*Where* do you see that it has value nil?
Since it's a buffer-local setting, the buffer in which you are when you
look at the value can make all the difference.
You might also want to use `M-x debug-on-variable-change` on
`major-mode-remap-alist` (which reminds me that we should also add
`trace-variable` to `trace.el`).
|
Yep, I appreciate the difference and did check that carefully: I see it as
It's strange, but perhaps something else is resetting the variable to Anyhow, I will try |
OK, this is interesting and seems relevant! I tried
However after continuing from this, the debugger reactivated again with this:
I can't figure out why |
However after continuing from this, the debugger reactivated again with this:
```
Debugger entered--killing local value of major-mode-remap-alist in buffer Options.tsx:
debug--implement-debug-watch(major-mode-remap-alist nil makunbound #<buffer Options.tsx>)
prog-mode()
Ah, yes, of course: the first thing that a major mode does is kill "all"
buffer-local variables (basically, to "reset" the settings installed by
any previous major mode).
|
Hrm, so does this mean that |
Hrm, so does this mean that `treesit-auto`'s approach is fundamentally flawed?
Don't know, but it does mean that Yasnippet can't get treesit-auto's
information via `major-mode-remap-alist` for free.
Stefan
|
OK thanks, so for now the workarounds are either to use https://github.com/fbrosda/yasnippet-treesitter-shim or my hack of setting it globally: (setq major-mode-remap-alist (treesit-auto--build-major-mode-remap-alist)) I think any further discussion on the treesit-auto side of things belongs in renzmann/treesit-auto#76. |
OK thanks, so for now the workarounds are either to use
https://github.com/fbrosda/yasnippet-treesitter-shim or [my
hack](aspiers/emacs@b579a4c)
of setting it globally:
```elisp
(setq major-mode-remap-alist (treesit-auto--build-major-mode-remap-alist))
```
Yes. `treesit-auto` (and `major-mode-remap-alist`) is designed to
redirect FOO-mode to FOO-ts-mode, whereas YASnippet needs something
different, which is to know that FOO-ts-mode is a "kind of" FOO-mode.
This should be used both for the users that want to redirect FOO-mode to
FOO-ts-mode and for those that don't do that but which invoked
FOO-ts-mode some other way (such as manually).
So I think the canonical way should be for the major mode to use
`derived-mode-add-parents` to declare its relationship.
I just pushed to `master` a patch which makes YASnippet use
`derived-mode-all-parents` so as to obey such settings.
Since this functionality is new in Emacs-30, the code still tries to use
`major-mode-remap-alist`, but that's just a crutch which will cover
only *some* configs 🙁.
BTW, instead of having "dummy" snippets with `.yas-parents` pointing to
the real snippets, like `yasnippet-treesitter-shim` does, maybe we
should allow snippets to have not only `.yas-parents` but also
`.yas-children`.
|
Yep, that all makes sense. |
I started to use only the new build in tree-sitter for my languages.
So for example instead of
typescipt-mode
I am now usingtypescipt-ts-mode
.Since I switched yasnippets are not showing up anymore. I guess yasnippet doesn't understand that typescript-ts-mode needs the same snippets as
typescript
mode.I was basically following instructions here:
https://www.masteringemacs.org/article/how-to-get-started-tree-sitter
I was hoping that the major-mode-remap list would take care of that mapping, but that doesn't seem to work for yasnippet.
Any ideas?
The text was updated successfully, but these errors were encountered: