lua LSP client: initial implementation (#11336)

Mainly configuration and RPC infrastructure can be considered "done". Specific requests and their callbacks will be improved later (and also served by plugins). There are also some TODO:s for the client itself, like incremental updates.

Co-authored by at-tjdevries and at-h-michael, with many review/suggestion contributions.
This commit is contained in:
Ashkan Kiani
2019-11-13 12:55:26 -08:00
committed by Björn Linse
parent db436d5277
commit 00dc12c5d8
15 changed files with 5556 additions and 1 deletions

View File

@@ -305,6 +305,78 @@ describe('lua stdlib', function()
pcall_err(exec_lua, [[return vim.pesc(2)]]))
end)
it('vim.tbl_keys', function()
eq({}, exec_lua("return vim.tbl_keys({})"))
for _, v in pairs(exec_lua("return vim.tbl_keys({'a', 'b', 'c'})")) do
eq(true, exec_lua("return vim.tbl_contains({ 1, 2, 3 }, ...)", v))
end
for _, v in pairs(exec_lua("return vim.tbl_keys({a=1, b=2, c=3})")) do
eq(true, exec_lua("return vim.tbl_contains({ 'a', 'b', 'c' }, ...)", v))
end
end)
it('vim.tbl_values', function()
eq({}, exec_lua("return vim.tbl_values({})"))
for _, v in pairs(exec_lua("return vim.tbl_values({'a', 'b', 'c'})")) do
eq(true, exec_lua("return vim.tbl_contains({ 'a', 'b', 'c' }, ...)", v))
end
for _, v in pairs(exec_lua("return vim.tbl_values({a=1, b=2, c=3})")) do
eq(true, exec_lua("return vim.tbl_contains({ 1, 2, 3 }, ...)", v))
end
end)
it('vim.tbl_islist', function()
eq(NIL, exec_lua("return vim.tbl_islist({})"))
eq(true, exec_lua("return vim.tbl_islist({'a', 'b', 'c'})"))
eq(false, exec_lua("return vim.tbl_islist({'a', '32', a='hello', b='baz'})"))
eq(false, exec_lua("return vim.tbl_islist({1, a='hello', b='baz'})"))
eq(false, exec_lua("return vim.tbl_islist({a='hello', b='baz', 1})"))
eq(false, exec_lua("return vim.tbl_islist({1, 2, nil, a='hello'})"))
end)
it('vim.tbl_isempty', function()
eq(true, exec_lua("return vim.tbl_isempty({})"))
eq(false, exec_lua("return vim.tbl_isempty({ 1, 2, 3 })"))
eq(false, exec_lua("return vim.tbl_isempty({a=1, b=2, c=3})"))
end)
it('vim.deep_equal', function()
eq(true, exec_lua [[ return vim.deep_equal({a=1}, {a=1}) ]])
eq(true, exec_lua [[ return vim.deep_equal({a={b=1}}, {a={b=1}}) ]])
eq(true, exec_lua [[ return vim.deep_equal({a={b={nil}}}, {a={b={}}}) ]])
eq(true, exec_lua [[ return vim.deep_equal({a=1, [5]=5}, {nil,nil,nil,nil,5,a=1}) ]])
eq(false, exec_lua [[ return vim.deep_equal(1, {nil,nil,nil,nil,5,a=1}) ]])
eq(false, exec_lua [[ return vim.deep_equal(1, 3) ]])
eq(false, exec_lua [[ return vim.deep_equal(nil, 3) ]])
eq(false, exec_lua [[ return vim.deep_equal({a=1}, {a=2}) ]])
end)
it('vim.list_extend', function()
eq({1,2,3}, exec_lua [[ return vim.list_extend({1}, {2,3}) ]])
eq('Error executing lua: .../shared.lua: src must be a table',
pcall_err(exec_lua, [[ return vim.list_extend({1}, nil) ]]))
eq({1,2}, exec_lua [[ return vim.list_extend({1}, {2;a=1}) ]])
eq(true, exec_lua [[ local a = {1} return vim.list_extend(a, {2;a=1}) == a ]])
end)
it('vim.tbl_add_reverse_lookup', function()
eq(true, exec_lua [[
local a = { A = 1 }
vim.tbl_add_reverse_lookup(a)
return vim.deep_equal(a, { A = 1; [1] = 'A'; })
]])
-- Throw an error for trying to do it twice (run into an existing key)
local code = [[
local res = {}
local a = { A = 1 }
vim.tbl_add_reverse_lookup(a)
assert(vim.deep_equal(a, { A = 1; [1] = 'A'; }))
vim.tbl_add_reverse_lookup(a)
]]
matches('Error executing lua: .../shared.lua: The reverse lookup found an existing value for "[1A]" while processing key "[1A]"',
pcall_err(exec_lua, code))
end)
it('vim.call, vim.fn', function()
eq(true, exec_lua([[return vim.call('sin', 0.0) == 0.0 ]]))
eq(true, exec_lua([[return vim.fn.sin(0.0) == 0.0 ]]))