vscode-kotlin
vscode-kotlin copied to clipboard
Unresolved reference
Description
Everything is marked with red underline.
The error message says "Unresolved reference: xxx"
Extension version
0.2.23
Additional context
Kotlin version: 1.6.10
JRE version: 1.8.0
OS: Windows 11 64-bit
The code can be compiled and executed without any problem.
Make sure you're opening entire folder (File -> Open Folder) and not only the file itself
I do open the entire folder.
This has been the case for as long I've been using this extension, around 6 mths, and it renders it effectively useless. Please do fix it urgently. In the meantime, the other extension by mathiasfrohlich
doesn't have this issue, although it has fewer features. Since we're working with a DSL which won't run in VSCode anyway, that isn't a problem for us.
Unfortunately I have the same issues when running in gitpod vscode browser. Even when I open the folder manually it still has tons of unresolved references.
Are you in a Maven or Gradle project? If not, the language server might have trouble finding your standard library. The extension by mathiasfrohlich
doesn't have this issue since it doesn't include a language server (for linting, code completion etc) at all. If you just wish to have syntax highlighting without linting etc, you can do that with this extension as well by adding
"kotlin.languageServer.enabled": false
to your VSCode settings. (I've filed #90 to improve the onboarding UI here)
Are you in a Maven or Gradle project? If not, the language server might have trouble finding your standard library.
Is there any way to tell the language server where to find the standard library, without being in a Maven or Gradle project?
Still there. The issue persists no matter if the project is opened standalone, from within a Gradle project or from a directory above. Tried multiple things apart from that like changing default JDK version, setting its path manually, redeploying a Gradle project using multiple different configurations, installing kotlin
package and more. KLS still spits out incorrect nulls despite project building and running fine via Code Runner.
Gradle ver. 8.0.1, Kotlin ver. 1.8.10, tried with OpenJDK 11, 17 and 19
If you are using just the version installed in the extension, and not tweaked it to use the latest kotlin-language-server, the errors will persist. This is because the issues are fixed in the main branch there, but not released. The release process is slow when it depend on only one person doing it, so there is currently work being done to automate it more. More details in the language server issue tracker: https://github.com/fwcd/kotlin-language-server/issues/413
Thank you! Works well indeed after building KSL from main and replacing it in plugin directory (~/.config/Code - OSS/User/globalStorage/fwcd.kotlin/langServerInstall
). Could as well point to new directory through settings, I assume ~ For now it should definitely be instructed somehow, leaving it there for others to follow. 💮
@xhoneybear Can you share the manually built extension (from main) even if it isn't an official update from fwcd?
Done! I forked the project and uploaded a build including the very last commit from 11h ago. Just to be clear though - building from source is incredibly simple and you just need to have Java 11+ and Gradle installed, clone KSL and run gradlew according to the instructions in BUILDING.MD 😊
git clone https://github.com/fwcd/kotlin-language-server
cd kotlin-language-server
./gradlew :server:installDist
cd ~/.config/Code\ -\ OSS/User/globalStorage/fwcd.kotlin/langServerInstall/
mv server/ server-backup
ln -s ~/kotlin-language-server/server/build/install/server ./server
Now it works for me.
@BuZZ-dEE That didn't help. The KLS keeps reporting a crash in org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:78)
while opening a Spring Boot Kotlin project.
Interesting fact, after reading a SO thread and removing a conflicting extension from Mathias Frohlich, it worked for a moment even with stock KLS, and I was able even to run the app and debug the main function, but only until I reloaded a window.