diff options
author | Mathias Fußenegger <mfussenegger@users.noreply.github.com> | 2020-06-30 17:48:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-30 11:48:04 -0400 |
commit | 554b21261ec0ad1eaac7afc21d9a1ba7fb7cabf1 (patch) | |
tree | 312ee1d63d6914e5fd4b1f974fa157b6088acf19 /runtime/lua/vim/lsp/util.lua | |
parent | 1920ba4b5597a872973de0a5d558cbbf23063fb6 (diff) | |
download | rneovim-554b21261ec0ad1eaac7afc21d9a1ba7fb7cabf1.tar.gz rneovim-554b21261ec0ad1eaac7afc21d9a1ba7fb7cabf1.tar.bz2 rneovim-554b21261ec0ad1eaac7afc21d9a1ba7fb7cabf1.zip |
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
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 4176255eb6..ab2992ba60 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -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 |