fwcd / kotlin-language-server

Kotlin code completion, diagnostics and more for any editor/IDE using the Language Server Protocol
MIT License
1.61k stars 203 forks source link

'Go to Definition' doesn't work for symbols from jars or java files #263

Closed linguiqi closed 3 years ago

linguiqi commented 3 years ago

I use this in vscode and open an Android project. For the 'Go to Definition' option, it works for the symbols in kotlin source code. However, it does not work for the symbols in jars or java files. For example, when I want to go to the definition of the class 'Application', it shows ‘No definition found for “Application” ’. Does this language server support 'Go to Definition' Completely?

fwcd commented 3 years ago

The language server should support go-to-definition for classes from jars, this seems to be a regression.

pajatopmr commented 3 years ago

Should a language server also support go-to-definition for functions from jars as well?

fwcd commented 3 years ago

This one does have a mechanism, where it returns special kls://...-URIs for classes in jars, which, through a non-standard-request, can be decompiled on the server-side and then displayed by the client (which is analogous to the Java language server's jdt://...-URIs).

Not quite sure why it doesn't work anymore though.

medwards commented 3 years ago

I'm using kls /w coc-nvim and see similar behaviour (can't look up some Spring Framework definitions). What can I provide to help debug this?

medwards commented 3 years ago

:CocCommand workspace.showOutput after setting trace.server to verbose shows:

[Trace - 3:11:21 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "async1    Go-to-definition at .../domain/KubernetesFetcher.kt 30:35"
}

[Info  - 3:11:21 PM] async1    Go-to-definition at .../domain/KubernetesFetcher.kt 30:35
[Trace - 3:11:21 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "async2    Updating symbol index..."
}

[Info  - 3:11:21 PM] async2    Updating symbol index...
[Trace - 3:11:21 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///home/medwards/forks/pex-router/src/main/java/com/signavio/pex/router/domain/KubernetesFetcher.kt",
    "diagnostics": []
}

[Trace - 3:11:21 PM] Received request 'window/workDoneProgress/create - (1)'.
Params: {
    "token": "bd375418-22af-4e27-a472-27b333ffc107"
}

[Trace - 3:11:21 PM] Sending response 'window/workDoneProgress/create - (1)'. Processing request took 1ms 
No result returned.

[Trace - 3:11:21 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "debounce0 No diagnostics in file:///home/medwards/forks/pex-router/src/main/java/com/signavio/pex/router/domain/KubernetesFetcher.kt"
}

[Info  - 3:11:21 PM] debounce0 No diagnostics in file:///home/medwards/forks/pex-router/src/main/java/com/signavio/pex/router/domain/KubernetesFetcher.kt
[Trace - 3:11:21 PM] Received notification '$/progress'.
Params: {
    "token": "bd375418-22af-4e27-a472-27b333ffc107",
    "value": {
        "kind": "begin",
        "title": "Kotlin: Indexing",
        "percentage": 0
    }   
}

[Trace - 3:11:22 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "async1    Re-parsing KubernetesFetcher.kt 29:5-30:57"
}

[Info  - 3:11:22 PM] async1    Re-parsing KubernetesFetcher.kt 29:5-30:57
[Trace - 3:11:22 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "async1    Hovering REFERENCE_EXPRESSION"
}

[Info  - 3:11:22 PM] async1    Hovering REFERENCE_EXPRESSION
[Trace - 3:11:22 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "async1    Found declaration descriptor @java.lang.FunctionalInterface public fun ApplicationEventPublisher(function: ((kotlin.Any..kotlin.Any?)) -> kotlin.Unit): org.springframework.context.ApplicationEventPublisher defined in org.springframework.context[SamConstructorDescriptorImpl@731b346c]"
}

[Info  - 3:11:22 PM] async1    Found declaration descriptor @java.lang.FunctionalInterface public fun ApplicationEventPublisher(function: ((kotlin.Any..kotlin.Any?)) -> kotlin.Unit): org.springframework.context.ApplicationEventPublisher defined in org.springframework.context[SamConstructorDescriptorImpl@731b346c]
[Trace - 3:11:22 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "async1    Couldn't find definition at .../domain/KubernetesFetcher.kt 30:35"
}

[Info  - 3:11:22 PM] async1    Couldn't find definition at .../domain/KubernetesFetcher.kt 30:35
[Trace - 3:11:22 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "async1    Finished in 1199 ms"
}

[Info  - 3:11:22 PM] async1    Finished in 1199 ms
[Trace - 3:11:22 PM] Received response 'textDocument/definition - (1)' in 1207ms.
Result: []

[Trace - 3:11:40 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "client    Updated symbol index in 19020 ms! (38459 symbol(s))"
}

[Info  - 3:11:40 PM] client    Updated symbol index in 19020 ms! (38459 symbol(s))
[Trace - 3:11:40 PM] Received notification '$/progress'.
Params: {
    "token": "bd375418-22af-4e27-a472-27b333ffc107",
    "value": {
        "kind": "end"
    }
}
medwards commented 3 years ago

Added some more logs, when this occurs:

Neither GoToDefinition.kt or Position.kt have been touched since 2019 so I'm not sure when this worked before.

medwards commented 3 years ago

Is #117 related? Seems not, looks like the related code has been uncommented and evolved since then.

daplf commented 3 years ago

It seems this is the commit that broke it. The previous commit works fine.

medwards commented 3 years ago

I tried doing some naive changes with no luck:

Neither change seems to change the bug behaviour. There might be a subtle difference in CompilerMessageSourceLocation vs CompilerMessageLocation but I'm just guessing.

daplf commented 3 years ago

I tried similar things to no avail. However, I just tried using earlier kotlin versions. It seems the problem started with version 1.3.70. With version 1.3.61 it still works. Don't know which dependency broke it though, but maybe we can find the build that broke it.

daplf commented 3 years ago

I think I fixed it. Opened a PR: https://github.com/fwcd/kotlin-language-server/pull/291

Works on my machine 🤷