diff options
author | Siddhant Agarwal <68201519+siddhantdev@users.noreply.github.com> | 2025-02-10 01:02:12 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-09 11:32:12 -0800 |
commit | ac207c3ac20026baa2a4561f5365c2af6a38a357 (patch) | |
tree | 9401be081587064e227d4646bcc84197a6800617 | |
parent | 24d7debdfb779bbc4efcd911b9d49dffe4822c2b (diff) | |
download | rneovim-ac207c3ac20026baa2a4561f5365c2af6a38a357.tar.gz rneovim-ac207c3ac20026baa2a4561f5365c2af6a38a357.tar.bz2 rneovim-ac207c3ac20026baa2a4561f5365c2af6a38a357.zip |
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.
-rw-r--r-- | runtime/doc/news.txt | 2 | ||||
-rw-r--r-- | runtime/lua/vim/_defaults.lua | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index bfa98dce05..1f1ad84a02 100644 --- 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 index 69204e3fe6..b1e5687d74 100644 --- 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', {}) |