vscode-kotlin icon indicating copy to clipboard operation
vscode-kotlin copied to clipboard

Unresolved reference

Open BEN425 opened this issue 2 years ago • 13 comments

Description

Everything is marked with red underline. The error message says "Unresolved reference: xxx" 螢幕擷取畫面 2022-02-12 211605 螢幕擷取畫面 2022-02-12 211618

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. 螢幕擷取畫面 2022-02-12 212323

BEN425 avatar Feb 12 '22 13:02 BEN425

Make sure you're opening entire folder (File -> Open Folder) and not only the file itself

TricolorHen061 avatar Feb 12 '22 21:02 TricolorHen061

I do open the entire folder.

BEN425 avatar Feb 13 '22 02:02 BEN425

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.

GrabCAD-Gary avatar Feb 15 '22 16:02 GrabCAD-Gary

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.

eiswind avatar Feb 23 '22 13:02 eiswind

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)

fwcd avatar Mar 29 '22 17:03 fwcd

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?

LeCyberDucky avatar Dec 17 '22 18:12 LeCyberDucky

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

xhoneybear avatar Mar 03 '23 21:03 xhoneybear

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

themkat avatar Mar 03 '23 21:03 themkat

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 avatar Mar 03 '23 22:03 xhoneybear

@xhoneybear Can you share the manually built extension (from main) even if it isn't an official update from fwcd?

rohitcolaco avatar Apr 06 '23 17:04 rohitcolaco

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 😊

xhoneybear avatar Apr 06 '23 19:04 xhoneybear

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 avatar May 06 '24 11:05 BuZZ-dEE

@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.

Skyggedans avatar May 09 '24 12:05 Skyggedans