kotlin-language-server
kotlin-language-server copied to clipboard
"Unresolved reference" for generated Java source files
I'm getting an "unresolved reference" (kotlin(UNRESOLVED_REFERENCE)
) error for all symbols imported from Java files generated in the target directory.
Any idea what could be the problem, and/or how to debug it?
Does your project use a build tool?
Does your project use a build tool?
Yes, Maven (with openapi-generator-maven-plugin and jooq-codegen-maven for code generation).
Support for Java projects in KLS is still somewhat limited, I am afraid. Could you share a minimal working example of a Maven/Java project where the issue occurs?
I will try to come up with something, thanks!
I made a minimal working example at https://github.com/fo-fo/vscode-kotlin-problem. It's a simple app that opens a web server that serves a hello world text at http://localhost:8080/api/example/foo
I noticed a couple of things about how it seems to be working. src/main/kotlin/com/example/apipublic/v1/FooApiController.kt
is the file of interest here.
- From a fresh clone, after opening VSCode, the references to generated code do not work, obviously, because the code generation hasn't been run yet.
- While keeping VSCode open, and after running
mvn spring-boot:run
and re-opening theFooApiController.kt
file, the references actually do work. - However, if I close VSCode entirely and re-open the directory, the references do not work.
- If (while keeping VSCode open) I again remove the
target
directory and runmvn spring-boot:run
, the references work (after re-opening theFooApiController.kt
file).
So, it seems that unless the generated files appear in the target
directory while VSCode is running, the Kotlin compiler doesn't take note of them.
I also have this problem with gradle when generating flatbuffer java files. Do you need a minimal working for that as well?