fwcd / kotlin-language-server

Kotlin code completion, diagnostics and more for any editor/IDE using the Language Server Protocol
MIT License
1.68k stars 212 forks source link

Feature - disable extension on per-file basis to mitigate `Unresolved reference:` errors #567

Open spaceunifyfifty opened 8 months ago

spaceunifyfifty commented 8 months ago

From my research it looks that the extension still does not support code from third party dependencies like JUnit or KMP. Examples #487, #101 The code successfully compiles and executes, but I have VSCode visually alerting me with red errors everywhere. I want to tell the extension to ignore certain files or sets of files where libraries are imported and used. I can tolerate not having autocompletion and hints in a few minority sections of my codebase while getting to benefit from the extension in the vanilla kotlin majority of cases. But currently it looks like my only options are to totally remove your extension and have no ide support for the language or use your extension but be limited from using any libraries if I don't want red squiggles everywhere.

fwcd commented 8 months ago

From my research it looks that the extension still does not support code from third party dependencies like JUnit or KMP.

It should support that, but only if your project follows a standard Maven/Gradle layout. If it does not, you could create a kls-classpath script to tell it where to find the corresponding JARs.

But currently it looks like my only options are to totally remove your extension and have no ide support for the language or use your extension but be limited from using any libraries if I don't want red squiggles everywhere.

If you "just" want to disable errors (and still get code completion etc.), you can also set "kotlin.diagnostics.enabled": false, but that will disable them everywhere. This is a more of a feature of last resort to make the language support somewhat usable even if the language server cannot resolve all dependencies correctly.

Ignoring specific files is still to be implemented, it has come up every now and then (see e.g. the discussion in https://github.com/fwcd/kotlin-language-server/pull/560).

spaceunifyfifty commented 7 months ago

I looked at the classpath example, and I'm not really sure what it would look like for example, a project that uses the ktor library? Where is that located?

josephquesnel commented 1 month ago

I just finally fixed my issue with the language server and it turned out the problem was resolved when i uninstalled java 23 and all my old unused jdk versions, installed 21 and 17. I had some bad path env and bad registry files because i was impatient. Once cleaned (read the logs to know what), it just worked with jvm21.

I also killed all java processes with the working reload.

I was using latest kotlin 2.0.21 and ktor 3.0.0 and latest java 23 with Gradle and just could not get auto completion for files beyond the main directory including all external libraries. Gradle was getting an error when syncing the config due to jvm 23 having an unsupported operation. I am sure i can redownload java 23 without worrying but not bothering till i really need it.

I used ktor to create the base package not gradle build init. Hope this helps someone. I was pulling hair for a day before figuring it out. It did not help that im new to java ecosystem.