Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lua/lspsaga/command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ local subcommands = {
hover_doc = function(args)
require('lspsaga.hover'):render_hover_doc(args)
end,
show_diagnostics = function(args)
require('lspsaga.diagnostic.show'):show_diagnostics({ fallback = true, args = args })
end,
show_workspace_diagnostics = function(args)
require('lspsaga.diagnostic.show'):show_diagnostics({ workspace = true, args = args })
end,
Expand Down
20 changes: 19 additions & 1 deletion lua/lspsaga/diagnostic/show.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,31 @@ function sd:show(opt)
end)
end

local function get_diagnostic_entrys(opt)
if opt.fallback then
local scopes = { 'cursor', 'line', 'buffer' }
for _, scope in ipairs(scopes) do
local result = diag:get_diagnostic({ [scope] = true })
if #result > 0 then
opt[scope] = true -- not sure if it's a good idea to modify the opt table here
return result
end
end

return diag:get_diagnostic({})
else
return diag:get_diagnostic(opt)
end
end

function sd:show_diagnostics(opt)
local has_jump_win = require('lspsaga.diagnostic').winid
if has_jump_win and api.nvim_win_is_valid(has_jump_win) then
return
end

local entrys = diag:get_diagnostic(opt)
local entrys = get_diagnostic_entrys(opt)

if next(entrys) == nil then
return
end
Expand Down