|
1 | 1 | package org.javacs.kt
|
2 | 2 |
|
| 3 | +import com.google.gson.* |
| 4 | +import org.eclipse.lsp4j.InitializeParams |
| 5 | +import org.javacs.kt.storage.Storage |
| 6 | +import java.lang.reflect.Type |
| 7 | +import java.nio.file.Files |
| 8 | +import java.nio.file.Path |
| 9 | +import java.nio.file.Paths |
| 10 | + |
3 | 11 | public data class SnippetsConfiguration(
|
4 | 12 | /** Whether code completion should return VSCode-style snippets. */
|
5 | 13 | var enabled: Boolean = true
|
@@ -35,10 +43,47 @@ public data class ExternalSourcesConfiguration(
|
35 | 43 | var autoConvertToKotlin: Boolean = true
|
36 | 44 | )
|
37 | 45 |
|
| 46 | + |
| 47 | +fun parseServerConfiguration(params: InitializeParams): ServerConfiguration? { |
| 48 | + val gson = GsonBuilder().registerTypeHierarchyAdapter(Path::class.java, GsonPathConverter()).create() |
| 49 | + |
| 50 | + var storage: Storage? = null |
| 51 | + |
| 52 | + params.initializationOptions?.let { initializationOptions -> |
| 53 | + val options = gson.fromJson(initializationOptions as JsonElement, InitializationOptions::class.java) |
| 54 | + |
| 55 | + options.storagePath?.let { storagePath -> |
| 56 | + if (Files.isDirectory(storagePath)) { |
| 57 | + storage = Storage(storagePath) |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + return ServerConfiguration(storage) |
| 63 | +} |
| 64 | + |
| 65 | +data class InitializationOptions(val storagePath: Path?) |
| 66 | + |
| 67 | +data class ServerConfiguration(val storage: Storage?) |
| 68 | + |
| 69 | +class GsonPathConverter : JsonDeserializer<Path?> { |
| 70 | + |
| 71 | + @Throws(JsonParseException::class) |
| 72 | + override fun deserialize(json: JsonElement, type: Type?, context: JsonDeserializationContext?): Path? { |
| 73 | + return try { |
| 74 | + Paths.get(json.asString) |
| 75 | + } catch (ex: Exception) { |
| 76 | + LOG.printStackTrace(ex) |
| 77 | + null |
| 78 | + } |
| 79 | + } |
| 80 | +} |
| 81 | + |
38 | 82 | public data class Configuration(
|
39 | 83 | val compiler: CompilerConfiguration = CompilerConfiguration(),
|
40 | 84 | val completion: CompletionConfiguration = CompletionConfiguration(),
|
41 | 85 | val linting: LintingConfiguration = LintingConfiguration(),
|
42 | 86 | var indexing: IndexingConfiguration = IndexingConfiguration(),
|
43 |
| - val externalSources: ExternalSourcesConfiguration = ExternalSourcesConfiguration() |
| 87 | + val externalSources: ExternalSourcesConfiguration = ExternalSourcesConfiguration(), |
| 88 | + var server: ServerConfiguration? = null |
44 | 89 | )
|
0 commit comments