From c90037241c4b5412ee468276f322fb666694e978 Mon Sep 17 00:00:00 2001 From: cos Date: Sat, 16 Sep 2023 17:33:43 +0200 Subject: [PATCH] Only call workspace/configuration when available Not all clients implement the client capability: `configuration`, which was added in version 3.6.0 of the Language Server Protocol. The LSP Specification also states: > A missing property should be interpreted as an absence of the capability. Above claims are possible to verify by reading the mentioned spec. at: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration Hence this change modifies behaviour to only call the method on clients explicitly announcing to support it. This commit makes the lua-language-server work with vim-ale. Thanks to Tom Lau for assistance in getting the test-setup updated. --- changelog.md | 1 + script/lclient.lua | 3 +++ script/provider/provider.lua | 15 ++++++++++----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index cd5665735..ce89e6bb4 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ * `FIX` Improve type narrow by checking exact match on literal type params * `FIX` Correctly list enums for function overload arguments [#2840](https://github.com/LuaLS/lua-language-server/pull/2840) * `FIX` Incorrect function params' type infer when there is only `@overload` [#2509](https://github.com/LuaLS/lua-language-server/issues/2509) [#2708](https://github.com/LuaLS/lua-language-server/issues/2708) [#2709](https://github.com/LuaLS/lua-language-server/issues/2709) +* `FIX` Only call workspace/configuration when available [#981](https://github.com/LuaLS/lua-language-server/issues/981), [#2318](https://github.com/LuaLS/lua-language-server/issues/2318), [2336](https://github.com/LuaLS/lua-language-server/issues/2336) [#2843](https://github.com/LuaLS/lua-language-server/pull/2843) ## 3.10.5 `2024-8-19` diff --git a/script/lclient.lua b/script/lclient.lua index 0960729d5..3bcde50ae 100644 --- a/script/lclient.lua +++ b/script/lclient.lua @@ -83,6 +83,9 @@ local defaultClientOptions = { }, }, }, + workspace = { + configuration = true, + }, }, } diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 3d1c5d527..f9f509951 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -41,7 +41,10 @@ function m.updateConfig(uri) end for _, folder in ipairs(scope.folders) do - local clientConfig = cfgLoader.loadClientConfig(folder.uri) + local clientConfig = nil + if client.getAbility('workspace.configuration') then + clientConfig = cfgLoader.loadClientConfig(folder.uri) + end if clientConfig then log.info('Load config from client', folder.uri) log.info(inspect(clientConfig)) @@ -57,10 +60,12 @@ function m.updateConfig(uri) config.update(folder, clientConfig, rc) end - local global = cfgLoader.loadClientConfig() - log.info('Load config from client', 'fallback') - log.info(inspect(global)) - config.update(scope.fallback, global) + if client.getAbility('workspace.configuration') then + local global = cfgLoader.loadClientConfig() + log.info('Load config from client', 'fallback') + log.info(inspect(global)) + config.update(scope.fallback, global) + end end function m.register(method)