language-tools: svelte-language-server watcher doesn't work in neovim lspconfig
I’m in the same problem with my sveltekit project.
I’m using typescript-svelte-plugin.
Although typescript files (like +page.server.ts) works realtime, diagnostics of .svelte file does not updated.
I’m configuring root_pattern( {"package.json", "tsconfig.json", "tsconfig.jsonc", "node_modules"}) for svelte language server
https://user-images.githubusercontent.com/1560508/237040552-0a1be152-0c2b-45ab-b98c-3e927ffeae34.mov
_Originally posted by @ryoppippi in https://github.com/sveltejs/language-tools/issues/1415#issuecomment-1539681042_
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 55 (11 by maintainers)
Links to this issue
Commits related to this issue
- (fix) move fs watcher config to language-server (#2009) #2008 #1613 — committed to sveltejs/language-tools by jasonlyu123 4 years ago
- fix(svelte): solves sveltejs/language-tools#2008 — committed to matadaniel/LazyVim by matadaniel 2 years ago
- fix(svelte): added organize imports and prettier (#3466) * feat(svelte): add key binding for organize imports * fix(svelte): solves sveltejs/language-tools#2008 * feat(svelte): add formatter fo... — committed to LazyVim/LazyVim by matadaniel 2 years ago
- update svelte lsp to use fallback watcher Correctly updates based on changes to page.server.ts files https://github.com/sveltejs/language-tools/issues/2008 — committed to magicalpuffin/dotfiles by magicalpuffin 2 years ago
- feat(svelte): notify LSP of changes in JS/TS files The Svelte LSP does not attach to JS / TS files. To get notified about changes in these files, it "needs" to send a custom message via `notify`. Th... — committed to igorlfs/nvim-lspconfig by igorlfs a year ago
- feat(svelte): notify LSP of changes in JS/TS files The Svelte LSP does not attach to regular JS / TS files. To get notified about changes in these files, it "needs" to send a custom message via `noti... — committed to igorlfs/nvim-lspconfig by igorlfs a year ago
- feat(svelte): notify LSP of changes in JS/TS files The Svelte LSP does not attach to regular JS / TS files. To get notified about changes in these files, it "needs" to send a custom message via `noti... — committed to igorlfs/nvim-lspconfig by igorlfs a year ago
- feat(svelte): notify LSP of changes in JS/TS files The Svelte LSP does not attach to regular JS / TS files. To get notified about changes in these files, it "needs" to send a custom message via `noti... — committed to igorlfs/nvim-lspconfig by igorlfs a year ago
- feat(svelte): notify LSP of changes in JS/TS files #3958 The Svelte LSP does not attach to regular JS / TS files. To get notified about changes in these files, it "needs" to send a custom message via... — committed to neovim/nvim-lspconfig by igorlfs a year ago
Actually, you can just manually change the client capability in 0.9.x to have
dynamicRegistration = trueIf this still doesn’t work, please prepare a reproduction and report to neovim. Also, to reiterate,
$/onDidChangeTsOrJsFileis not a substitution for file watcher, They both exist for a reason.So It seems like neovim intentionally disabled didChangeWatchedFiles.dynamicRegistration in Linux because the watcher capability is limited. Currently, only Mac and Windows have
dynamicRegistration=true.https://github.com/neovim/neovim/blob/f69937fdbd162630c35e119e67bbbf052558c0e0/runtime/doc/news-0.10.txt#L185
Setting it to true does trigger the watcher registration but the file watch itself never triggers. For Linux users with 0.10 stable, You can set
lsp_capabilities.workspace.didChangeWatchedFilesto false. This will enable a fallback watcher with chokidar in the language server.Also, I probably have to repeat a thousand times in this kind of big thread.
$/onDidChangeTsOrJsFileis for unsaved changes. And we don’t add new files from$/onDidChangeTsOrJsFile. If you only use it, the new files won’t be loaded.For people for whom the hack is still not working it might be because you are using
ctx.filewhich when using telescope for example will be a relative path and not an absolute path. You can usectx.matchinstead, and it fixed it for me.Okay, this is a truly hacky things, but I solved this problem with this setting
We can update @ryoppippi’s snippet to work without requiring the file to be saved to disk, replicating the behavior in the svelte-vscode extension. It would enable us to do the following:
foo.tsimportsMyTypefrombar.svelte.MyTypeinfoo.ts.foo.ts.bar.svelteis now aware of the latest changes made in step 2.Some things I’m not sure of:
In the original svelte-vscode implementation, the
changes.rangeproperty is defined. However, I’m unsure as to how to define it in nvim. Nevertheless, this still works (maybe at the cost of some performance?) because “if only a text is provided it is considered to be the full content of the document.” (source).What is the best autocmd event(s) to use to balance performance and convenience. TBH, I’m not sure if we need to worry ourselves with performance at this point. I’m only mentioning this point due to the note in
TextChanged’s description.svelte-language-server: v0.16.1
This worked for me, nvim 0.10.0 on macOs, also working good for astro + svelte.
Make sure you include:
inside the 2nd param for
nvim_create_autocmdfunction. Otherwise, new autocmd is created on every new buffer svelte lsp get attached to.Please repoen, this entire extension literally doesn’t work, you install it copying/pasting the exact commands of the readme and nothing.
Thank you @amitgupta6 ! I was not able to really test this in Astro because I cannot easily restart it in the container test setup that they provide.
But it gave me an idea for my LazyVim setup that finally does the trick.
I added a
.config/nvim/lua/plugins/lspconfig.luawithThanks everyone for all the information. I got mine working by adding this into my
on_attach()function:I’m running
and
on latest macOS and problem persists.
Ah, I see, my bad.
Hey folks,
I’m porting the
$/onDidChangeTsOrJsFilenotification to lspconfig, so other users will have a better OOTB experience.At this point, I am ok with PR to add a workaround specific to neovim to enable the fallback chokidar watcher we have. If anyone wanted to contribute, you can find a way to detect if the client is neovim and if
evt.capabilities.workspace?.didChangeWatchedFiles.dynamicRegistrationis false in here https://github.com/sveltejs/language-tools/blob/ef92ff314e6f647c10c36b04c151da911453e19e/packages/language-server/src/server.ts#L126neovim 0.12.0-dev, svelte-language-server 0.17.15, this works for me:
Note the replacement
client:notifyforclient.notifysinceclient.notifyis deprecated in nvim 0.12Hello, I’ve been experiencing similar issues under the following circumstances:
Based on my understanding, the root cause of the problem appears to be Neovim’s watch behavior, not the Svelte language server itself. I found a related issue on Neovim’s GitHub and wanted to share it here: https://github.com/neovim/neovim/pull/30595 It looks like this fix will be included in version 0.11.
For anyone still struggling, I used following configuration in Astrovim and it worked
@jasonlyu123 i install the last version but not working and fixed using example of @ryoppippi