Skip to content

Commit ae2dcd5

Browse files
committed
Update ShellClassPathResolver and description
1 parent cb15b9d commit ae2dcd5

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Kotlin Language Server
2+
23
[![Release](https://img.shields.io/github/release/fwcd/kotlin-language-server)](https://github.com/fwcd/kotlin-language-server/releases)
34
[![Build](https://github.com/fwcd/kotlin-language-server/actions/workflows/build.yml/badge.svg)](https://github.com/fwcd/kotlin-language-server/actions/workflows/build.yml)
45
[![Downloads](https://img.shields.io/github/downloads/fwcd/kotlin-language-server/total)](https://github.com/fwcd/kotlin-language-server/releases)
@@ -11,6 +12,7 @@ A [language server](https://microsoft.github.io/language-server-protocol/) that
1112
Any editor conforming to LSP is supported, including [VSCode](https://github.com/fwcd/vscode-kotlin) and [Atom](https://github.com/fwcd/atom-ide-kotlin).
1213

1314
## Getting Started
15+
1416
* See [BUILDING.md](BUILDING.md) for build instructions
1517
* See [Editor Integration](EDITORS.md) for editor-specific instructions
1618
* See [Roadmap](https://github.com/fwcd/kotlin-language-server/projects/1) for features, planned additions, bugfixes and changes
@@ -19,6 +21,7 @@ Any editor conforming to LSP is supported, including [VSCode](https://github.com
1921
* See [tree-sitter-kotlin](https://github.com/fwcd/tree-sitter-kotlin) for an experimental [Tree-Sitter](https://tree-sitter.github.io/tree-sitter/) grammar
2022

2123
## This repository needs your help!
24+
2225
[The original author](https://github.com/georgewfraser) created this project while he was considering using Kotlin in his work. He ended up deciding not to and is not really using Kotlin these days though this is a pretty fully-functional language server that just needs someone to use it every day for a while and iron out the last few pesky bugs.
2326

2427
There are two hard parts of implementing a language server:
@@ -27,10 +30,9 @@ There are two hard parts of implementing a language server:
2730

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

33+
### Figuring out the dependencies
3034

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.
35+
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.
3436

3537
* Example of the `~/.config/KotlinLanguageServer/classpath.sh` on Linux:
3638
```bash

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,24 @@ internal class ShellClassPathResolver(
2929
}
3030

3131
companion object {
32+
private val scriptExtensions = listOf("sh", "bat", "cmd")
33+
3234
/** Create a shell resolver if a file is a pom. */
3335
fun maybeCreate(file: Path): ShellClassPathResolver? =
34-
file.takeIf { it.endsWith("kotlinLspClasspath.sh") }?.let { ShellClassPathResolver(it) }
36+
file.takeIf { scriptExtensions.any { file.endsWith("kotlinLspClasspath.$it") } }
37+
?.let { ShellClassPathResolver(it) }
3538

3639
/** The root directory for config files. */
3740
private val globalConfigRoot: Path =
3841
System.getenv("XDG_CONFIG_HOME")?.let { Paths.get(it) } ?: userHome.resolve(".config")
3942

4043
/** Returns the ShellClassPathResolver for the global home directory shell script. */
4144
fun global(workingDir: Path?): ClassPathResolver =
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) }
45+
globalConfigRoot.resolve("KotlinLanguageServer")
46+
?.let { root ->
47+
scriptExtensions
48+
.map { root.resolve("classpath.$it") }
49+
.first { Files.exists(it) }
4650
}
4751
?.let { ShellClassPathResolver(it, workingDir) }
4852
?: ClassPathResolver.empty

0 commit comments

Comments
 (0)