mirror of
https://github.com/neovim/neovim.git
synced 2025-12-09 16:12:48 +00:00
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:
committed by
Björn Linse
parent
db436d5277
commit
00dc12c5d8
107
test/functional/lua/uri_spec.lua
Normal file
107
test/functional/lua/uri_spec.lua
Normal file
@@ -0,0 +1,107 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
local clear = helpers.clear
|
||||
local exec_lua = helpers.exec_lua
|
||||
local eq = helpers.eq
|
||||
|
||||
describe('URI methods', function()
|
||||
before_each(function()
|
||||
clear()
|
||||
end)
|
||||
|
||||
describe('file path to uri', function()
|
||||
describe('encode Unix file path', function()
|
||||
it('file path includes only ascii charactors', function()
|
||||
exec_lua("filepath = '/Foo/Bar/Baz.txt'")
|
||||
|
||||
eq('file:///Foo/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)"))
|
||||
end)
|
||||
|
||||
it('file path including white space', function()
|
||||
exec_lua("filepath = '/Foo /Bar/Baz.txt'")
|
||||
|
||||
eq('file:///Foo%20/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)"))
|
||||
end)
|
||||
|
||||
it('file path including Unicode charactors', function()
|
||||
exec_lua("filepath = '/xy/åäö/ɧ/汉语/↥/🤦/🦄/å/بِيَّ.txt'")
|
||||
|
||||
-- The URI encoding should be case-insensitive
|
||||
eq('file:///xy/%c3%a5%c3%a4%c3%b6/%c9%a7/%e6%b1%89%e8%af%ad/%e2%86%a5/%f0%9f%a4%a6/%f0%9f%a6%84/a%cc%8a/%d8%a8%d9%90%d9%8a%d9%8e%d9%91.txt', exec_lua("return vim.uri_from_fname(filepath)"))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('encode Windows filepath', function()
|
||||
it('file path includes only ascii charactors', function()
|
||||
exec_lua([[filepath = 'C:\\Foo\\Bar\\Baz.txt']])
|
||||
|
||||
eq('file:///C:/Foo/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)"))
|
||||
end)
|
||||
|
||||
it('file path including white space', function()
|
||||
exec_lua([[filepath = 'C:\\Foo \\Bar\\Baz.txt']])
|
||||
|
||||
eq('file:///C:/Foo%20/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)"))
|
||||
end)
|
||||
|
||||
it('file path including Unicode charactors', function()
|
||||
exec_lua([[filepath = 'C:\\xy\\åäö\\ɧ\\汉语\\↥\\🤦\\🦄\\å\\بِيَّ.txt']])
|
||||
|
||||
eq('file:///C:/xy/%c3%a5%c3%a4%c3%b6/%c9%a7/%e6%b1%89%e8%af%ad/%e2%86%a5/%f0%9f%a4%a6/%f0%9f%a6%84/a%cc%8a/%d8%a8%d9%90%d9%8a%d9%8e%d9%91.txt', exec_lua("return vim.uri_from_fname(filepath)"))
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('uri to filepath', function()
|
||||
describe('decode Unix file path', function()
|
||||
it('file path includes only ascii charactors', function()
|
||||
exec_lua("uri = 'file:///Foo/Bar/Baz.txt'")
|
||||
|
||||
eq('/Foo/Bar/Baz.txt', exec_lua("return vim.uri_to_fname(uri)"))
|
||||
end)
|
||||
|
||||
it('file path including white space', function()
|
||||
exec_lua("uri = 'file:///Foo%20/Bar/Baz.txt'")
|
||||
|
||||
eq('/Foo /Bar/Baz.txt', exec_lua("return vim.uri_to_fname(uri)"))
|
||||
end)
|
||||
|
||||
it('file path including Unicode charactors', function()
|
||||
local test_case = [[
|
||||
local uri = 'file:///xy/%C3%A5%C3%A4%C3%B6/%C9%A7/%E6%B1%89%E8%AF%AD/%E2%86%A5/%F0%9F%A4%A6/%F0%9F%A6%84/a%CC%8A/%D8%A8%D9%90%D9%8A%D9%8E%D9%91.txt'
|
||||
return vim.uri_to_fname(uri)
|
||||
]]
|
||||
|
||||
eq('/xy/åäö/ɧ/汉语/↥/🤦/🦄/å/بِيَّ.txt', exec_lua(test_case))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('decode Windows filepath', function()
|
||||
it('file path includes only ascii charactors', function()
|
||||
local test_case = [[
|
||||
local uri = 'file:///C:/Foo/Bar/Baz.txt'
|
||||
return vim.uri_to_fname(uri)
|
||||
]]
|
||||
|
||||
eq('C:\\Foo\\Bar\\Baz.txt', exec_lua(test_case))
|
||||
end)
|
||||
|
||||
it('file path including white space', function()
|
||||
local test_case = [[
|
||||
local uri = 'file:///C:/Foo%20/Bar/Baz.txt'
|
||||
return vim.uri_to_fname(uri)
|
||||
]]
|
||||
|
||||
eq('C:\\Foo \\Bar\\Baz.txt', exec_lua(test_case))
|
||||
end)
|
||||
|
||||
it('file path including Unicode charactors', function()
|
||||
local test_case = [[
|
||||
local uri = 'file:///C:/xy/%C3%A5%C3%A4%C3%B6/%C9%A7/%E6%B1%89%E8%AF%AD/%E2%86%A5/%F0%9F%A4%A6/%F0%9F%A6%84/a%CC%8A/%D8%A8%D9%90%D9%8A%D9%8E%D9%91.txt'
|
||||
return vim.uri_to_fname(uri)
|
||||
]]
|
||||
|
||||
eq('C:\\xy\\åäö\\ɧ\\汉语\\↥\\🤦\\🦄\\å\\بِيَّ.txt', exec_lua(test_case))
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
@@ -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 ]]))
|
||||
|
||||
Reference in New Issue
Block a user