neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit ac207c3ac20026baa2a4561f5365c2af6a38a357
parent 24d7debdfb779bbc4efcd911b9d49dffe4822c2b
Author: Siddhant Agarwal <68201519+siddhantdev@users.noreply.github.com>
Date:   Mon, 10 Feb 2025 01:02:12 +0530

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.
Diffstat:
Mruntime/doc/news.txt | 2++
Mruntime/lua/vim/_defaults.lua | 22+++++++++++++++++++++-
2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt @@ -221,6 +221,8 @@ DEFAULTS on a URL. • Mouse |popup-menu| includes a "Go to definition" item when LSP is active 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| jump to the first and last diagnostic in the current buffer, respectively. diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua @@ -383,9 +383,12 @@ end do --- Right click popup menu vim.cmd([[ - anoremenu PopUp.Go\ to\ definition <Cmd>lua vim.lsp.buf.definition()<CR> amenu PopUp.Open\ in\ web\ browser gx 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> vnoremenu PopUp.Cut "+x vnoremenu PopUp.Copy "+y @@ -403,6 +406,9 @@ do vim.cmd([[ amenu disable PopUp.Go\ to\ definition 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 @@ -410,6 +416,20 @@ do elseif ctx == 'lsp' then vim.cmd([[anoremenu enable PopUp.Go\ to\ definition]]) 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 local nvim_popupmenu_augroup = vim.api.nvim_create_augroup('nvim.popupmenu', {})