Skip to content

Conversation

gAbelli
Copy link
Contributor

@gAbelli gAbelli commented May 20, 2025

This should allow us to find implementations of classes/interfaces, methods and variables. I tested it in this example

interface I {
    fun f()
    fun f(y: Int)
    fun <T> f(y: T)
    val x: Int
}

class A : I {
    override fun f() = println("f")
    override fun f(y: Int) = println(y)
    override fun <T> f(y: T) = println(y)
    override val x: Int = 0

    fun g(i: I) {
        i.f()
        i.f(1)
        i.f(1.0)
        i.x
    }
}

and it correctly jumps to the right implementation in all cases.

Some limitations I found:

  • It does not find anonymous objects like analysisSessionNotifier in KotlinLanguageServer. But I'm assuming this is a problem with DirectInheritorsProvider right?
  • It does not find implementations defined in libraries. I saw that you were working on decompiling library files so maybe you know how to get that to work?

I'm not sure if module and scope are defined properly, let me know if I should change that.

@amgdev9
Copy link
Owner

amgdev9 commented May 20, 2025

It does not find anonymous objects like analysisSessionNotifier in KotlinLanguageServer. But I'm assuming this is a problem with DirectInheritorsProvider right?

I'm not sure about this case, I'll test that one on standalone platform and see if it happens there, as our KotlinDirectInheritorsProvider is 90% the standalone code. EDIT: Tested and does not work there either, with a local class, a local object or a top level object this service does not detect it

It does not find implementations defined in libraries. I saw that you were working on decompiling library files so maybe you know how to get that to work?

Yeah that's expected, the DirectInheritorsProvider is meant to work only for source files, not libraries as the analysis api requires based on how it's configured right now in KotlinPlatformSettings service.

To implement this feature we can use the background index instead, we can collect for each KtDeclaration in the codebase the inheritance chain (using analyze we can know that) and store it in the index (in a query friendly way, we want to avoid a linear search here), so in the textDocument/implementation handler we just need to search in the index

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants