Skip to content

Commit ac26ad8

Browse files
committed
Accept better defaults for ShellClassPathResolver
Update the ShellClassPathResolver to accept ~/.config/kotlin-language-server (instead of KotlinLanguageServer) and kls-classpath.{sh,bat,cmd} instead of kotlinLspClasspath.{sh,bat,cmd}, along with scripts without a file extension to better adhere to Unix conventions.
1 parent 80ad2d8 commit ac26ad8

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ The project uses the internal APIs of the [Kotlin compiler](https://github.com/J
3737

3838
### Figuring out the dependencies
3939

40-
Dependencies are determined by the [DefaultClassPathResolver.kt](shared/src/main/kotlin/org/javacs/kt/classpath/DefaultClassPathResolver.kt), which invokes Maven or Gradle to get a list of classpath JARs. Alternatively, projects can also 'manually' provide a list of dependencies through a shell script, located either at `[project root]/kotlinLspClasspath.{sh,bat,cmd}` or `[config root]/KotlinLanguageServer/classpath.{sh,bat,cmd}`, which outputs a list of JARs.
40+
Dependencies are determined by the [DefaultClassPathResolver.kt](shared/src/main/kotlin/org/javacs/kt/classpath/DefaultClassPathResolver.kt), which invokes Maven or Gradle to get a list of classpath JARs. Alternatively, projects can also 'manually' provide a list of dependencies through a shell script, located either at `[project root]/kls-classpath` or `[config root]/kotlin-language-server/classpath`, which outputs a list of JARs. Depending on your platform, the scripts also can be suffixed with `.{sh,bat,cmd}`.
4141

42-
* Example of the `~/.config/KotlinLanguageServer/classpath.sh` on Linux:
42+
* Example of the `~/.config/kotlin-language-server/classpath` on Linux:
4343
```bash
4444
#!/bin/bash
4545
echo /my/path/kotlin-compiler-1.4.10/lib/kotlin-stdlib.jar:/my/path/my-lib.jar
4646
```
4747

48-
* Example of the `%HOMEPATH%\.config\KotlinLanguageServer\classpath.bat` on Windows:
48+
* Example of the `%HOMEPATH%\.config\kotlin-language-server\classpath.bat` on Windows:
4949
```cmd
5050
@echo off
5151
echo C:\my\path\kotlin-compiler-1.4.10\lib\kotlin-stdlib.jar;C:\my\path\my-lib.jar

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ internal class ShellClassPathResolver(
2929
}
3030

3131
companion object {
32-
private val scriptExtensions = listOf("sh", "bat", "cmd")
32+
private val configDirNames = listOf("kotlin-language-server", "KotlinLanguageServer")
33+
private val scriptNames = listOf("kls-classpath", "kotlinLspClasspath")
34+
private val scriptExtensions = listOf("", ".sh", ".bat", ".cmd")
3335

3436
/** Create a shell resolver if a file is a pom. */
3537
fun maybeCreate(file: Path): ShellClassPathResolver? =
36-
file.takeIf { scriptExtensions.any { file.endsWith("kotlinLspClasspath.$it") } }
38+
file.takeIf { scriptNames.any { name -> scriptExtensions.any { file.endsWith("$name$it") } } }
3739
?.let { ShellClassPathResolver(it) }
3840

3941
/** The root directory for config files. */
@@ -42,12 +44,10 @@ internal class ShellClassPathResolver(
4244

4345
/** Returns the ShellClassPathResolver for the global home directory shell script. */
4446
fun global(workingDir: Path?): ClassPathResolver =
45-
globalConfigRoot.resolve("KotlinLanguageServer")
46-
?.let { root ->
47-
scriptExtensions
48-
.map { root.resolve("classpath.$it") }
49-
.firstOrNull { Files.exists(it) }
50-
}
47+
configDirNames
48+
.map(globalConfigRoot::resolve)
49+
.flatMap { root -> scriptExtensions.map { root.resolve("classpath$it") } }
50+
.firstOrNull(Files::exists)
5151
?.let { ShellClassPathResolver(it, workingDir) }
5252
?: ClassPathResolver.empty
5353
}

0 commit comments

Comments
 (0)