Skip to content

Commit

Permalink
fix: lsp diag creates ugly buffers for unopened files in the workspac…
Browse files Browse the repository at this point in the history
…e. Fixed now
  • Loading branch information
folke committed Apr 22, 2021
1 parent 232c539 commit 91d1139
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions lua/trouble/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local function preprocess_diag(diag, bufnr)

---@class Diagnostics
---@field is_file boolean
---@field fixed boolean
local ret
ret = {
bufnr = bufnr,
Expand Down
24 changes: 21 additions & 3 deletions lua/trouble/view.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
local renderer = require("trouble.renderer")
local config = require("trouble.config")
local folds = require("trouble.folds")
local pfiletype = require('plenary.filetype')

local highlight = vim.api.nvim_buf_add_highlight
local buf_opt = vim.api.nvim_buf_get_option

---@class View
---@field buf number
Expand Down Expand Up @@ -142,7 +144,7 @@ function View:setup(opts)
vim.api.nvim_exec([[
augroup LspTroubleHighlights
autocmd! * <buffer>
autocmd CursorMoved <buffer> lua require("trouble").action("preview")
autocmd CursorMoved <buffer> nested lua require("trouble").action("preview")
autocmd BufEnter <buffer> lua require("trouble").action("on_enter")
autocmd BufLeave <buffer> lua require("trouble").action("on_leave")
augroup END
Expand Down Expand Up @@ -279,18 +281,34 @@ function View:jump(opts)
View.switch_to(opts.win or self.parent, item.bufnr)
vim.api.nvim_win_set_cursor(self.parent,
{item.start.line + 1, item.start.character})

-- edit the buffer if it was a temp one
if item.fixed == true then
vim.cmd "e"
item.fixed = nil
end
end
end

-- TODO: nvim_open_window
function View:preview()
local item = self:current_item()
if not item then return end

if item.is_file ~= true then
vim.api.nvim_win_set_buf(self.parent, item.bufnr)
vim.api.nvim_win_set_cursor(self.parent,
{item.start.line, item.start.character})
{item.start.line + 1, item.start.character})
-- center the buffer vertically
vim.api.nvim_buf_call(item.bufnr, function() vim.cmd "norm! zz" end)

-- check if this is a temp buffer created by lsp diag
-- if so, then trigger BufRead to fix syntax etc
if item.fixed ~= true and buf_opt(item.bufnr, "buflisted") == false then
vim.api.nvim_buf_call(item.bufnr,
function() vim.cmd "do BufRead" end)
item.fixed = true
end

clear_hl(item.bufnr)
buffersHl[item.bufnr] = true
for row = item.start.line, item.finish.line, 1 do
Expand Down

0 comments on commit 91d1139

Please sign in to comment.