feat(defaults): "Show Diagnostics" in mouse popupmenu #32122

Problem:
No obvious way to see diagnostics without configuring it first.
Solution:
Add `Show Diagnostics`, `Show All Diagnostics` and `Configure
Diagnostics` buttons to the context menu.
This commit is contained in:
Siddhant Agarwal
2025-02-10 01:02:12 +05:30
committed by GitHub
parent 24d7debdfb
commit ac207c3ac2
2 changed files with 23 additions and 1 deletions

View File

@@ -221,6 +221,8 @@ DEFAULTS
on a URL. on a URL.
• Mouse |popup-menu| includes a "Go to definition" item when LSP is active • Mouse |popup-menu| includes a "Go to definition" item when LSP is active
in the buffer. in the buffer.
• Mouse |popup-menu| includes "Show Diagnostics", "Show All Diagnostics" and
"Configure Diagnostics" items when there are diagnostics in the buffer.
• |]d-default| and |[d-default| accept a count. • |]d-default| and |[d-default| accept a count.
• |[D-default| and |]D-default| jump to the first and last diagnostic in the • |[D-default| and |]D-default| jump to the first and last diagnostic in the
current buffer, respectively. current buffer, respectively.

View File

@@ -383,9 +383,12 @@ end
do do
--- Right click popup menu --- Right click popup menu
vim.cmd([[ vim.cmd([[
anoremenu PopUp.Go\ to\ definition <Cmd>lua vim.lsp.buf.definition()<CR>
amenu PopUp.Open\ in\ web\ browser gx amenu PopUp.Open\ in\ web\ browser gx
anoremenu PopUp.Inspect <Cmd>Inspect<CR> anoremenu PopUp.Inspect <Cmd>Inspect<CR>
anoremenu PopUp.Go\ to\ definition <Cmd>lua vim.lsp.buf.definition()<CR>
anoremenu PopUp.Show\ Diagnostics <Cmd>lua vim.diagnostic.open_float()<CR>
anoremenu PopUp.Show\ All\ Diagnostics <Cmd>lua vim.diagnostic.setqflist()<CR>
anoremenu PopUp.Configure\ Diagnostics <Cmd>help vim.diagnostic.config()<CR>
anoremenu PopUp.-1- <Nop> anoremenu PopUp.-1- <Nop>
vnoremenu PopUp.Cut "+x vnoremenu PopUp.Cut "+x
vnoremenu PopUp.Copy "+y vnoremenu PopUp.Copy "+y
@@ -403,6 +406,9 @@ do
vim.cmd([[ vim.cmd([[
amenu disable PopUp.Go\ to\ definition amenu disable PopUp.Go\ to\ definition
amenu disable PopUp.Open\ in\ web\ browser amenu disable PopUp.Open\ in\ web\ browser
amenu disable PopUp.Show\ Diagnostics
amenu disable PopUp.Show\ All\ Diagnostics
amenu disable PopUp.Configure\ Diagnostics
]]) ]])
if ctx == 'url' then if ctx == 'url' then
@@ -410,6 +416,20 @@ do
elseif ctx == 'lsp' then elseif ctx == 'lsp' then
vim.cmd([[anoremenu enable PopUp.Go\ to\ definition]]) vim.cmd([[anoremenu enable PopUp.Go\ to\ definition]])
end end
local lnum = vim.fn.getcurpos()[2] - 1 ---@type integer
local diagnostic = false
if next(vim.diagnostic.get(0, { lnum = lnum })) ~= nil then
diagnostic = true
vim.cmd([[anoremenu enable PopUp.Show\ Diagnostics]])
end
if diagnostic or next(vim.diagnostic.count(0)) ~= nil then
vim.cmd([[
anoremenu enable PopUp.Show\ All\ Diagnostics
anoremenu enable PopUp.Configure\ Diagnostics
]])
end
end end
local nvim_popupmenu_augroup = vim.api.nvim_create_augroup('nvim.popupmenu', {}) local nvim_popupmenu_augroup = vim.api.nvim_create_augroup('nvim.popupmenu', {})