mirror of
https://github.com/neovim/neovim.git
synced 2026-01-07 05:43:14 +00:00
feat(lsp): add vim.lsp.buf.subtypes(), vim.lsp.buf.supertypes() (#28388)
Co-authored-by: Mathias Fußenegger <mfussenegger@users.noreply.github.com> Co-authored-by: Maria José Solano <majosolano99@gmail.com>
This commit is contained in:
@@ -3461,6 +3461,442 @@ describe('LSP', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('vim.lsp.buf.subtypes', function()
|
||||
it('does nothing for an empty response', function()
|
||||
local qflist_count = exec_lua([=[
|
||||
require'vim.lsp.handlers'['typeHierarchy/subtypes'](nil, nil, {})
|
||||
return #vim.fn.getqflist()
|
||||
]=])
|
||||
eq(0, qflist_count)
|
||||
end)
|
||||
|
||||
it('opens the quickfix list with the right subtypes', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local qflist = exec_lua([=[
|
||||
local clangd_response = { {
|
||||
data = {
|
||||
parents = { {
|
||||
parents = { {
|
||||
parents = { {
|
||||
parents = {},
|
||||
symbolID = "62B3D268A01B9978"
|
||||
} },
|
||||
symbolID = "DC9B0AD433B43BEC"
|
||||
} },
|
||||
symbolID = "06B5F6A19BA9F6A8"
|
||||
} },
|
||||
symbolID = "EDC336589C09ABB2"
|
||||
},
|
||||
kind = 5,
|
||||
name = "D2",
|
||||
range = {
|
||||
["end"] = {
|
||||
character = 8,
|
||||
line = 9
|
||||
},
|
||||
start = {
|
||||
character = 6,
|
||||
line = 9
|
||||
}
|
||||
},
|
||||
selectionRange = {
|
||||
["end"] = {
|
||||
character = 8,
|
||||
line = 9
|
||||
},
|
||||
start = {
|
||||
character = 6,
|
||||
line = 9
|
||||
}
|
||||
},
|
||||
uri = "file:///home/jiangyinzuo/hello.cpp"
|
||||
}, {
|
||||
data = {
|
||||
parents = { {
|
||||
parents = { {
|
||||
parents = { {
|
||||
parents = {},
|
||||
symbolID = "62B3D268A01B9978"
|
||||
} },
|
||||
symbolID = "DC9B0AD433B43BEC"
|
||||
} },
|
||||
symbolID = "06B5F6A19BA9F6A8"
|
||||
} },
|
||||
symbolID = "AFFCAED15557EF08"
|
||||
},
|
||||
kind = 5,
|
||||
name = "D1",
|
||||
range = {
|
||||
["end"] = {
|
||||
character = 8,
|
||||
line = 8
|
||||
},
|
||||
start = {
|
||||
character = 6,
|
||||
line = 8
|
||||
}
|
||||
},
|
||||
selectionRange = {
|
||||
["end"] = {
|
||||
character = 8,
|
||||
line = 8
|
||||
},
|
||||
start = {
|
||||
character = 6,
|
||||
line = 8
|
||||
}
|
||||
},
|
||||
uri = "file:///home/jiangyinzuo/hello.cpp"
|
||||
} }
|
||||
|
||||
local server = _create_server({
|
||||
capabilities = {
|
||||
positionEncoding = "utf-8"
|
||||
},
|
||||
})
|
||||
local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
|
||||
local handler = require'vim.lsp.handlers'['typeHierarchy/subtypes']
|
||||
handler(nil, clangd_response, { client_id = client_id, bufnr = 1 })
|
||||
return vim.fn.getqflist()
|
||||
]=])
|
||||
|
||||
local expected = {
|
||||
{
|
||||
bufnr = 2,
|
||||
col = 7,
|
||||
end_col = 0,
|
||||
end_lnum = 0,
|
||||
lnum = 10,
|
||||
module = '',
|
||||
nr = 0,
|
||||
pattern = '',
|
||||
text = 'D2',
|
||||
type = '',
|
||||
valid = 1,
|
||||
vcol = 0,
|
||||
},
|
||||
{
|
||||
bufnr = 2,
|
||||
col = 7,
|
||||
end_col = 0,
|
||||
end_lnum = 0,
|
||||
lnum = 9,
|
||||
module = '',
|
||||
nr = 0,
|
||||
pattern = '',
|
||||
text = 'D1',
|
||||
type = '',
|
||||
valid = 1,
|
||||
vcol = 0,
|
||||
},
|
||||
}
|
||||
|
||||
eq(expected, qflist)
|
||||
end)
|
||||
|
||||
it('opens the quickfix list with the right subtypes and details', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local qflist = exec_lua([=[
|
||||
local jdtls_response = {
|
||||
{
|
||||
data = { element = '=hello-java_ed323c3c/_<{Main.java[Main[A' },
|
||||
detail = '',
|
||||
kind = 5,
|
||||
name = 'A',
|
||||
range = {
|
||||
['end'] = { character = 26, line = 3 },
|
||||
start = { character = 1, line = 3 },
|
||||
},
|
||||
selectionRange = {
|
||||
['end'] = { character = 8, line = 3 },
|
||||
start = { character = 7, line = 3 },
|
||||
},
|
||||
tags = {},
|
||||
uri = 'file:///home/jiangyinzuo/hello-java/Main.java',
|
||||
},
|
||||
{
|
||||
data = { element = '=hello-java_ed323c3c/_<mylist{MyList.java[MyList[Inner' },
|
||||
detail = 'mylist',
|
||||
kind = 5,
|
||||
name = 'MyList$Inner',
|
||||
range = {
|
||||
['end'] = { character = 37, line = 3 },
|
||||
start = { character = 1, line = 3 },
|
||||
},
|
||||
selectionRange = {
|
||||
['end'] = { character = 19, line = 3 },
|
||||
start = { character = 14, line = 3 },
|
||||
},
|
||||
tags = {},
|
||||
uri = 'file:///home/jiangyinzuo/hello-java/mylist/MyList.java',
|
||||
},
|
||||
}
|
||||
|
||||
local server = _create_server({
|
||||
capabilities = {
|
||||
positionEncoding = "utf-8"
|
||||
},
|
||||
})
|
||||
local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
|
||||
local handler = require'vim.lsp.handlers'['typeHierarchy/subtypes']
|
||||
handler(nil, jdtls_response, { client_id = client_id, bufnr = 1 })
|
||||
return vim.fn.getqflist()
|
||||
]=])
|
||||
|
||||
local expected = {
|
||||
{
|
||||
bufnr = 2,
|
||||
col = 2,
|
||||
end_col = 0,
|
||||
end_lnum = 0,
|
||||
lnum = 4,
|
||||
module = '',
|
||||
nr = 0,
|
||||
pattern = '',
|
||||
text = 'A',
|
||||
type = '',
|
||||
valid = 1,
|
||||
vcol = 0,
|
||||
},
|
||||
{
|
||||
bufnr = 3,
|
||||
col = 2,
|
||||
end_col = 0,
|
||||
end_lnum = 0,
|
||||
lnum = 4,
|
||||
module = '',
|
||||
nr = 0,
|
||||
pattern = '',
|
||||
text = 'MyList$Inner mylist',
|
||||
type = '',
|
||||
valid = 1,
|
||||
vcol = 0,
|
||||
},
|
||||
}
|
||||
eq(expected, qflist)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('vim.lsp.buf.supertypes', function()
|
||||
it('does nothing for an empty response', function()
|
||||
local qflist_count = exec_lua([=[
|
||||
require'vim.lsp.handlers'['typeHierarchy/supertypes'](nil, nil, {})
|
||||
return #vim.fn.getqflist()
|
||||
]=])
|
||||
eq(0, qflist_count)
|
||||
end)
|
||||
|
||||
it('opens the quickfix list with the right supertypes', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local qflist = exec_lua([=[
|
||||
local clangd_response = { {
|
||||
data = {
|
||||
parents = { {
|
||||
parents = { {
|
||||
parents = { {
|
||||
parents = {},
|
||||
symbolID = "62B3D268A01B9978"
|
||||
} },
|
||||
symbolID = "DC9B0AD433B43BEC"
|
||||
} },
|
||||
symbolID = "06B5F6A19BA9F6A8"
|
||||
} },
|
||||
symbolID = "EDC336589C09ABB2"
|
||||
},
|
||||
kind = 5,
|
||||
name = "D2",
|
||||
range = {
|
||||
["end"] = {
|
||||
character = 8,
|
||||
line = 9
|
||||
},
|
||||
start = {
|
||||
character = 6,
|
||||
line = 9
|
||||
}
|
||||
},
|
||||
selectionRange = {
|
||||
["end"] = {
|
||||
character = 8,
|
||||
line = 9
|
||||
},
|
||||
start = {
|
||||
character = 6,
|
||||
line = 9
|
||||
}
|
||||
},
|
||||
uri = "file:///home/jiangyinzuo/hello.cpp"
|
||||
}, {
|
||||
data = {
|
||||
parents = { {
|
||||
parents = { {
|
||||
parents = { {
|
||||
parents = {},
|
||||
symbolID = "62B3D268A01B9978"
|
||||
} },
|
||||
symbolID = "DC9B0AD433B43BEC"
|
||||
} },
|
||||
symbolID = "06B5F6A19BA9F6A8"
|
||||
} },
|
||||
symbolID = "AFFCAED15557EF08"
|
||||
},
|
||||
kind = 5,
|
||||
name = "D1",
|
||||
range = {
|
||||
["end"] = {
|
||||
character = 8,
|
||||
line = 8
|
||||
},
|
||||
start = {
|
||||
character = 6,
|
||||
line = 8
|
||||
}
|
||||
},
|
||||
selectionRange = {
|
||||
["end"] = {
|
||||
character = 8,
|
||||
line = 8
|
||||
},
|
||||
start = {
|
||||
character = 6,
|
||||
line = 8
|
||||
}
|
||||
},
|
||||
uri = "file:///home/jiangyinzuo/hello.cpp"
|
||||
} }
|
||||
|
||||
local server = _create_server({
|
||||
capabilities = {
|
||||
positionEncoding = "utf-8"
|
||||
},
|
||||
})
|
||||
local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
|
||||
local handler = require'vim.lsp.handlers'['typeHierarchy/supertypes']
|
||||
handler(nil, clangd_response, { client_id = client_id, bufnr = 1 })
|
||||
return vim.fn.getqflist()
|
||||
]=])
|
||||
|
||||
local expected = {
|
||||
{
|
||||
bufnr = 2,
|
||||
col = 7,
|
||||
end_col = 0,
|
||||
end_lnum = 0,
|
||||
lnum = 10,
|
||||
module = '',
|
||||
nr = 0,
|
||||
pattern = '',
|
||||
text = 'D2',
|
||||
type = '',
|
||||
valid = 1,
|
||||
vcol = 0,
|
||||
},
|
||||
{
|
||||
bufnr = 2,
|
||||
col = 7,
|
||||
end_col = 0,
|
||||
end_lnum = 0,
|
||||
lnum = 9,
|
||||
module = '',
|
||||
nr = 0,
|
||||
pattern = '',
|
||||
text = 'D1',
|
||||
type = '',
|
||||
valid = 1,
|
||||
vcol = 0,
|
||||
},
|
||||
}
|
||||
|
||||
eq(expected, qflist)
|
||||
end)
|
||||
|
||||
it('opens the quickfix list with the right supertypes and details', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
local qflist = exec_lua([=[
|
||||
local jdtls_response = {
|
||||
{
|
||||
data = { element = '=hello-java_ed323c3c/_<{Main.java[Main[A' },
|
||||
detail = '',
|
||||
kind = 5,
|
||||
name = 'A',
|
||||
range = {
|
||||
['end'] = { character = 26, line = 3 },
|
||||
start = { character = 1, line = 3 },
|
||||
},
|
||||
selectionRange = {
|
||||
['end'] = { character = 8, line = 3 },
|
||||
start = { character = 7, line = 3 },
|
||||
},
|
||||
tags = {},
|
||||
uri = 'file:///home/jiangyinzuo/hello-java/Main.java',
|
||||
},
|
||||
{
|
||||
data = { element = '=hello-java_ed323c3c/_<mylist{MyList.java[MyList[Inner' },
|
||||
detail = 'mylist',
|
||||
kind = 5,
|
||||
name = 'MyList$Inner',
|
||||
range = {
|
||||
['end'] = { character = 37, line = 3 },
|
||||
start = { character = 1, line = 3 },
|
||||
},
|
||||
selectionRange = {
|
||||
['end'] = { character = 19, line = 3 },
|
||||
start = { character = 14, line = 3 },
|
||||
},
|
||||
tags = {},
|
||||
uri = 'file:///home/jiangyinzuo/hello-java/mylist/MyList.java',
|
||||
},
|
||||
}
|
||||
|
||||
local server = _create_server({
|
||||
capabilities = {
|
||||
positionEncoding = "utf-8"
|
||||
},
|
||||
})
|
||||
local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
|
||||
local handler = require'vim.lsp.handlers'['typeHierarchy/supertypes']
|
||||
handler(nil, jdtls_response, { client_id = client_id, bufnr = 1 })
|
||||
return vim.fn.getqflist()
|
||||
]=])
|
||||
|
||||
local expected = {
|
||||
{
|
||||
bufnr = 2,
|
||||
col = 2,
|
||||
end_col = 0,
|
||||
end_lnum = 0,
|
||||
lnum = 4,
|
||||
module = '',
|
||||
nr = 0,
|
||||
pattern = '',
|
||||
text = 'A',
|
||||
type = '',
|
||||
valid = 1,
|
||||
vcol = 0,
|
||||
},
|
||||
{
|
||||
bufnr = 3,
|
||||
col = 2,
|
||||
end_col = 0,
|
||||
end_lnum = 0,
|
||||
lnum = 4,
|
||||
module = '',
|
||||
nr = 0,
|
||||
pattern = '',
|
||||
text = 'MyList$Inner mylist',
|
||||
type = '',
|
||||
valid = 1,
|
||||
vcol = 0,
|
||||
},
|
||||
}
|
||||
eq(expected, qflist)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('vim.lsp.buf.rename', function()
|
||||
for _, test in ipairs({
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user