mirror of
https://github.com/neovim/neovim.git
synced 2026-04-27 17:54:10 +00:00
lsp: Use nvim_buf_get_lines in locations_to_items and add more tests (#12357)
* LSP: Add tests & use nvim_buf_get_lines in locations_to_items This is to add support for cases where the server returns a URI in the locations that does not have a file scheme but needs to be loaded via a BufReadCmd event. * LSP: Don't iterate through all lines in locations_to_items * fixup! LSP: Don't iterate through all lines in locations_to_items * fixup! fixup! LSP: Don't iterate through all lines in locations_to_items * fixup! fixup! fixup! LSP: Don't iterate through all lines in locations_to_items
This commit is contained in:
committed by
GitHub
parent
1920ba4b55
commit
554b21261e
@@ -1089,40 +1089,31 @@ function M.locations_to_items(locations)
|
||||
for _, d in ipairs(locations) do
|
||||
-- locations may be Location or LocationLink
|
||||
local uri = d.uri or d.targetUri
|
||||
local fname = assert(vim.uri_to_fname(uri))
|
||||
local range = d.range or d.targetSelectionRange
|
||||
table.insert(grouped[fname], {start = range.start})
|
||||
table.insert(grouped[uri], {start = range.start})
|
||||
end
|
||||
|
||||
|
||||
local keys = vim.tbl_keys(grouped)
|
||||
table.sort(keys)
|
||||
-- TODO(ashkan) I wish we could do this lazily.
|
||||
for _, fname in ipairs(keys) do
|
||||
local rows = grouped[fname]
|
||||
|
||||
for _, uri in ipairs(keys) do
|
||||
local rows = grouped[uri]
|
||||
table.sort(rows, position_sort)
|
||||
local i = 0
|
||||
for line in io.lines(fname) do
|
||||
for _, temp in ipairs(rows) do
|
||||
local pos = temp.start
|
||||
local row = pos.line
|
||||
if i == row then
|
||||
local col
|
||||
if pos.character > #line then
|
||||
col = #line
|
||||
else
|
||||
col = vim.str_byteindex(line, pos.character)
|
||||
end
|
||||
table.insert(items, {
|
||||
filename = fname,
|
||||
lnum = row + 1,
|
||||
col = col + 1;
|
||||
text = line;
|
||||
})
|
||||
end
|
||||
end
|
||||
i = i + 1
|
||||
local bufnr = vim.uri_to_bufnr(uri)
|
||||
vim.fn.bufload(bufnr)
|
||||
local filename = vim.uri_to_fname(uri)
|
||||
for _, temp in ipairs(rows) do
|
||||
local pos = temp.start
|
||||
local row = pos.line
|
||||
local line = (api.nvim_buf_get_lines(bufnr, row, row + 1, false) or {""})[1]
|
||||
local col = M.character_offset(bufnr, row, pos.character)
|
||||
table.insert(items, {
|
||||
filename = filename,
|
||||
lnum = row + 1,
|
||||
col = col + 1;
|
||||
text = line;
|
||||
})
|
||||
end
|
||||
end
|
||||
return items
|
||||
|
||||
Reference in New Issue
Block a user