diff options
author | Josh Rahm <rahm@google.com> | 2022-08-19 12:26:08 -0600 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2022-08-19 13:06:41 -0600 |
commit | a7237662f96933efe29eed8212464571e3778cd0 (patch) | |
tree | 27930202726b4251437c8cfa53069f65b4db90dc /runtime/lua/vim/lsp | |
parent | 02292344929069ea63c0bb872cc22d552d86b67f (diff) | |
parent | b2f979b30beac67906b2dd717fcb6a34f46f5e54 (diff) | |
download | rneovim-tmp.tar.gz rneovim-tmp.tar.bz2 rneovim-tmp.zip |
Merge branch 'master' of https://github.com/neovim/neovim into rahmtmp
Diffstat (limited to 'runtime/lua/vim/lsp')
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 14 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/rpc.lua | 25 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 2 |
3 files changed, 21 insertions, 20 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index 63f4688d94..6a070928d9 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -61,7 +61,7 @@ end --- ---@param options table|nil additional options --- - reuse_win: (boolean) Jump to existing window if buffer is already open. ---- - on_list: (function) handler for list results. See |on-list-handler| +--- - on_list: (function) handler for list results. See |lsp-on-list-handler| function M.declaration(options) local params = util.make_position_params() request_with_options('textDocument/declaration', params, options) @@ -71,7 +71,7 @@ end --- ---@param options table|nil additional options --- - reuse_win: (boolean) Jump to existing window if buffer is already open. ---- - on_list: (function) handler for list results. See |on-list-handler| +--- - on_list: (function) handler for list results. See |lsp-on-list-handler| function M.definition(options) local params = util.make_position_params() request_with_options('textDocument/definition', params, options) @@ -81,7 +81,7 @@ end --- ---@param options table|nil additional options --- - reuse_win: (boolean) Jump to existing window if buffer is already open. ---- - on_list: (function) handler for list results. See |on-list-handler| +--- - on_list: (function) handler for list results. See |lsp-on-list-handler| function M.type_definition(options) local params = util.make_position_params() request_with_options('textDocument/typeDefinition', params, options) @@ -91,7 +91,7 @@ end --- quickfix window. --- ---@param options table|nil additional options ---- - on_list: (function) handler for list results. See |on-list-handler| +--- - on_list: (function) handler for list results. See |lsp-on-list-handler| function M.implementation(options) local params = util.make_position_params() request_with_options('textDocument/implementation', params, options) @@ -503,7 +503,7 @@ end ---@param context (table) Context for the request ---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references ---@param options table|nil additional options ---- - on_list: (function) handler for list results. See |on-list-handler| +--- - on_list: (function) handler for list results. See |lsp-on-list-handler| function M.references(context, options) validate({ context = { context, 't', true } }) local params = util.make_position_params() @@ -516,7 +516,7 @@ end --- Lists all symbols in the current buffer in the quickfix window. --- ---@param options table|nil additional options ---- - on_list: (function) handler for list results. See |on-list-handler| +--- - on_list: (function) handler for list results. See |lsp-on-list-handler| function M.document_symbol(options) local params = { textDocument = util.make_text_document_params() } request_with_options('textDocument/documentSymbol', params, options) @@ -659,7 +659,7 @@ end --- ---@param query (string, optional) ---@param options table|nil additional options ---- - on_list: (function) handler for list results. See |on-list-handler| +--- - on_list: (function) handler for list results. See |lsp-on-list-handler| function M.workspace_symbol(query, options) query = query or npcall(vim.fn.input, 'Query: ') if query == nil then diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua index 913eee19a2..0926912066 100644 --- a/runtime/lua/vim/lsp/rpc.lua +++ b/runtime/lua/vim/lsp/rpc.lua @@ -58,12 +58,10 @@ end ---@private --- Parses an LSP Message's header --- ----@param header: The header to parse. ----@returns Parsed headers +---@param header string: The header to parse. +---@return table parsed headers local function parse_headers(header) - if type(header) ~= 'string' then - return nil - end + assert(type(header) == 'string', 'header must be a string') local headers = {} for line in vim.gsplit(header, '\r\n', true) do if line == '' then @@ -189,9 +187,9 @@ end --- Creates an RPC response object/table. --- ----@param code RPC error code defined in `vim.lsp.protocol.ErrorCodes` ----@param message (optional) arbitrary message to send to server ----@param data (optional) arbitrary data to send to server +---@param code number RPC error code defined in `vim.lsp.protocol.ErrorCodes` +---@param message string|nil arbitrary message to send to server +---@param data any|nil arbitrary data to send to server local function rpc_response_error(code, message, data) -- TODO should this error or just pick a sane error (like InternalError)? local code_name = assert(protocol.ErrorCodes[code], 'Invalid RPC error code') @@ -248,13 +246,13 @@ end --- ---@param cmd (string) Command to start the LSP server. ---@param cmd_args (table) List of additional string arguments to pass to {cmd}. ----@param dispatchers (table, optional) Dispatchers for LSP message types. Valid +---@param dispatchers table|nil Dispatchers for LSP message types. Valid ---dispatcher names are: --- - `"notification"` --- - `"server_request"` --- - `"on_error"` --- - `"on_exit"` ----@param extra_spawn_params (table, optional) Additional context for the LSP +---@param extra_spawn_params table|nil Additional context for the LSP --- server process. May contain: --- - {cwd} (string) Working directory for the LSP server process --- - {env} (table) Additional environment variables for LSP server process @@ -342,6 +340,9 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params) end handle, pid = uv.spawn(cmd, spawn_params, onexit) if handle == nil then + stdin:close() + stdout:close() + stderr:close() local msg = string.format('Spawning language server with cmd: `%s` failed', cmd) if string.match(pid, 'ENOENT') then msg = msg @@ -434,7 +435,7 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params) end end - stderr:read_start(function(_err, chunk) + stderr:read_start(function(_, chunk) if chunk then local _ = log.error() and log.error('rpc', cmd, 'stderr', chunk) end @@ -520,7 +521,7 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params) -- This works because we are expecting vim.NIL here elseif decoded.id and (decoded.result ~= vim.NIL or decoded.error ~= vim.NIL) then -- We sent a number, so we expect a number. - local result_id = tonumber(decoded.id) + local result_id = assert(tonumber(decoded.id), 'response id must be a number') -- Notify the user that a response was received for the request local notify_reply_callback = notify_reply_callbacks and notify_reply_callbacks[result_id] diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index eac21db386..283099bbcf 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -113,7 +113,7 @@ end --- Convert byte index to `encoding` index. --- Convenience wrapper around vim.str_utfindex ---@param line string line to be indexed ----@param index number byte index (utf-8), or `nil` for length +---@param index number|nil byte index (utf-8), or `nil` for length ---@param encoding string utf-8|utf-16|utf-32|nil defaults to utf-16 ---@return number `encoding` index of `index` in `line` function M._str_utfindex_enc(line, index, encoding) |