neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 7ade44fefe864961cfa17d1af6c8b8b33eeb4933
parent afb70eba8cdfc44b3633bdb91a1554b86b06a5d0
Author: Gregory Anders <8965202+gpanders@users.noreply.github.com>
Date:   Thu,  1 Jun 2023 12:10:48 -0500

Merge pull request #23871 from gpanders/lsp-position-encoding

Add support for LSP positionEncoding capability
Diffstat:
Mruntime/doc/news.txt | 6++++++
Mruntime/lua/vim/lsp.lua | 4++++
Mruntime/lua/vim/lsp/protocol.lua | 7+++++++
Mtest/functional/plugin/lsp_spec.lua | 28++++++++++++++++++++++++++++
4 files changed, 45 insertions(+), 0 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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')