Open alexciarlillo opened 5 months ago
Does the error happen on every js file opened or only files from the project mentioned? Currently I have no idea how this could happen, but if the error didn't occur with typescript-language-server
, it is very likely the problem is from here. Could you provide a tsserver log for this error by command open_tsserver_log
to help troubleshooting? The log will contain the source files it recognized contained in the project and we can see if the reported missing source file is in there.
Do I need verbose logging on for this? The project is quite large and the verbose file is huge and also appears to have some of the file contents. I want to ensure I am not potentially leaking anything from sharing these logs.
Do I need verbose logging on for this?
Yes, verbose logging is needed.
I want to ensure I am not potentially leaking anything from sharing these logs.
I see. Does the error only happen on the specific project or any random js files? You can just try to create another test project and open a js file in it to reproduce the error and provide the log from it, which does not contain any sensitive information.
It does appear so far to be limited to only this project and it does not seem to happen on every file. I am starting to think it is possibly our jsconfig files which are to blame here. We have code that generates these for us because we use some custom named module importing stuff. I just never had an issue with this previously but I am thinking it could just as likely be a newer tsserver / typescript version rather than vtsls itself. I had not really taken updates to my neovim config for a while so a lot of things changed.
I am going to go ahead and close this out and will try troubleshooting through the logs myself as time permits. I don't want to clutter things up with issues which are likely specific to my weird gigantic legacy project 🤣 If I do find anything that definitively points to vtsls I'll let you know.
Thanks!
For what it's worth I'm noticing this a lot on monorepo projects.
@helgardferreira Did you see the error on file open and the reported missing file is the current file? If you could provide client lsp log (with file content removed) or reproduction for it, we can track it in another issue.
I'm seeing this a lot, too. I can't currently correlate when or how this starts happening but here's what I know:
[WARN][2024-06-28 11:31:47] ...lsp/handlers.lua:135 "The language server eslint triggers a registerCapability handler for workspace/didChangeWorkspaceFolders despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[WARN][2024-06-28 11:32:36] ...m/lsp/client.lua:1023 "server_request: no handler found for" "workspace/diagnostic/refresh"
[ERROR][2024-06-28 11:32:36] ...lsp/handlers.lua:623 "Failed to refresh diagnostics"
[ERROR][2024-06-28 13:19:10] .../vim/lsp/rpc.lua:770 "rpc" "/Users/max/.local/share/nvim/mason/bin/vtsls" "stderr" "node:internal/process/promises:289\n triggerUncaughtException(err, true /* fromPromise */);\n ^\n\n_TypeScriptServerError: <semantic> TypeScript Server Error (5.4.5)\nCould not find source file: /path/to/file
---snip---
@gegenschall Thanks for your information. But unfortunately the logs before the error are from eslint and not related here... It would be really helpful if log level could be set to debug to show more context about the error, like if the file is opened before and the request triggering the error.
There are also some config options you can try to play with (also for anyone encountering the same issue):
typescript.tsserver.maxTsServerMemory
: This defaults to 3GB, maybe needs to be adjusted to fit the large monorepo.typescript.tsserver.watchOptions
: This controls how the tsserver tracks file, see the schema for it where different watching strategies are available for testing.vtsls.autoUseWorkspaceTsdk
: Toggle this to see if the problem is related to the version of typescript used.That's awesome, @yioneko. I'll keep my config as is and switch on debug logging in the hope of triggering those errors and then fiddle around with the parameters after.
I believe it happens more often if files are actually moved and/or there's large amounts of errors in those files. LspRestart
doesn't always help, I have to close and reopen nvim usually.
Will report back.
I am also experiencing the same error, but it only happens on new files and open that file really quick after create. ( Also only if the project is huge which means there's lots of types declaration ) E.g. if I open that file few seconds after creating it the vtsls server will not crash.
LspRestart doesn't always help, I have to close and reopen nvim usually.
The server crashed ( at least in my case ) so you need to LspStart vtsls
Finally have some idea how this could happen. Does the error usually triggered on server starting?
@RayGuo-ergou Could you test with the following key mapping (pressing <A-i>
will delete and create the file at the maximum possible speed):
vim.keymap.set("n", "<A-i>", function()
local fname = "fast_create.ts"
local cname = A.nvim_buf_get_name(A.nvim_get_current_buf())
if vim.fn.fnamemodify(cname, ":t") == fname then
vim.cmd.bdelete({ bang = true })
os.remove(cname)
else
local file = io.open(fname, "w")
file:write("")
file:close()
vim.cmd.edit({ args = { fname } })
end
end, {})
If this is 100% reproducible for you, then the problem would be much easier to work on. And if possible, please post the full error stack for tracing the original request.
Hi @yioneko Thanks for that, I have tried that and found the issue would not happen on ts
files but vue
files. 🤔 I am not sure now is it vue plugin's issue or vtsls, btw tsserver
also have issue with new vue
file but in my case tsserver
will not crash it just not working for the new file but vtsls
does crash.
Here's the crash log
[ERROR][2024-07-01 22:35:46] .../vim/lsp/rpc.lua:772 "rpc" "/home/raydev/.local/share/nvim/mason/bin/vtsls" "stderr" "node:internal/process/promises:391
triggerUncaughtException(err, true /* fromPromise */);
^
\n_TypeScriptServerError:
@RayGuo-ergou Thanks, it is much clearer now. Did you see something like A non-recoverable error occurred while executing tsserver command: encodedSemanticClassifications-full
before the crashing log? It seems that the crashing is due to the request of semantic tokens. Does it still crash if you set server_capabilities.textDocument.semanticTokens = nil
in nvim?
Sometimes I will get this error message about semantic token
( not always and not in lsp log).
Error 13:35:58 msg_show.lua_error Error executing vim.schedule lua callback: ...local/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:309: ...local/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:102: Invalid buffer id: 13
stack traceback:
[builtin#36]: at 0x5652345912a0
...local/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:309: in function 'handler'
/usr/local/share/nvim/runtime/lua/vim/lsp/client.lua:687: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
Below is messages before the log above. Which I don't think it's related.
I have added this to my config but it still happening
mason_lspconfig.setup({
handlers = {
function(server_name)
local server = servers[server_name] or {}
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
+ if server_name == 'vtsls' then
+ server.capabilities.textDocument.semanticTokens = nil
+ end
print(vim.inspect(server.capabilities))
require('lspconfig')[server_name].setup(server)
end,
},
})
The error message are the same
[ERROR][2024-07-02 13:48:01] .../vim/lsp/rpc.lua:772 "rpc" "/home/raydev/.local/share/nvim/mason/bin/vtsls" "stderr" "node:internal/process/promises:391
triggerUncaughtException(err, true /* fromPromise */);
^
\n_TypeScriptServerError:
It still shows error for getEncodedSemanticClassifications
wondering if that used by vue languager server plugin? 🤔
Sorry, it is my bad. We should use server_capabilities.semanticTokensProvider = nil
to disable semantic tokens on nvim client.
The vim.schedule
error is an issue on nvim side and I could see that too. It is caused by not checking buffer validity in async callback.
If you didn't see the message before the crashing log, then I think it is not the semantic tokens that causing the crash. Could you see more detailed logs by vim.lsp.set_log_level("DEBUG")
before crashing?
Sorry, it is my bad. We should use server_capabilities.semanticTokensProvider = nil to disable semantic tokens on nvim client.
After this I got these errors ( by searching with [ERROR]
. ). It seems it's caused by vue-plugin. 🤔
```
[ERROR][2024-07-02 15:08:41] ...lsp/handlers.lua:624 "[Vue Named Pipe Client] Timeout"
```
```
[ERROR][2024-07-02 15:08:41] ...lsp/handlers.lua:624 "[Vue Named Pipe Client] Timeout"
```
[ERROR][2024-07-02 15:08:59] .../vim/lsp/rpc.lua:772 "rpc" "/home/raydev/.local/share/nvim/mason/bin/vue-language-server" "stderr" "/home/raydev/.local/share/nvim/mason/packages/vue-language-server/node_modules/@vue/language-server/node_modules/@vue/language-service/lib/plugins/vue-sfc.js:184\n label: base.label + ' lang=\"ts\"',\n ^\n\nTypeError: Cannot read properties of undefined (reading 'label')\n at createCompletionItemWithTs (/home/raydev/.local/share/nvim/mason/packages/vue-language-server/node_modules/@vue/language-server/node_modules/@vue/language-service/lib/plugins/vue-sfc.js:184:21)\n at Object.provideCompletionItems (/home/raydev/.local/share/nvim/mason/packages/vue-language-server/node_modules/@vue/language-server/node_modules/@vue/language-service/lib/plugins/vue-sfc.js:164:25)\n at async worker (/home/raydev/.local/share/nvim/mason/packages/vue-language-server/node_modules/@vue/language-server/node_modules/@volar/language-service/lib/features/provideCompletionItems.js:128:42)\n at async Object.getCompletionItems (/home/raydev/.local/share/nvim/mason/packages/vue-language-server/node_modules/@vue/language-server/node_modules/@volar/language-service/lib/features/provideCompletionItems.js:169:25)\n at async /home/raydev/.local/share/nvim/mason/packages/vue-language-server/node_modules/@vue/language-server/node_modules/@volar/language-server/lib/register/registerLanguageFeatures.js:97:30\n at async Timeout.
I believe the error is from volar (the language server attached to vue file, not ts plugin):
... "rpc" "/path/to/bin/vue-language-server" ...
and seems unrelated here. Does vtsls crashed this time?
Oh sorry my bad, the crashed server this time is volar. It looks very similar to vtsls
Warn 17:06:55 notify.warn Client volar quit with exit code 1 and signal 0. Check log for errors: /home/raydev/.local/state/nvim/lsp.log
Btw the way I disable semanticTokensProvider is via command e.g.
:lua vim.lsp.get_active_clients()[4].server_capabilities.semanticTokensProvider = nil
4
is vtsls's id I manually checked with LspInfo
It is very weird that disabling the capability of one server will cause another server to crash... This is more like a client side issue. Could you try to disable vtsls and see if volar will crash?
Another thing I'd like to know is if other features of vtsls works normally for the new vue file after turning off semantic tokens. This could confirm that your "Could not find source file" error is related to semantic tokens request.
This is more like a client side issue. Could you try to disable vtsls and see if volar will crash?
Yes after disabled vtsls
, volar still crash
other features of vtsls works normally for the new vue file
I only use vtsls
as a lsp, at least the it's still sending messages to cmp.
oh I found an issue on vue language server: https://github.com/vuejs/language-tools/issues/4520 for that, which introduced in newest version ( released in this week )
But the vtsls
crash issue I am having for weeks, so I think it's not related, and the semanticTokensProvider
probably is why the server crashes.
Actually if I did not set semanticTokensProvider
to nil both lsp will crash, it's just vtsls
crashed first so I don't get the volar notify message. ( maybe related how nvim or noice.nvim handle the notify messages like I remembered that if print same value mulitiple times I only see one notification)
Sorry for random message, to summarize what am I saying is after set semanticTokensProvider
to nil vtsls
seems to work as expected.
I just pushed a fix https://github.com/yioneko/vtsls/commit/00f766e9bbefb9ee6dfcb7d62ba3befaf0b32b4a to not let the failed semantic token request crash the server. This is a bug inherited from the original vscode typescript extension. Note that it won't be expected to resolve this issue, the culprit for it is still unknown to me.
Thanks!
This is a bug inherited from the original vscode typescript extension.
Yeah i do remember seeing issues that people using vscode having the same issue. ( in vue language server repo )
The reason typescript-language-server
wasn't crashing here is because I've also diverged from vscode and applied similar (but different) fix there https://github.com/typescript-language-server/typescript-language-server/blob/caca0071095557ecc43d8695d922a4cf5e38a2ad/src/ts-client.ts#L484-L486
I've somehow managed to trigger a similar error again, here's the debug log:
[ERROR][2024-07-07 16:58:40] ...lsp/handlers.lua:623 "File file:///path/to/eslint.config.js not found"
[DEBUG][2024-07-07 16:59:31] ...m/lsp/client.lua:676 "LSP[vtsls]" "client.request" 4 "textDocument/documentHighlight" { position = { character = 51, line = 3 }, textDocument = { uri = "file:///path/to/eslint.config.js" }} <function 1> 102
[DEBUG][2024-07-07 16:59:31] .../vim/lsp/rpc.lua:286 "rpc.send" { id = 717, jsonrpc = "2.0", method = "textDocument/documentHighlight", params = { position = { character = 51, line = 3 }, textDocument = { uri = "file:///path/to/eslint.config.js" } }}
[DEBUG][2024-07-07 16:59:31] .../vim/lsp/rpc.lua:408 "rpc.receive" { error = { code = -32603, message = "Request textDocument/documentHighlight failed with message: Cannot find document file:///path/to/eslint.config.js" }, id = 717, jsonrpc = "2.0"}
The file in question exists, is readable, has no weird encoding or anything like that. Not sure if this helps...
The error is from the server itself and not the same. It is triggered when the client requests a feature without notifying the server the document is opened by textDocument/didOpen
notification. Could you see the log recording textDocument/didOpen
notification for the file sent to vtsls before the textDocument/documentHighlight
request? Also note that the textDocument/didOpen
notification should not follow a textDocument/didClose
notification or cancelled by $/cancelRequest
.
Ah, I see. Thanks for the explanation. I'm not seeing a didClose/cancelRequest message because TSServer crashed before that. I'm seeing lots of those errors and then a SIGTERM:
[ERROR][2024-07-06 13:35:24] ...lsp/handlers.lua:623 "An unexpected error occurred:"
[ERROR][2024-07-06 13:35:24] ...lsp/handlers.lua:623 "/path/to/eslint.config.js:3\nimport eslint from '@eslint/js';\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n at wrapSafe (node:internal/modules/cjs/loader:1383:18)\n at Module._compile (node:internal/modules/cjs/loader:1412:20)\n at Module._extensions..js (node:internal/modules/cjs/loader:1551:10)\n at Module.load (node:internal/modules/cjs/loader:1282:32)\n at Module._load (node:internal/modules/cjs/loader:1098:12)\n at TracingChannel.traceSync (node:diagnostics_channel:315:14)\n at wrapModuleLoad (node:internal/modules/cjs/loader:215:24)\n at cjsLoader (node:internal/modules/esm/translators:318:5)\n at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:258:7)\n at ModuleJob.run (node:internal/modules/esm/module_job:262:25)"
--- a lot more of the above ---
[ERROR][2024-07-06 13:40:47] ...lsp/handlers.lua:623 "TSServer exited. Code: null. Signal: SIGTERM"
That error was to be "expected" - my mistake while writing the file in question. I wouldn't expect TSServer to die from that, tho (then again, no idea if that's regular execution or not). Should that be reported upstream or am I just holding it wrong? :D
I'm not seeing a didClose/cancelRequest message because TSServer crashed before that.
Did you see textDocument/didOpen
notification for the eslint.config.js
file before that? If the server has not been notified the opened file, you will see an error message like Cannot find document file:///path/to/eslint.config.js
, and this is expected. There is an issue for that in LSP repo, for now we just require client to send textDocument/didOpen
notification before requesting any language features.
[ERROR][2024-07-06 13:35:24] ...lsp/handlers.lua:623 "An unexpected error occurred:" [ERROR][2024-07-06 13:35:24] ...lsp/handlers.lua:623 "/path/to/eslint.config.js:3\nimport eslint from '@eslint/js';\n^^^^^^\n\nSyntaxError: Cannot use import statement outside a module\n at wrapSafe (node:internal/modules/cjs/loader:1383:18)\n at Module._compile (node:internal/modules/cjs/loader:1412:20)\n at Module._extensions..js (node:internal/modules/cjs/loader:1551:10)\n at Module.load (node:internal/modules/cjs/loader:1282:32)\n at Module._load (node:internal/modules/cjs/loader:1098:12)\n at TracingChannel.traceSync (node:diagnostics_channel:315:14)\n at wrapModuleLoad (node:internal/modules/cjs/loader:215:24)\n at cjsLoader (node:internal/modules/esm/translators:318:5)\n at ModuleWrap.
(node:internal/modules/esm/translators:258:7)\n at ModuleJob.run (node:internal/modules/esm/module_job:262:25)"
I believe these errors are from the eslint server... https://github.com/microsoft/vscode-eslint/blob/edc9685bcda26462dc52decce213167af8d2b25d/server/src/eslint.ts#L1451-L1454, and not related here. Tsserver do not throw error like that.
[ERROR][2024-07-06 13:40:47] ...lsp/handlers.lua:623 "TSServer exited. Code: null. Signal: SIGTERM"
Though the log level for this is ERROR
, it actually indicates that tsserver is requested to shut down by external handle and not crashing itself. Usually you will see that if vtsls stopped when the editor closed or user manually killed it. Another case is that vtsls itself crashed, and the tsserver as a subprocess might be automatically killed. If you could confirm that the problem is vtsls exited accidentally, I could investigate it if related error logs could be provided (the current posted erros are from eslint, not here).
Ok, I've tried diving a little deeper into it since the problem still persists, pretty much on every TS project I use. I still cannot pin-point why it's happening or what exactly triggers it.
I've logged a full close and open cycle of a file that exhibits the error. I'm seeing several textDocument/didClose
notifications but no didOpen
ones when re-opening the file, so my previous message was slightly off. Then the textDocument/documentHighlight
errors start appearing. I can rule out issues with memory definitely.
Here's some more logs:
[DEBUG][2024-07-15 11:18:53] ...m/lsp/client.lua:676 "LSP[vtsls]" "client.request" 5 "textDocument/documentHighlight" { position = { character = 9, line = 55 }, textDocument = { uri = "file:///path/to/file.ts" }} <function 1> 10
[DEBUG][2024-07-15 11:18:53] .../vim/lsp/rpc.lua:286 "rpc.send" { id = 14, jsonrpc = "2.0", method = "textDocument/documentHighlight", params = { position = { character = 9, line = 55 }, textDocument = { uri = "file:///path/to/file.ts" } }}
[DEBUG][2024-07-15 11:18:53] .../vim/lsp/rpc.lua:408 "rpc.receive" { id = 14, jsonrpc = "2.0", result = {}}
[DEBUG][2024-07-15 11:18:53] ...m/lsp/client.lua:676 "LSP[eslint]" "client.request" 8 "textDocument/formatting" { options = { insertSpaces = true, tabSize = 2 }, textDocument = { uri = "file:///path/to/file.ts" }} <function 1> 10
[DEBUG][2024-07-15 11:18:53] .../vim/lsp/rpc.lua:286 "rpc.send" { id = 9, jsonrpc = "2.0", method = "textDocument/formatting", params = { options = { insertSpaces = true, tabSize = 2 }, textDocument = { uri = "file:///path/to/file.ts" } }}
[DEBUG][2024-07-15 11:18:53] .../vim/lsp/rpc.lua:408 "rpc.receive" { id = 9, jsonrpc = "2.0", result = {}}
[DEBUG][2024-07-15 11:18:54] ...m/lsp/client.lua:676 "LSP[stylelint_lsp]" "client.request" 6 "textDocument/willSaveWaitUntil" { reason = 1, textDocument = { uri = "file:///path/to/file.ts" }} <function 1> 10
[DEBUG][2024-07-15 11:18:54] .../vim/lsp/rpc.lua:286 "rpc.send" { id = 2, jsonrpc = "2.0", method = "textDocument/willSaveWaitUntil", params = { reason = 1, textDocument = { uri = "file:///path/to/file.ts" } }}
[DEBUG][2024-07-15 11:18:54] .../vim/lsp/rpc.lua:408 "rpc.receive" { id = 2, jsonrpc = "2.0", result = {}}
[DEBUG][2024-07-15 11:18:54] .../vim/lsp/rpc.lua:286 "rpc.send" { jsonrpc = "2.0", method = "textDocument/didSave", params = { textDocument = { uri = "file:///path/to/file.ts" } }}
[DEBUG][2024-07-15 11:18:54] .../vim/lsp/rpc.lua:286 "rpc.send" { jsonrpc = "2.0", method = "textDocument/didSave", params = { textDocument = { uri = "file:///path/to/file.ts" } }}
[DEBUG][2024-07-15 11:18:54] .../vim/lsp/rpc.lua:408 "rpc.receive" { jsonrpc = "2.0", method = "window/logMessage", params = { message = "(node:47108) [stylelint:002] DeprecationWarning: The CommonJS Node.js API is deprecated.\nSee https://stylelint.io/migration-guide/to-16", type = 1 }}
[DEBUG][2024-07-15 11:18:54] .../vim/lsp/rpc.lua:408 "rpc.receive" { jsonrpc = "2.0", method = "textDocument/publishDiagnostics", params = { diagnostics = {}, uri = "file:///path/to/file.ts" }}
[ERROR][2024-07-15 11:18:54] ...lsp/handlers.lua:623 "(node:47108) [stylelint:002] DeprecationWarning: The CommonJS Node.js API is deprecated.\nSee https://stylelint.io/migration-guide/to-16"
[DEBUG][2024-07-15 11:18:54] ...m/lsp/client.lua:676 "LSP[vtsls]" "client.request" 5 "textDocument/documentHighlight" { position = { character = 9, line = 55 }, textDocument = { uri = "file:///path/to/file.ts" }} <function 1> 10
[DEBUG][2024-07-15 11:18:54] .../vim/lsp/rpc.lua:286 "rpc.send" { id = 15, jsonrpc = "2.0", method = "textDocument/documentHighlight", params = { position = { character = 9, line = 55 }, textDocument = { uri = "file:///path/to/file.ts" } }}
[DEBUG][2024-07-15 11:18:54] .../vim/lsp/rpc.lua:408 "rpc.receive" { id = 15, jsonrpc = "2.0", result = {}}
[DEBUG][2024-07-15 11:18:55] .../vim/lsp/rpc.lua:286 "rpc.send" { jsonrpc = "2.0", method = "textDocument/didClose", params = { textDocument = { uri = "file:///path/to/file.ts" } }}
[DEBUG][2024-07-15 11:18:55] .../vim/lsp/rpc.lua:286 "rpc.send" { jsonrpc = "2.0", method = "textDocument/didClose", params = { textDocument = { uri = "file:///path/to/file.ts" } }}
[DEBUG][2024-07-15 11:18:55] .../vim/lsp/rpc.lua:286 "rpc.send" { jsonrpc = "2.0", method = "textDocument/didClose", params = { textDocument = { uri = "file:///path/to/file.ts" } }}
[DEBUG][2024-07-15 11:18:55] .../vim/lsp/rpc.lua:408 "rpc.receive" { jsonrpc = "2.0", method = "textDocument/publishDiagnostics", params = { diagnostics = {}, uri = "file:///path/to/file.ts" }}
[DEBUG][2024-07-15 11:18:55] .../vim/lsp/rpc.lua:408 "rpc.receive" { id = 3, jsonrpc = "2.0", method = "client/unregisterCapability", params = { unregisterations = { { id = "21c9cf03-8acf-49e5-b47b-d631a7fd763d", method = "textDocument/formatting" } } }}
[DEBUG][2024-07-15 11:18:55] ...m/lsp/client.lua:676 "LSP[vtsls]" "client.request" 5 "textDocument/documentSymbol" { textDocument = { uri = "file:///path/to/file.spec.ts" }} <function 1> 11
[DEBUG][2024-07-15 11:18:55] .../vim/lsp/rpc.lua:286 "rpc.send" { id = 16, jsonrpc = "2.0", method = "textDocument/documentSymbol", params = { textDocument = { uri = "file:///path/to/file.spec.ts" } }}
[DEBUG][2024-07-15 11:18:55] .../vim/lsp/rpc.lua:423 "server_request: callback result" { result = vim.NIL, status = true}
[DEBUG][2024-07-15 11:18:55] .../vim/lsp/rpc.lua:286 "rpc.send" { id = 3, jsonrpc = "2.0", result = vim.NIL}
[DEBUG][2024-07-15 11:18:55] .../vim/lsp/rpc.lua:408 "rpc.receive" { id = 16, jsonrpc = "2.0", result = { ---snip--- }}
[DEBUG][2024-07-15 11:18:55] .../vim/lsp/rpc.lua:408 "rpc.receive" { jsonrpc = "2.0", method = "textDocument/publishDiagnostics", params = { diagnostics = {}, uri = "file:///path/to/file.ts" }}
[DEBUG][2024-07-15 11:18:55] .../vim/lsp/rpc.lua:408 "rpc.receive" { jsonrpc = "2.0", method = "textDocument/publishDiagnostics", params = { diagnostics = { { code = 2345, message = "Argument of type 'MathCollection' is not assignable to parameter of type 'Matrix'.\n Type 'MathNumericType[]' is missing the following properties from type 'Matrix': type, storage, datatype, create, and 13 more.", range = { ["end"] = { character = 60, line = 31 }, start = { character = 52, line = 31 } }, severity = 1, source = "ts" }, { code = 6133, message = "'gradientMap' is declared but its value is never read.", range = { ["end"] = { character = 21, line = 31 }, start = { character = 10, line = 31 } }, severity = 4, source = "ts", tags = { 1 } } }, uri = "file:///path/to/another-file.ts" }}
[DEBUG][2024-07-15 11:18:57] .../vim/lsp/rpc.lua:408 "rpc.receive" { jsonrpc = "2.0", method = "textDocument/publishDiagnostics", params = { diagnostics = { { code = 2345, message = "Argument of type 'MathCollection' is not assignable to parameter of type 'Matrix'.\n Type 'MathNumericType[]' is missing the following properties from type 'Matrix': type, storage, datatype, create, and 13 more.", range = { ["end"] = { character = 60, line = 31 }, start = { character = 52, line = 31 } }, severity = 1, source = "ts" }, { code = 6133, message = "'gradientMap' is declared but its value is never read.", range = { ["end"] = { character = 21, line = 31 }, start = { character = 10, line = 31 } }, severity = 4, source = "ts", tags = { 1 } } }, uri = "file:///path/to/another-file.ts" }}
[DEBUG][2024-07-15 11:18:57] .../vim/lsp/rpc.lua:286 "rpc.send" { jsonrpc = "2.0", method = "textDocument/didClose", params = { textDocument = { uri = "file:///path/to/file.spec.ts" } }}
[DEBUG][2024-07-15 11:18:57] .../vim/lsp/rpc.lua:286 "rpc.send" { jsonrpc = "2.0", method = "textDocument/didClose", params = { textDocument = { uri = "file:///path/to/file.spec.ts" } }}
[DEBUG][2024-07-15 11:18:57] .../vim/lsp/rpc.lua:286 "rpc.send" { jsonrpc = "2.0", method = "textDocument/didClose", params = { textDocument = { uri = "file:///path/to/file.spec.ts" } }}
[DEBUG][2024-07-15 11:18:57] .../vim/lsp/rpc.lua:408 "rpc.receive" { jsonrpc = "2.0", method = "textDocument/publishDiagnostics", params = { diagnostics = {}, uri = "file:///path/to/file.spec.ts" }}
[DEBUG][2024-07-15 11:18:57] .../vim/lsp/rpc.lua:408 "rpc.receive" { jsonrpc = "2.0", method = "textDocument/publishDiagnostics", params = { diagnostics = {}, uri = "file:///path/to/file.spec.ts" }}
[DEBUG][2024-07-15 11:18:57] .../vim/lsp/rpc.lua:408 "rpc.receive" { jsonrpc = "2.0", method = "textDocument/publishDiagnostics", params = { diagnostics = { { code = 2345, message = "Argument of type 'MathCollection' is not assignable to parameter of type 'Matrix'.\n Type 'MathNumericType[]' is missing the following properties from type 'Matrix': type, storage, datatype, create, and 13 more.", range = { ["end"] = { character = 60, line = 31 }, start = { character = 52, line = 31 } }, severity = 1, source = "ts" }, { code = 6133, message = "'gradientMap' is declared but its value is never read.", range = { ["end"] = { character = 21, line = 31 }, start = { character = 10, line = 31 } }, severity = 4, source = "ts", tags = { 1 } } }, uri = "file:///path/to/another-file.ts" }}
[DEBUG][2024-07-15 11:18:59] ...m/lsp/client.lua:676 "LSP[vtsls]" "client.request" 5 "textDocument/documentSymbol" { textDocument = { uri = "file:///path/to/file.ts" }} <function 1> 10
[DEBUG][2024-07-15 11:18:59] .../vim/lsp/rpc.lua:286 "rpc.send" { id = 17, jsonrpc = "2.0", method = "textDocument/documentSymbol", params = { textDocument = { uri = "file:///path/to/file.ts" } }}
[DEBUG][2024-07-15 11:18:59] .../vim/lsp/rpc.lua:408 "rpc.receive" { error = { code = -32603, message = "Request textDocument/documentSymbol failed with message: Cannot find document file:///path/to/file.ts" }, id = 17, jsonrpc = "2.0"}
[DEBUG][2024-07-15 11:18:59] ...m/lsp/client.lua:676 "LSP[vtsls]" "client.request" 5 "textDocument/documentHighlight" { position = { character = 9, line = 55 }, textDocument = { uri = "file:///path/to/file.ts" }} <function 1> 10
[DEBUG][2024-07-15 11:18:59] .../vim/lsp/rpc.lua:286 "rpc.send" { id = 18, jsonrpc = "2.0", method = "textDocument/documentHighlight", params = { position = { character = 9, line = 55 }, textDocument = { uri = "file:///path/to/file.ts" } }}
[DEBUG][2024-07-15 11:18:59] .../vim/lsp/rpc.lua:408 "rpc.receive" { error = { code = -32603, message = "Request textDocument/documentHighlight failed with message: Cannot find document file:///path/to/file.ts" }, id = 18, jsonrpc = "2.0"}
I see. It's really hard to troubleshoot a problem cannot be stability reproduced. But based on the logs we can confirm the triggering reason for the Cannot find document
error is that client fails to send the textDocument/didOpen
notification for re-opened files. That could save us from inspecting what's wrong on the server side.
Strictly speaking, it's not a good behavior that the server throws error on file not opened since that has not been clarified in LSP and the error could trigger very frequently leading to a bad user experience. Therefore I've pushed a change https://github.com/yioneko/vtsls/commit/23f922ee2840d2a42588e77cc2167d4d1916b59a to suppress this type of error in case that client does not behave what the server expects (sending didopen notification before requesting any features).
However, that change doesn't mean to resolve this problem, it's just suppressing the annoying errors. You won't get any language features like completion working on the file not notified to have been opened. The issue should go to the client side but I'm afraid that they won't give a shot on this if no minimal reproduction steps provided.
I've tried to inspect the nvim LSP client code related to this, here are some of my suggestions (hopefully useful):
The next time you encounter this, using these commands to find what's going wrong:
:lua =vim.lsp.get_clients({ name = "vtsls" })[1].attached_buffers[vim.api.nvim_get_current_buf()]
This output whether the file is marked as attached in the client internal state. :lua =vim.lsp.util.buf_versions[vim.api.nvim_get_current_buf()]
This would output a version number if file is successfully tracked by nvim LSP module. If both of them output nil
, this possibly indicates that the client has not tried to attach to the current file. If you are using lspconfig
to setup server, that is what manages the clients. Check :au lspconfig
to see if the autocmds are correctly set and try :doautocmd BufReadPost
(or :set ft=typescript
) to see if it will make the file successfully attached by client.
Otherwise it possibly means a bug in nvim builtin LSP client. That's what things become complicated and I (and nvim core maintainers) could hardly help here if no reproduction steps available. But I could provide a possibly working workaroud (see below).
local function reattch_workaround()
local bufnr = vim.api.nvim_get_current_buf()
vim.schedule(function()
if not vim.api.nvim_buf_is_loaded(bufnr) then
return
end
for _, client in pairs(vim.lsp.get_clients({ name = "vtsls" })) do
vim.lsp.buf_detach_client(bufnr, client.id)
if client.attached_buffers[bufnr] then
-- if triggered, this is a bug in core
client.attached_buffers[bufnr] = nil
end
if not client.initialized then
-- if triggered, this is (possibly) a bug in core
client.initialized = true
end
vim.lsp.buf_attach_client(bufnr, client.id)
-- ensure the didOpen request in sent
client.notify(vim.lsp.protocol.Methods.textDocument_didOpen, {
textDocument = {
version = vim.lsp.util.buf_versions[bufnr],
uri = vim.uri_from_bufnr(bufnr),
languageId = vim.bo[bufnr].filetype,
text = vim.lsp._buf_get_full_text(bufnr),
},
})
end
end)
end
-- hack on vim.notify to trigger the workaround
-- you can also bind it to a key mapping
local notify = vim.notify
vim.notify = function(...)
notify(...)
local msg = select(1, ...)
if string.find(msg, "vtsls.*Cannot find document") == nil then
return
end
reattch_workaround()
end
Thank you, so much @yioneko for the super comprehensive reply.
Check you nvim version. There is a known bug in 0.10 stable version that client might be not able to send didopen notification on some cases, especially when some servers were stopped/restarted before. Try to upgrade nightly to see if that solves your problem.
I've used neovim nightly all day and haven't had the issue come up. I'm inclined to say that the bug you mentioned in 0.10 seems to be fixed in nightly but I'll give it a couple of more hours to see if it starts popping up again. Out of curiosity, do you happen to have a commit over on the neovim repo that fixes it?
Strictly speaking, it's not a good behavior that the server throws error on file not opened since that has not been clarified in LSP and the error could trigger very frequently leading to a bad user experience. Therefore I've pushed a change https://github.com/yioneko/vtsls/commit/23f922ee2840d2a42588e77cc2167d4d1916b59a to suppress this type of error in case that client does not behave what the server expects (sending didopen notification before requesting any features).
That's interesting, I haven't had the time to test that one out but will definitely try should the issue resurface again.
edit: after about a week: nightly completely fixed it I have no issues whatsoever anymore.
Just found this issue https://github.com/microsoft/vscode/issues/214226 not sure if this is related( because it is on vscode ), but the error does seem identical tho.
I think this issue is probably something with the vscode tsserver itself but I am hesitant to open an issue there as the issues I have seen seem specific to debugging "Workspaces" and TS versions in those workspaces and I don't know about any of that in my neovim world.
Since switching to vtsls (upgrading LazyVim) I am seeing errors like the following when opening files:
It does seem odd that it's using tsserver from my project here and not the one bundled with vtsls... but I don't know enough to know if that's a problem.
This is on a Javascript - not typescript - project. I don't remember ever seeing this issue with the old tsserver package lazyvim was using but I believe there may be other new versions of things involved. Apologies if this is not the correct place for this issue but it seemed like maybe the right place to start and hopefully someone more knowledgeable can point me in the right direction.
edit: I found the
select_ts_version
command but still get the error with the global version (5.4.5)