feat(lsp): set client offset_encoding if server supports positionEncoding

If the server sends the positionEncoding capability in its
initialization response, automatically set the client's offset_encoding
to use the value provided.
This commit is contained in:
Gregory Anders 2023-06-01 11:15:33 -05:00
parent afb70eba8c
commit fb54e6980e
2 changed files with 32 additions and 0 deletions

View File

@ -1344,6 +1344,10 @@ function lsp.start_client(config)
assert(result.capabilities, "initialize result doesn't contain capabilities")
client.server_capabilities = protocol.resolve_capabilities(client.server_capabilities)
if client.server_capabilities.positionEncoding then
client.offset_encoding = client.server_capabilities.positionEncoding
end
if next(config.settings) then
client.notify('workspace/didChangeConfiguration', { settings = config.settings })
end

View File

@ -218,6 +218,34 @@ describe('LSP', function()
})
end)
it("should set the client's offset_encoding when positionEncoding capability is supported", function()
clear()
exec_lua(create_server_definition)
local result = exec_lua([[
local server = _create_server({
capabilities = {
positionEncoding = "utf-8"
},
})
local client_id = vim.lsp.start({
name = 'dummy',
cmd = server.cmd,
})
if not client_id then
return 'vim.lsp.start did not return client_id'
end
local client = vim.lsp.get_client_by_id(client_id)
if not client then
return 'No client found with id ' .. client_id
end
return client.offset_encoding
]])
eq('utf-8', result)
end)
it('should succeed with manual shutdown', function()
if is_ci() then
pending('hangs the build on CI #14028, re-enable with freeze timeout #14204')