-
Notifications
You must be signed in to change notification settings - Fork 467
kotlin imports into Java file are unresolved #531
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
Comments
While I can appreciate the problem, Kotlin support is kinda out of scope of our Java support at the moment. We'll need to assess if/how we can help improve the situation. It might come from a companion extension eventually. |
Currently developing a language server and an extension for Kotlin, I have thought about this. In a mixed Kotlin-Java Gradle project both languages do recognize dependencies properly. They fail when trying to use classes from the other language though. An approach to this problem might be to add compiled JVM classes located in the other languages build directory to the classpath. |
Any updates on this? |
@fwcd do you have any suggestions on how to implement this either here or in the kotlin language server? you mentioned copying the classfiles around but I'm not sure how to do that manually, let alone code it up. |
@coffeepac Implementing that in KotlinLanguageServer first might be easier, because the KLS repo has a smaller codebase and is pretty easy to setup. Copying any classfiles might not even be necessary, the language server would just have to know where they are located. The Java language server uses the Eclipse project model whilst the Kotlin language server entirely relies on Gradle/Maven, thus placing the classfiles in different locations each. When scanning the classpath from the Kotlin language server, it would have to search through the directory that the Java language server/the Eclipse project model places the compiled files in. |
Can't wait for using kotlin in VSCode. When can we use kotlin in VSCode? |
Any updates or news? |
This also seems like the last piece for me as well to make VS Code viable for development. I am unable to run Java Junit classes that reference a Kotlin class as it is not able to find the class. |
Yes this is pretty hard since most projects nowadays mix kotlin packages in the import... |
Hey, just in case anyone might have missed it, I built a prototype companion extension that attempts to solve this issue: https://github.com/fwcd/vscode-java-kotlin |
Any updates on this issue? |
Any updates on this? |
I follow the others here: are there any updates? |
Any updates? It's frustrating to have to use IntelliJ for some projects. |
Hey everyone. I finally published the companion extension I linked above to make this work: https://marketplace.visualstudio.com/items?itemName=daplf.vscode-java-kotlin Keep in mind that this is only a prototype for now and I haven't used it with very large projects, but it seems to work well for small ones at least. If you have any problems with the extension, please create an issue. I'm happy to improve it :) |
Any updates here? Will this feature come at some point? |
info update |
this is necessary, as we mix kotlin and java |
Every big project (including mine) that is going to move from Java to Kotlin will do so incrementally rather than as a total rewrite so the need for having Kotlin recognized in in the VSCode IDE is a pretty big deal breaker, and will stop people from adopting Kotlin. |
Agreed, but I suggest telling that to Jetbrains. |
Jetbrains benefits HUGELY from leaving this flaw unfixed, because it's literally the only thing stopping Kotlin & Java from being mixed in VSCode projects, and forces people to stay on IntelliJ. |
@fbricon @fwcd this issue prevents Would you be open to sponsorship or know of a trusted contributor we could sponsor to move this forward? (email in profile) |
I don't really have the capacity to maintain the language server more actively these days, but feel free to ask some of the other contributors. @daplf wrote an extension for this a while ago: https://github.com/daplf/vscode-java-kotlin Would love to see better Kotlin/Java interop in VSCode too. |
@fwcd do you know if this issue is the same or different from importing a Kotlin library into Java? Versus importing a Kotlin file in the same project into Java? I ask because it sounds like in the latter case the import is completely unresolved while in the former case the import is resolved, but you don't get docs-on-hover or jump-to-definition. |
Thanks @fwcd ! Do you have a sense of whether that extension could feasibly be merged into this one? Ideally Java users would not have to install a Kotlin-related extension just to use a library that happens to be built with Kotlin. |
@TomerAberbach It's been a while since I've dug into the classpath logic so I'm probably not the right person to ask 😄 That said, I remember it being a bit fiddly, since it very much depends on how your project is built and structured. The idea was definitely to support mixed Java/Kotlin codebases, not sure how far we got with that. |
@rattrayalex @TomerAberbach Hey 👋 Your use case is one I hadn't really considered and it's not really what my extension was made for. However, the issue is fairly similar. In a nutshell, my extension allows Kotlin source files used in mixed Java/Kotlin codebases to be added to the project classpath, so that the Java Language Server doesn't complaint about missing symbols (defined in Kotlin). However, my extension merely adds the compiled bytecode to the project classpath in JDT LS. This means we have the same problem. Any additional language support, such as The solution to this will likely be something along these lines: eclipse-jdtls/eclipse.jdt.ls#2583 (comment) So there needs to be a companion extension that advertises Java language support and is thus able to provide hovers and definitions for Kotlin symbols used in Java source files. This extension would likely need to connect to some other language server that is capable of rendering docs for the Kotlin symbols and provide definition results. Since the actual project is managed by JDT LS, this separate language server would potentially need to make requests to JDT LS (via the I don't have a lot of experience with JDT LS and their extensions apart from the one I built, so I'm not entirely sure this would actually work, but it seems to me like this is how some similar use cases are currently being done (e.g., Regarding upstreaming any of this to |
Thanks for the note @daplf !
I am curious whether maintainers share this view. Should a Java developer installing a package like |
In a project, there are some interfaces set up in Kotlin, also config files, that are imported into the main Java file. These aren't recognized as valid imports, support for this would be useful. Attempting to move out of IntelliJ to VS Code, this is the only problem with the project.
The text was updated successfully, but these errors were encountered: