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

Support Windows Kotlin installed via Scoop #445

Open tats-u opened 1 year ago

tats-u commented 1 year ago

Kotlin installed via scoop install kotlin in Windows has a directory structure not assumed by this language server.

PS> (gcm kotlin).path
C:\Users\tatsu\scoop\shims\kotlin.cmd
PS> ls (split-path -parent (Split-Path -Parent ((gcm kotlin).path)))

    Directory: C:\Users\tatsu\scoop

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          2023/04/01    23:37                apps
d----          2019/11/10    17:44                buckets
d----          2023/04/01    23:37                cache
d----          2023/01/30    23:38                persist
d----          2023/04/01    23:37                shims
PS> ls "$(split-path -parent (Split-Path -Parent ((gcm kotlin).path)))\apps\kotlin\current\lib\"

    Directory: C:\Users\tatsu\scoop\apps\kotlin\current\lib

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-----          1980/02/01     0:00          23724 allopen-compiler-plugin.jar
-----          1980/02/01     0:00         492419 android-extensions-compiler.jar
-----          1980/02/01     0:00           9593 android-extensions-runtime.jar
-----          1980/02/01     0:00          17536 annotations-13.0.jar
-----          1980/02/01     0:00          52265 assignment-compiler-plugin.jar
-----          1980/02/01     0:00          11126 js.engines.jar
-----          1980/02/01     0:00        1177854 jvm-abi-gen.jar
-----          1980/02/01     0:00          26347 kotlin-annotation-processing-cli.jar
-----          1980/02/01     0:00           1377 kotlin-annotation-processing-runtime.jar
-----          1980/02/01     0:00         481458 kotlin-annotation-processing.jar
-----          1980/02/01     0:00           3130 kotlin-annotations-jvm-sources.jar
-----          1980/02/01     0:00           2676 kotlin-annotations-jvm.jar
-----          1980/02/01     0:00          25356 kotlin-ant.jar
-----          1980/02/01     0:00       55137299 kotlin-compiler.jar
-----          1980/02/01     0:00         675469 kotlin-daemon-client.jar
-----          1980/02/01     0:00         733096 kotlin-daemon.jar
-----          1980/02/01     0:00         274006 kotlin-imports-dumper-compiler-plugin.jar
-----          1980/02/01     0:00        6572469 kotlin-main-kts.jar
-----          1980/02/01     0:00          52271 kotlin-preloader.jar
-----          1980/02/01     0:00         713762 kotlin-reflect-sources.jar
-----          1980/02/01     0:00        3155363 kotlin-reflect.jar
-----          1980/02/01     0:00          30873 kotlin-runner.jar
-----          1980/02/01     0:00           9916 kotlin-script-runtime-sources.jar
-----          1980/02/01     0:00          42824 kotlin-script-runtime.jar
-----          1980/02/01     0:00         226059 kotlin-scripting-common.jar
-----          1980/02/01     0:00         317456 kotlin-scripting-compiler-impl.jar
-----          1980/02/01     0:00         376451 kotlin-scripting-compiler.jar
-----          1980/02/01     0:00           7602 kotlin-scripting-js.jar
-----          1980/02/01     0:00         200054 kotlin-scripting-jvm.jar
-----          1980/02/01     0:00            580 kotlin-stdlib-jdk7-sources.jar
-----          1980/02/01     0:00            959 kotlin-stdlib-jdk7.jar
-----          1980/02/01     0:00            556 kotlin-stdlib-jdk8-sources.jar
-----          1980/02/01     0:00            965 kotlin-stdlib-jdk8.jar
-----          1980/02/01     0:00         523365 kotlin-stdlib-js-sources.jar
-----          1980/02/01     0:00        4331907 kotlin-stdlib-js.jar
-----          1980/02/01     0:00         567552 kotlin-stdlib-sources.jar
-----          1980/02/01     0:00        1636556 kotlin-stdlib.jar
-----          1980/02/01     0:00           8040 kotlin-test-js-sources.jar
-----          1980/02/01     0:00         107546 kotlin-test-js.jar
-----          1980/02/01     0:00           1784 kotlin-test-junit-sources.jar
-----          1980/02/01     0:00           5146 kotlin-test-junit.jar
-----          1980/02/01     0:00           1792 kotlin-test-junit5-sources.jar
-----          1980/02/01     0:00           5121 kotlin-test-junit5.jar
-----          1980/02/01     0:00           2272 kotlin-test-sources.jar
-----          1980/02/01     0:00           1775 kotlin-test-testng-sources.jar
-----          1980/02/01     0:00           5144 kotlin-test-testng.jar
-----          1980/02/01     0:00         133094 kotlin-test.jar
-----          1980/02/01     0:00        1482528 kotlinx-coroutines-core-jvm.jar
-----          1980/02/01     0:00         918106 kotlinx-serialization-compiler-plugin.jar
-----          1980/02/01     0:00         319772 lombok-compiler-plugin.jar
-----          1980/02/01     0:00           1472 mutability-annotations-compat.jar
-----          1980/02/01     0:00          62067 noarg-compiler-plugin.jar
-----          1980/02/01     0:00         357668 parcelize-compiler.jar
-----          1980/02/01     0:00           6996 parcelize-runtime.jar
-----          1980/02/01     0:00          18513 sam-with-receiver-compiler-plugin.jar
-----          1980/02/01     0:00         572985 trove4j.jar
PS> cat (gcm kotlin).path
@rem C:\Users\tatsu\scoop\apps\kotlin\current\bin\kotlin.bat
@"C:\Users\tatsu\scoop\apps\kotlin\current\bin\kotlin.bat"  %*

https://github.com/fwcd/kotlin-language-server/blob/8df2a0576ebc2979bd0afa37ba02a04c3f460244/shared/src/main/kotlin/org/javacs/kt/classpath/BackupClassPathResolver.kt#L53-L71

It's only Scoop that includes the latest and standalone Kotlin in package managers for Windows.

fwcd commented 1 year ago

Hm, I think the issue is that scoop creates shim scripts instead of symlinking directly to the compiler, which makes it hard for us to find the compiler (without hardcoding scoop-related paths).

tats-u commented 1 year ago

Right. BackupClassPathResolver.kt must be modified.

fwcd commented 1 year ago

I think you'd want to modify findAlternativeLibraryLocation