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

"Unresolved reference" for generated Java source files

Open fo-fo opened this issue 3 years ago • 6 comments

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?

fo-fo avatar Feb 04 '21 16:02 fo-fo

Does your project use a build tool?

fwcd avatar Feb 05 '21 05:02 fwcd

Does your project use a build tool?

Yes, Maven (with openapi-generator-maven-plugin and jooq-codegen-maven for code generation).

fo-fo avatar Feb 05 '21 07:02 fo-fo

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?

fwcd avatar Feb 05 '21 13:02 fwcd

I will try to come up with something, thanks!

fo-fo avatar Feb 05 '21 14:02 fo-fo

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 the FooApiController.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 run mvn spring-boot:run, the references work (after re-opening the FooApiController.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.

fo-fo avatar Feb 06 '21 13:02 fo-fo

I also have this problem with gradle when generating flatbuffer java files. Do you need a minimal working for that as well?

casret avatar Mar 06 '21 02:03 casret