From 5e49ef0af3cb8dba658e5d0dc6a807f8edebf590 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 11 Jun 2024 12:05:18 +0100 Subject: refactor(lua): improve type annotations --- runtime/lua/vim/lsp/rpc.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim/lsp/rpc.lua') diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua index 3c63a12da2..5e2b041a0a 100644 --- a/runtime/lua/vim/lsp/rpc.lua +++ b/runtime/lua/vim/lsp/rpc.lua @@ -140,7 +140,7 @@ local client_errors = { SERVER_RESULT_CALLBACK_ERROR = 7, } ---- @type table +--- @type table | table --- @nodoc M.client_errors = vim.deepcopy(client_errors) for k, v in pairs(client_errors) do @@ -502,7 +502,7 @@ function Client:handle_body(body) if decoded.error then decoded.error = setmetatable(decoded.error, { __tostring = M.format_rpc_error, - }) --- @type table + }) end self:try_call( M.client_errors.SERVER_RESULT_CALLBACK_ERROR, -- cgit From 81b372fecd749d350fbd86be1f65146b2df97b70 Mon Sep 17 00:00:00 2001 From: Tama McGlinn Date: Fri, 14 Jun 2024 11:02:36 +0200 Subject: fix(lsp): check for nil response from server (#29196) this only changes the error message, so that it is clear that the error is with the LSP server, rather than being a crash inside nvim runtime scripts. We are already doing a lot of validation, it's just that nil was being overlooked here. This fixes issue #27395 --- runtime/lua/vim/lsp/rpc.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'runtime/lua/vim/lsp/rpc.lua') diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua index 5e2b041a0a..7acb67b25e 100644 --- a/runtime/lua/vim/lsp/rpc.lua +++ b/runtime/lua/vim/lsp/rpc.lua @@ -407,7 +407,9 @@ function Client:handle_body(body) end log.debug('rpc.receive', decoded) - if type(decoded.method) == 'string' and decoded.id then + if type(decoded) ~= 'table' then + self:on_error(M.client_errors.INVALID_SERVER_MESSAGE, decoded) + elseif type(decoded.method) == 'string' and decoded.id then local err --- @type lsp.ResponseError|nil -- Schedule here so that the users functions don't trigger an error and -- we can still use the result. -- cgit From bcae8be91f9fd4967f0c6f6ffabf59702253949b Mon Sep 17 00:00:00 2001 From: Tristan Knight Date: Sun, 1 Sep 2024 23:46:01 +0100 Subject: docs: vim.lsp.rpc.connect() TCP requires IP address #30219 "localhost" would work if we used [tcp_connect](https://github.com/luvit/luv/blob/ae0387742b460bc89ebddce33214ad65fffddba2/examples/echo-server-client.lua#L42), but that will require changes to [vim.lsp.rpc.connect](https://github.com/neovim/neovim/blob/318c0415d5b10b44fee4afa06994734f1beb7e71/runtime/lua/vim/lsp/rpc.lua#L638). --- runtime/lua/vim/lsp/rpc.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim/lsp/rpc.lua') diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua index 7acb67b25e..a9c6723094 100644 --- a/runtime/lua/vim/lsp/rpc.lua +++ b/runtime/lua/vim/lsp/rpc.lua @@ -627,12 +627,12 @@ end --- --- - a named pipe (windows) --- - a domain socket (unix) ---- - a host and port via TCP +--- - a host and port via TCP (host must be IP address) --- --- Return a function that can be passed to the `cmd` field for --- |vim.lsp.start_client()| or |vim.lsp.start()|. --- ----@param host_or_path string host to connect to or path to a pipe/domain socket +---@param host_or_path string host (IP address) to connect to or path to a pipe/domain socket ---@param port integer? TCP port to connect to. If absent the first argument must be a pipe ---@return fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient function M.connect(host_or_path, port) -- cgit From 45e76acaa053a077cab49b6606536d3f2646f033 Mon Sep 17 00:00:00 2001 From: Tristan Knight Date: Tue, 3 Sep 2024 16:10:39 +0100 Subject: feat(lsp): support hostname in rpc.connect #30238 Updated the `rpc.connect` function to support connecting to LSP servers using hostnames, not just IP addresses. This change includes updates to the documentation and additional test cases to verify the new functionality. - Modified `connect` function to resolve hostnames. - Updated documentation to reflect the change. - Added test case for connecting using hostname. Added a TCP echo server utility function to the LSP test suite. This server echoes the first message it receives and is used in tests to verify LSP server connections via both IP address and hostname. Refactored existing tests to use the new utility function. --- runtime/lua/vim/lsp/rpc.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim/lsp/rpc.lua') diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua index a9c6723094..d81eae20d1 100644 --- a/runtime/lua/vim/lsp/rpc.lua +++ b/runtime/lua/vim/lsp/rpc.lua @@ -627,12 +627,12 @@ end --- --- - a named pipe (windows) --- - a domain socket (unix) ---- - a host and port via TCP (host must be IP address) +--- - a host and port via TCP --- --- Return a function that can be passed to the `cmd` field for --- |vim.lsp.start_client()| or |vim.lsp.start()|. --- ----@param host_or_path string host (IP address) to connect to or path to a pipe/domain socket +---@param host_or_path string host to connect to or path to a pipe/domain socket ---@param port integer? TCP port to connect to. If absent the first argument must be a pipe ---@return fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient function M.connect(host_or_path, port) @@ -703,7 +703,9 @@ function M.connect(host_or_path, port) if port == nil then handle:connect(host_or_path, on_connect) else - handle:connect(host_or_path, port, on_connect) + local info = uv.getaddrinfo(host_or_path, nil) + local resolved_host = info and info[1] and info[1].addr or host_or_path + handle:connect(resolved_host, port, on_connect) end return public_client(client) -- cgit From 47e6b2233feffc6e9d94f6086fb904eb5688fa25 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 23 Sep 2024 06:05:58 -0700 Subject: fix(vim.fs): dirname() returns "." on mingw/msys2 #30480 Problem: `vim.fs.dirname([[C:\User\XXX\AppData\Local]])` returns "." on mingw/msys2. Solution: - Check for "mingw" when deciding `iswin`. - Use `has("win32")` where possible, it works in "fast" contexts since b02eeb6a7281df0561a021d7ae595c84be9a01be. --- runtime/lua/vim/lsp/rpc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/lsp/rpc.lua') diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua index d81eae20d1..bc24501eae 100644 --- a/runtime/lua/vim/lsp/rpc.lua +++ b/runtime/lua/vim/lsp/rpc.lua @@ -3,7 +3,7 @@ local log = require('vim.lsp.log') local protocol = require('vim.lsp.protocol') local validate, schedule, schedule_wrap = vim.validate, vim.schedule, vim.schedule_wrap -local is_win = uv.os_uname().version:find('Windows') +local is_win = vim.fn.has('win32') == 1 --- Checks whether a given path exists and is a directory. ---@param filename string path to check -- cgit From 385fbfb3e739b457027b469782678f86eefdf7fc Mon Sep 17 00:00:00 2001 From: James Trew <66286082+jamestrew@users.noreply.github.com> Date: Thu, 3 Oct 2024 10:45:51 +0000 Subject: docs: improve luacats support #30580 Some composite/compound types even as basic as `(string|number)[]` are not currently supported by the luacats LPEG grammar used by gen_vimdoc. It would be parsed & rendered as just `string|number`. Changeset adds better support for these types. --- runtime/lua/vim/lsp/rpc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/lsp/rpc.lua') diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua index bc24501eae..e79dbd2db3 100644 --- a/runtime/lua/vim/lsp/rpc.lua +++ b/runtime/lua/vim/lsp/rpc.lua @@ -550,7 +550,7 @@ local function new_client(dispatchers, transport) end ---@class vim.lsp.rpc.PublicClient ----@field request fun(method: string, params: table?, callback: fun(err: lsp.ResponseError|nil, result: any), notify_reply_callback: fun(integer)|nil):boolean,integer? see |vim.lsp.rpc.request()| +---@field request fun(method: string, params: table?, callback: fun(err: lsp.ResponseError|nil, result: any), notify_reply_callback: fun(message_id: integer)|nil):boolean,integer? see |vim.lsp.rpc.request()| ---@field notify fun(method: string, params: any):boolean see |vim.lsp.rpc.notify()| ---@field is_closing fun(): boolean ---@field terminate fun() -- cgit