kotlin-language-server
kotlin-language-server copied to clipboard
Investigate improving configuration flow by sending `workspace/configuration` at startup
Extracted from https://github.com/fwcd/kotlin-language-server/pull/367#discussion_r969869742
There was some discussion upstream (in the LSP repo) on encouraging servers to move to a pull-model where the server fetches configurations through workspace/configuration at startup instead of relying on the configuration to always be passed at launch. Ideally we should probably do something similar in the medium term.
Some interesting threads:
- https://github.com/microsoft/vscode-languageserver-node/issues/524
- https://github.com/Microsoft/language-server-protocol/issues/567
- https://github.com/haskell/haskell-language-server/issues/2762
So, i am actually working on that, however with the way the configuration class currently works it would be quite clunky to implement, what do you suggest as a rough idea? This is how the request and its handling would generally work with the current system:
private fun newConfig(item: String) = ConfigurationItem().also { it.section = item }
override fun initialized(params: InitializedParams?) {
client.configuration(ConfigurationParams(listOf(
newConfig("foo"),
newConfig("bar")
))).get().let { // Blocking to ensure we are loaded before continuing
// Note the boilerplate and inability to use a loop as well as the order requirement
config.foo = it[0] as X
config.bar = it[1] as Y
}
}
Reflection could potentially be used to make it better but that would still be fairly hacky, i believe it would be better to rewrite the config system entirely.