mirror of
https://github.com/neovim/neovim.git
synced 2025-10-25 20:07:09 +00:00
lsp: make the command error message more detailed (#11633)
* lsp.lua: make the error message more detailed * test: add lsp._cmd_part test
This commit is contained in:
@@ -122,20 +122,20 @@ local function validate_encoding(encoding)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function lsp._cmd_parts(input)
|
function lsp._cmd_parts(input)
|
||||||
local cmd, cmd_args
|
vim.validate{cmd={
|
||||||
if vim.tbl_islist(input) then
|
input,
|
||||||
cmd = input[1]
|
function() return vim.tbl_islist(input) end,
|
||||||
cmd_args = {}
|
"list"}}
|
||||||
|
|
||||||
|
local cmd = input[1]
|
||||||
|
local cmd_args = {}
|
||||||
-- Don't mutate our input.
|
-- Don't mutate our input.
|
||||||
for i, v in ipairs(input) do
|
for i, v in ipairs(input) do
|
||||||
assert(type(v) == 'string', "input arguments must be strings")
|
vim.validate{["cmd argument"]={v, "s"}}
|
||||||
if i > 1 then
|
if i > 1 then
|
||||||
table.insert(cmd_args, v)
|
table.insert(cmd_args, v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
error("cmd type must be list.")
|
|
||||||
end
|
|
||||||
return cmd, cmd_args
|
return cmd, cmd_args
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -524,7 +524,7 @@ function lsp.start_client(config)
|
|||||||
function client.request(method, params, callback, bufnr)
|
function client.request(method, params, callback, bufnr)
|
||||||
if not callback then
|
if not callback then
|
||||||
callback = resolve_callback(method)
|
callback = resolve_callback(method)
|
||||||
or error("not found: request callback for client "..client.name)
|
or error(string.format("not found: %q request callback for client %q.", method, client.name))
|
||||||
end
|
end
|
||||||
local _ = log.debug() and log.debug(log_prefix, "client.request", client_id, method, params, callback, bufnr)
|
local _ = log.debug() and log.debug(log_prefix, "client.request", client_id, method, params, callback, bufnr)
|
||||||
-- TODO keep these checks or just let it go anyway?
|
-- TODO keep these checks or just let it go anyway?
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ local buf_lines = helpers.buf_lines
|
|||||||
local dedent = helpers.dedent
|
local dedent = helpers.dedent
|
||||||
local exec_lua = helpers.exec_lua
|
local exec_lua = helpers.exec_lua
|
||||||
local eq = helpers.eq
|
local eq = helpers.eq
|
||||||
|
local pcall_err = helpers.pcall_err
|
||||||
local pesc = helpers.pesc
|
local pesc = helpers.pesc
|
||||||
local insert = helpers.insert
|
local insert = helpers.insert
|
||||||
local retry = helpers.retry
|
local retry = helpers.retry
|
||||||
@@ -705,7 +706,6 @@ describe('LSP', function()
|
|||||||
end;
|
end;
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("parsing tests", function()
|
describe("parsing tests", function()
|
||||||
@@ -733,7 +733,23 @@ describe('LSP', function()
|
|||||||
end;
|
end;
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
end)
|
||||||
|
describe('lsp._cmd_parts test', function()
|
||||||
|
local function _cmd_parts(input)
|
||||||
|
return exec_lua([[
|
||||||
|
lsp = require('vim.lsp')
|
||||||
|
return lsp._cmd_parts(...)
|
||||||
|
]], input)
|
||||||
|
end
|
||||||
|
it('should valid cmd argument', function()
|
||||||
|
eq(true, pcall(_cmd_parts, {"nvim"}))
|
||||||
|
eq(true, pcall(_cmd_parts, {"nvim", "--head"}))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('should invalid cmd argument', function()
|
||||||
|
eq('Error executing lua: .../shared.lua: cmd: expected list, got nvim', pcall_err(_cmd_parts, "nvim"))
|
||||||
|
eq('Error executing lua: .../shared.lua: cmd argument: expected string, got number', pcall_err(_cmd_parts, {"nvim", 1}))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user