Skip to content

Commit

Permalink
Only call workspace/configuration when available
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cos committed Sep 9, 2024
1 parent a126e9c commit c900372
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions script/lclient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ local defaultClientOptions = {
},
},
},
workspace = {
configuration = true,
},
},
}

Expand Down
15 changes: 10 additions & 5 deletions script/provider/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down

0 comments on commit c900372

Please sign in to comment.