daplf / vscode-java-kotlin

Experimental support for importing Kotlin code into Java projects via a JDT.LS extension
MIT License
23 stars 6 forks source link

Set-Up / Configuration of Extension #14

Open FelixGSE opened 1 year ago

FelixGSE commented 1 year ago

I tried to use your plugin in a mixed Kotlin Java Maven project, without any success. I have a rather stupid question: Do I have to do any further configuration or should it work out of the box? (I have installed fwcd Kotlin extension as well as Microsofts extension pack for Java)

daplf commented 1 year ago

Hey @FelixGSE

It should work out of the box, but it has not been thoroughly tested, especially with bigger projects. Could you maybe elaborate on what doesn't work for you? Is it only the mixed Kotlin Java stuff that fails?

Also, could you maybe share the logs for both extensions? They are in the output tab under "Kotlin" and "Language Support for Java".

Other than that, I suppose you could also share a small project that doesn't work for you and I could try to repro it on my end.

imudak commented 8 months ago

Here is a small sample of importing Kotlin classes from Java. https://github.com/imudak/small-sample-for-vscode-java-kotlin/tree/master/src/main/java/org/example

I have installed the vscode-java-kotlin extension, but I am getting a "cannot be resolved" error, as shown in the image. unresolved

Gradle build and execution are successful.

daplf commented 8 months ago

Hey @imudak

Thanks for the sample! Can you try putting the Common.kt file under src/main/kotlin/org/example? That seems to fix it on my end.

imudak commented 8 months ago

Thank you for your quick reply, @daplf.

I tried moving to the Kotlin directory, but the error still occurred in my environment.

unresolved2

daplf commented 8 months ago

Not sure what the issue could be then since it works on my end 🤔

image

I guess one thing I noticed on your screenshot is that your path to the file starts with kotlin-java and mine starts with src. Perhaps that means you opened the parent directory of your project instead of the project itself? As far as I recall, the kotlin extension has some issues with projects inside sub-directories.

imudak commented 8 months ago

Thank you. It is now working on my end as well.

It seems to be in the following state:

a) Opening the project as a folder → It works b) Opening with a workspace file → It does not work

As you mentioned, it might be that the Kotlin extension is not finding the Kotlin files when in workspace mode.

The following are the logs for each terminal. For the one opened in the workspace, "Update project kotlin-java" is not running.

a) Open folder

a24eae26 Validating Gradle wrapper checksum... [Done]
2276157c Importing Gradle project(s) [Done]
b222897e Synchronizing projects [Done]
99395ee9 Synchronizing projects [Done]
4b83850c Building [Done]
c550dfb6 Validate documents [Done]
fa6d7b72 Background task [Done]
e5bc66b7 Publish Diagnostics [Done]
3b592e2e Validate documents [Done]
1565f22f Publish Diagnostics [Done]
ae56f2a6 Update project kotlin-java [Done]
93e11b45 Building [Done]
c98f8769 Building [Done]
25d558c1 Register Watchers [Done]
f17e5fab Building [Done]

b) Open workspace:

8c99d1d1 Build Server Task [Done]
d07e3c66 Initialize Workspace [Done]
db18e046 Synchronizing projects [Done]
28c36988 Synchronizing projects [Done]
64cbd969 Validate documents [Done]
d430ed29 Publish Diagnostics [Done]
760ae74e Background task [Done]
7adf125c Validate documents [Done]
3259abbf Building [Done]
9517a9f0 Build Server Task [Done]
822c922f Publish Diagnostics [Done]
fdd42fe1 Building [Done]
enzobonggio commented 6 months ago

Hi! I tried the example provided but it seems that when I try to follow the code of Common.version it redirects me to the .class file instead of the .kt file. Is that expected? Also, I was not able to do the other way around from the kt file look who is using the variable version

I want to bring my iPad instead of my computer to my vacations and if this is working I would be able to D:

daplf commented 6 months ago

Hey @enzobonggio

Hi! I tried the example provided but it seems that when I try to follow the code of Common.version it redirects me to the .class file instead of the .kt file. Is that expected?

This is expected, yes. There is a separate issue tracking this: https://github.com/daplf/vscode-java-kotlin/issues/3

Also, I was not able to do the other way around from the kt file look who is using the variable version

Do you mean finding the uses of a Kotlin variable? Regardless of whether or not those uses are in Kotlin or Java, I believe this should be handled by the Kotlin Language Server, since KLS is aware of the Java sources (and since KLS "owns" the variable it should be able to find them). If this doesn't work, it's most likely an issue in KLS and not on this extension. It might not actually be supported at all yet in KLS (I know those features don't cover every case yet).

If you mean the other way around (i.e., finding the uses of a Java variable), it's a similar issue to the one for definitions. We would need to find a way to let the Java Language Server know about our Kotlin sources.

AndrewMcLeodHT commented 3 months ago

Hello! I'm trying to get this working and running into the same issue. Are you still interested in working on this? I can't use Intellij for several reasons 😢.

daplf commented 3 months ago

Hello! I'm trying to get this working and running into the same issue. Are you still interested in working on this? I can't use Intellij for several reasons 😢.

Which issue are you facing? There are a few things reported in this thread, so perhaps you can clarify.

I am not really pursuing this project at the moment because there's not that much interest in it (or in the Kotlin Language Server itself, for that matter).

AndrewMcLeodHT commented 3 months ago

Thank you so much for responding! Sorry for the delay, it is a busy time at work. The issue I was having was the first reported problem of the extension not working out of the box. I attempted the suggested workaround to open as a folder and not as a workspace and it worked this time!

Now whenever I open a file the errors are reappearing in the problems window. So sadly, it shows any namespaces from the kotlin directory in the currently opened file not being resolved. It is quite strange. Do you have any ideas? I can give you more details tomorrow after work. Really appreciate your work on this!!