Skip to content

Commit cb15b9d

Browse files
borisbrodskifwcd
authored andcommitted
Fix ShellClassPathResolver on Windows +README.md
Teach ShellClassPathResolver how to get classpath from classpath.bat or classpath.cmd on Windows. Improve README.md describing how to use ShellClassPathResolver on Linux and Windows. Fix broken URL for classpath resolution.
1 parent b4c9349 commit cb15b9d

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,24 @@ There are two hard parts of implementing a language server:
2727

2828
The project uses the internal APIs of the [Kotlin compiler](https://github.com/JetBrains/kotlin/tree/master/compiler).
2929

30-
Dependencies are determined by the [findClassPath](server/src/main/kotlin/org/javacs/kt/classpath/findClassPath.kt) function, which invokes Maven or Gradle and tells it to output a list of dependencies. Currently, both Maven and Gradle projects are supported.
30+
31+
### Figuring out the dependencies
32+
33+
Dependencies are determined by the [DefaultClassPathResolver.kt](shared/src/main/kotlin/org/javacs/kt/classpath/DefaultClassPathResolver.kt), which invokes Maven, Gradle or `$HOME/.config/KotlinLanguageServer/classpath.{sh,bat,cmd}` and tells it to output a list of dependencies.
34+
35+
* Example of the `~/.config/KotlinLanguageServer/classpath.sh` on Linux:
36+
```bash
37+
#!/bin/bash
38+
echo /my/path/kotlin-compiler-1.4.10/lib/kotlin-stdlib.jar:/my/path/my-lib.jar
39+
```
40+
41+
* Example of the `%HOMEPATH%\.config\KotlinLanguageServer\classpath.bat` on Windows:
42+
```cmd
43+
@echo off
44+
echo C:\my\path\kotlin-compiler-1.4.10\lib\kotlin-stdlib.jar;C:\my\path\my-lib.jar
45+
```
46+
47+
### Incrementally re-compiling as the user types
3148

3249
I get incremental compilation at the file-level by keeping the same `KotlinCoreEnvironment` alive between compilations in [Compiler.kt](server/src/main/kotlin/org/javacs/kt/compiler/Compiler.kt). There is a performance benchmark in [OneFilePerformance.kt](server/src/test/kotlin/org/javacs/kt/OneFilePerformance.kt) that verifies this works.
3350

shared/src/main/kotlin/org/javacs/kt/classpath/ShellClassPathResolver.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.javacs.kt.classpath
22

3+
import java.io.File
34
import java.nio.file.Files
45
import java.nio.file.Path
56
import java.nio.file.Paths
@@ -19,7 +20,7 @@ internal class ShellClassPathResolver(
1920
val process = Runtime.getRuntime().exec(cmd, null, workingDirectory)
2021

2122
return process.inputStream.bufferedReader().readText()
22-
.split(':')
23+
.split(File.pathSeparator)
2324
.asSequence()
2425
.map { it.trim() }
2526
.filter { it.isNotEmpty() }
@@ -38,8 +39,11 @@ internal class ShellClassPathResolver(
3839

3940
/** Returns the ShellClassPathResolver for the global home directory shell script. */
4041
fun global(workingDir: Path?): ClassPathResolver =
41-
globalConfigRoot.resolve("KotlinLanguageServer").resolve("classpath.sh")
42-
.takeIf { Files.exists(it) }
42+
globalConfigRoot.resolve("KotlinLanguageServer")?.let {
43+
it.resolve("classpath.sh").takeIf { Files.exists(it) } ?:
44+
it.resolve("classpath.bat").takeIf { Files.exists(it) } ?:
45+
it.resolve("classpath.cmd").takeIf { Files.exists(it) }
46+
}
4347
?.let { ShellClassPathResolver(it, workingDir) }
4448
?: ClassPathResolver.empty
4549
}

0 commit comments

Comments
 (0)