Skip to content

Commit

Permalink
perf: dont load buffers when processing items. Get line with luv instead
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Feb 16, 2023
1 parent bf0eeea commit 82c9a9a
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lua/trouble/util.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local config = require("trouble.config")
local uv = vim.loop

local M = {}

Expand Down Expand Up @@ -146,17 +147,13 @@ function M.process_item(item, bufnr)
local row = start.line
local col = start.character

if not item.message then
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
if not item.message and filename then
local fd = assert(uv.fs_open(filename, "r", 438))
local stat = assert(uv.fs_fstat(fd))
local data = assert(uv.fs_read(fd, stat.size, 0))
assert(uv.fs_close(fd))

item.message = item.message or line or ""
item.message = vim.split(data, "\n", { plain = true })[row + 1] or ""
end

---@class Item
Expand Down

0 comments on commit 82c9a9a

Please sign in to comment.