kotlin-language-server icon indicating copy to clipboard operation
kotlin-language-server copied to clipboard

Possible bug in workspace/symbol request result

Open pajatopmr opened this issue 3 years ago • 2 comments

Given a top level function:

fun hello() = println("Hello from Kotliin")

KLS correctly returns the symbol "hello" however it does not return the symbol "println". IMHO this is a bug but in fairness the LSP spec is extremely vague about what is and is not a symbol. Given that vagueness, my hope is that server developers will choose to provide as many "symbols" as the underlying compiler technology provides. Assuming my take is of value, I will proceed to generate a KLS PR to address this issue. Comments and advice toward a successful PR are wanted and welcome.

An initial observation is that a workspace/symbol request result returns only declarations. Since "println" is a function call from the standard library there is no easily definable declaration for it but (at least with IntelliJ) there is information to be had about the symbol from the compiler. Perhaps a declaration can be synthesized from that information.

pajatopmr avatar Jan 14 '21 16:01 pajatopmr

I was under the impression that workspace/symbols (and LSP symbols in general) refer to definitions only, so that e.g. looking up a symbol by name using the client yields a unique location per symbol.

While I could see how textDocument/documentSymbol might provide the complete AST, since this is what clients usually display as 'Outline', including every function call could make the list very long and potentially hard to navigate.

fwcd avatar Jan 15 '21 11:01 fwcd

Yes, a complete AST dump would lead to an explosion which would be good to avoid. My thinking is to walk a block and look for function call references and ensure that associated call declarations make it into the workspace/symbol result. I believe this can be done reasonably efficiently for Kotlin. If you would be willing to answer questions I might have while developing this solution please send a message to me ([email protected]) or let me know if posting questions here is preferable. For example, given a call reference node (PsiElement) how can I obtain the associated declaration node? Being able to do this would significantly reduce the extra workspace/symbol output.

pajatopmr avatar Jan 15 '21 14:01 pajatopmr