Skip to content

Commit

Permalink
feat: added "hover" action that defaults to "K" to show the full mult…
Browse files Browse the repository at this point in the history
…iline text #11
  • Loading branch information
folke committed May 2, 2021
1 parent 571ef5f commit 9111a5e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -79,6 +79,7 @@ Trouble comes with the following defaults:
refresh = "r", -- manually refresh
jump = {"<cr>", "<tab>"}, -- jump to the diagnostic or open / close folds
jump_close = {"o"}, -- jump to the diagnostic and close the list
hover = "K", -- opens a small poup with the full multiline message
toggle_mode = "m", -- toggle between "workspace" and "document" mode
toggle_preview = "P", -- toggle auto_preview
preview = "p", -- preview the diagnostic location
Expand Down
1 change: 1 addition & 0 deletions lua/trouble/config.lua
Expand Up @@ -17,6 +17,7 @@ local defaults = {
jump_close = {"o"}, -- jump to the diagnostic and close the list
toggle_mode = "m", -- toggle between "workspace" and "document" mode
toggle_preview = "P", -- toggle auto_preview
hover = "K", -- opens a small poup with the full multiline message
preview = "p", -- preview the diagnostic location
close_folds = {"zM", "zm"}, -- close all folds
open_folds = {"zR", "zr"}, -- open all folds
Expand Down
1 change: 1 addition & 0 deletions lua/trouble/init.lua
Expand Up @@ -86,6 +86,7 @@ function Trouble.action(action)

if view and action == "on_win_enter" then view:on_win_enter() end
if not is_open() then return end
if action == "hover" then view:hover() end
if action == "jump" then view:jump() end
if action == "jump_close" then
view:jump()
Expand Down
1 change: 1 addition & 0 deletions lua/trouble/lsp.lua
Expand Up @@ -31,6 +31,7 @@ local function preprocess_diag(diag, bufnr)
finish = finish,
-- remove line break to avoid display issues
text = vim.trim(diag.message:gsub("[\n]", "")),
full_text = vim.trim(diag.message),
type = lsp_type_diagnostic[diag.severity] or lsp_type_diagnostic[1],
code = diag.code,
source = diag.source,
Expand Down
13 changes: 13 additions & 0 deletions lua/trouble/view.lua
Expand Up @@ -281,6 +281,19 @@ function View:previous_item()
end
end

function View:hover(opts)
opts = opts or {}
local item = opts.item or self:current_item()
if not (item and item.full_text) then return end

local lines = {}
for line in item.full_text:gmatch("([^\n]*)\n?") do
table.insert(lines, line)
end

vim.lsp.util.open_floating_preview(lines, "plaintext", {border = "single"})
end

function View:jump(opts)
opts = opts or {}
local item = opts.item or self:current_item()
Expand Down

0 comments on commit 9111a5e

Please sign in to comment.