aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2023-06-01 12:10:48 -0500
committerGitHub <noreply@github.com>2023-06-01 12:10:48 -0500
commit7ade44fefe864961cfa17d1af6c8b8b33eeb4933 (patch)
tree94f503464e247241b81bf2cd5dc28b99e7c2ef60
parentafb70eba8cdfc44b3633bdb91a1554b86b06a5d0 (diff)
parent15641f38cf4b489a7c83e2c3aa6efc4c63009f00 (diff)
downloadrneovim-7ade44fefe864961cfa17d1af6c8b8b33eeb4933.tar.gz
rneovim-7ade44fefe864961cfa17d1af6c8b8b33eeb4933.tar.bz2
rneovim-7ade44fefe864961cfa17d1af6c8b8b33eeb4933.zip
Merge pull request #23871 from gpanders/lsp-position-encoding
Add support for LSP positionEncoding capability
-rw-r--r--runtime/doc/news.txt6
-rw-r--r--runtime/lua/vim/lsp.lua4
-rw-r--r--runtime/lua/vim/lsp/protocol.lua7
-rw-r--r--test/functional/plugin/lsp_spec.lua28
4 files changed, 45 insertions, 0 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 72eb182fa5..3fd2d4d40e 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -39,6 +39,12 @@ ADDED FEATURES *news-added*
The following new APIs or features were added.
+• Nvim's LSP client now advertises the general.positionEncodings client
+ capability to indicate to servers that it supports utf-8, utf-16, and utf-32
+ encodings. If the server responds with the positionEncoding capability in
+ its initialization response, Nvim automatically sets the client's
+ `offset_encoding` field.
+
• Dynamic registration of LSP capabilities. An implication of this change is that checking a client's `server_capabilities` is no longer a sufficient indicator to see if a server supports a feature. Instead use `client.supports_method(<method>)`. It considers both the dynamic capabilities and static `server_capabilities`.
• |vim.iter()| provides a generic iterator interface for tables and Lua
iterators |luaref-in|.
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index d64ed0b5a3..baf8b5c1a8 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -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
diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua
index a28ff407b7..7e49a572e7 100644
--- a/runtime/lua/vim/lsp/protocol.lua
+++ b/runtime/lua/vim/lsp/protocol.lua
@@ -634,6 +634,13 @@ export interface WorkspaceClientCapabilities {
--- capabilities.
function protocol.make_client_capabilities()
return {
+ general = {
+ positionEncodings = {
+ 'utf-8',
+ 'utf-16',
+ 'utf-32',
+ },
+ },
textDocument = {
semanticTokens = {
dynamicRegistration = false,
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index e0ce62c0db..dac49345d0 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -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')