Skip to content

fix(svelte): use augroup to avoid creating multiple autocmds #3964

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

Merged
merged 1 commit into from
Jul 19, 2025

Conversation

igorlfs
Copy link
Contributor

@igorlfs igorlfs commented Jul 19, 2025

Follow up: #3958

As it turns out, we can't use both buffer and pattern in the same autocmd. And even if we could set the buffer, it is not necessarily the one the server is attaching to.

By removing the buffer we are creating a new autocmd every time the buffer attaches. The ideal solution would be to guard against that, but I'm not sure if that would be the best approach (I imagine there are some augroup shenanigans?).

@justinmk
Copy link
Member

if we could set the buffer, it is not necessarily the one the server is attaching to.

? the bufnr passed to on_attach is the buffer being attached.

Removing the pattern seems like the correct approach. A pattern isn't needed, on_attach already decided the "pattern" by matching against filetypes.

@SebasF1349
Copy link

The lsp attaches to svelte files, but the autocmd is for js/ts files, so the buffers and filetypes will be different. I have this autocmd in my config (with pattern and no buffer) and it worked last time I used svelte. I would only add a augroup.

@justinmk
Copy link
Member

justinmk commented Jul 19, 2025

oops, yeah then an augroup should be used.

this is why a code comment helps with this kind of thing. especially when multiple configs are working together, that isn't obvious.

@igorlfs igorlfs force-pushed the hotfix/svelte-attach-autocmd branch from f58fc9d to 54ed59a Compare July 19, 2025 17:20
@igorlfs
Copy link
Contributor Author

igorlfs commented Jul 19, 2025

oops, yeah then an augroup should be used.

Done! I also messed up, should have tested after setting the buffer 🤦🏼‍♂️

this is why a code comment helps with this kind of thing. especially when multiple configs are working together, that isn't obvious.

LMK if any comments would be useful now

@igorlfs igorlfs changed the title fix(svelte): do not specify both buffer and pattern fix(svelte): use augroup to avoid creating multiple autocmds Jul 19, 2025
@justinmk justinmk merged commit f47cd68 into neovim:master Jul 19, 2025
6 checks passed
@igorlfs igorlfs deleted the hotfix/svelte-attach-autocmd branch July 19, 2025 17:48
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.

3 participants