Closed jebej closed 3 years ago
This is on Windows with julia 1.6.1, and up to date packages: LS.jl @ 4.0.0, SymbolServer.jl @7.0.0 & JSONRPC @ 1.3.3.
When using "Goto Definition..." Sublime Text shows a list with the files for the returned definition locations and immediately displays a preview of the selected file (i.e. the first item in the quick panel list), and then asks for possible code actions at that position via textDocument/codeAction
. While this request for code actions probably makes not much sense here for files in Julia's "base" or "stdlib", I don't see any mention in the LSP specs that the URI for textDocument/codeAction
would be restricted to the workspace.
But on the other hand, these file previews for a selected file in the quick panel are very volatile and these files are not really opened until the user confirms the selected item with Enter, and only after that happened, the textDocument/didOpen
notification is sent from Sublime Text. So this error from the server is thrown because the file URI for such file previews are not yet registered in the server.
I'm not sure if this is a bug in the server (i.e. it should not error if a file URI is outside of the workspace), or in the Sublime Text client (i.e. textDocument/codeAction
should not be requested for file previews, and instead only after the file was really opened). Perhaps @rwols has an opinion whether this should be handled by the server, of fixed in Sublime's LSP?
Regardlessly, the following would be a possible fix here in LanguageServer.jl, which would prevent a crash for file URIs outside of the workspace (such a check would probably be useful for other requests too then):
diff --git a/src/languageserverinstance.jl b/src/languageserverinstance.jl
index 7cb1525..3a89cfe 100644
--- a/src/languageserverinstance.jl
+++ b/src/languageserverinstance.jl
@@ -106,7 +106,7 @@ function hasdocument(server::LanguageServerInstance, uri::URI2)
end
function getdocument(server::LanguageServerInstance, uri::URI2)
- return server._documents[uri]
+ return get(server._documents, uri, nothing)
end
function getdocuments_key(server::LanguageServerInstance)
diff --git a/src/requests/actions.jl b/src/requests/actions.jl
index 02c10cc..45383ec 100644
--- a/src/requests/actions.jl
+++ b/src/requests/actions.jl
@@ -7,6 +7,7 @@ end
function textDocument_codeAction_request(params::CodeActionParams, server::LanguageServerInstance, conn)
commands = Command[]
doc = getdocument(server, URI2(params.textDocument.uri))
+ !isnothing(doc) || return nothing
offset = get_offset(doc, params.range.start) # Should usef get_offset2?
x = get_expr(getcst(doc), offset)
arguments = Any[params.textDocument.uri, offset] # use the same arguments for all commands
Hm, I'm pretty sure VSCode sends textDocument/didOpen
even for previews, which would explain the differing behaviour. I wouldn't mind adding these checks to the server, but basically all of our code assumes that only URIs of didOpen
ed text documents are ever used in requests, I think.
This was a bug in the ST client and is now fixed.
Yep, it works now, thanks!
Error trying to find definitions for a base function in Sumblime with the Sublime LSP client. The various definition locations are returned and displayed properly, but the LSP crashes right after (I assume) trying to ask for more details.