eclipse-jdtls / eclipse.jdt.ls

Java language server
1.81k stars 403 forks source link

typeDefinition returns null instead of an empty list #3112

Open Bnaya opened 8 months ago

Bnaya commented 8 months ago

Hey

See https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/NavigateToTypeDefinitionHandler.java#L58

return location == null ? null : Arrays.asList(location);

Other handles returns Collections.emptyList(), but NavigateToTypeDefinitionHandler retures null

When using vscode-jsonrpc on the client side, you will see these errors: The received response has neither a result nor an error property.

rgrunber commented 8 months ago

What any given handle returns depends on the protocol. If the protocol allows it, then it should be expected. According to https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_typeDefinition :

Response:

result: Location | Location[] | LocationLink[] | null partial result: Location[] | LocationLink[] error: code and message set in case an exception happens during the definition request.

Seems similar to https://github.com/microsoft/vscode-languageserver-node/issues/311#issuecomment-368024069 except in that case it was determined the response was not correct. Maybe it's a bug in the vscode-jsonrpc library unless there's something I'm missing here.

Bnaya commented 8 months ago

I've done some more debugging, and the LS is not sending result: null, but not sending the result prop at all, Which is against the spec

rgrunber commented 8 months ago

What client are you using to run the language server ? There should be a folder created by jdt-ls either in the system's temporary directory or somewhere else (depending on how you run the actual language server). It should contain a file at some path like .metadata/.log. That might contain more information on why there is no response.

Note that prior to calling something like typeDefinition, you need to have called initialize on the project & probably didOpen on a particular document.