Skip to content

Commit

Permalink
perf: use vim.lsp.util.get_line to get line instad of bufload
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 24, 2021
1 parent 4375f1f commit 607b1d5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lua/trouble/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,21 @@ M.severity = {

function M.process_item(item, bufnr)
local filename = vim.api.nvim_buf_get_name(bufnr)
local uri = vim.uri_from_bufnr(bufnr)
local start = item.range["start"]
local finish = item.range["end"]
local row = start.line
local col = start.character
local line = (vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false) or { "" })[1]

local line
if vim.lsp.util.get_line then
line = vim.lsp.util.get_line(uri, row)
else
-- load the buffer when needed
vim.fn.bufload(bufnr)
line = (vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false) or { "" })[1]
end

item.message = item.message or line or ""

---@class Item
Expand Down Expand Up @@ -112,8 +122,6 @@ function M.locations_to_items(results, default_severity)
if not vim.tbl_isempty(loc) then
local buf = loc.uri and vim.uri_to_bufnr(loc.uri) or bufnr
loc.severity = loc.severity or default_severity
-- load the buffer when needed
vim.fn.bufload(buf)
table.insert(ret, M.process_item(loc, buf))
end
end
Expand Down

0 comments on commit 607b1d5

Please sign in to comment.