Skip to content

Autoimport code action does not work #390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
malteehrlen opened this issue Sep 8, 2022 · 4 comments
Closed

Autoimport code action does not work #390

malteehrlen opened this issue Sep 8, 2022 · 4 comments

Comments

@malteehrlen
Copy link

malteehrlen commented Sep 8, 2022

Released in 1.3.1 was a much awaited (by me) code action for autoimporting new deps (see #343). However it does not work as expected:

Expected:

  • Unresolved reference should have a CA to import that reference

Actual:

  • Unresolved reference has no code actions available

Code to reproduce:

package example

fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)

Fetching code actions on io returns nothing.

LSP version: 1.3.1

Thanks for working on this project!

ping @themkat

@malteehrlen
Copy link
Author

I guess I was mistaken how this code action would work. It does work for local imports

@themkat
Copy link
Collaborator

themkat commented Sep 8, 2022

@malteehrlen , it does work for global imports as well. In your case you have used a fully qualified name (io.ktor.server.netty.EngineMain), so there is nothing to import really. io is the start of a package name, and there will be no code action on that one. If EngineMain was by itself, then one should expect the code action to show a missing import.... given that the Symbol Index contains the entry. Because io gives an unresolved reference in your case, my main guess is that the Symbol Index does not contain any entries in that package. There can be several reasons for this:

  1. Has the language server finished indexing? It may take some time before the indexing is done, and I've sadly heard some people experience quite slow times here. Usually fast on my machines, especially on my M1 Macbook Air.
  2. Is it a Kotlin Multi Platform project? If so, then the experimental support was probably merged after the the release of the version you are using: Experimental resolution of dependencies in Kotlin multiplatform projects (Gradle) #377
  3. Some other issue that we may find by reading the server logs (gradle/maven failures etc.)

Wrote this also in case someone googles this issue and end up here 🙂

Happy to hear that you looked forward to that release 😄 Feel free to suggest any wishes for code actions, different ways they should work etc. that you might have.

@weilbith
Copy link

Should I also see an action for annotations?

@themkat
Copy link
Collaborator

themkat commented Oct 28, 2022

@weilbith , yes you should. Given that the symbol you are trying to import is in your symbol index. Make sure that there are no issues during the initialisation of the language server (there have been several issues relating to Gradle mostly as it uses a custom task). Also make sure that it is done loading, as the server won't do much if that is not the case.

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

No branches or pull requests

3 participants