From 9e58b1629df6ca3ac79149471cdbe75f4d0ee0b0 Mon Sep 17 00:00:00 2001 From: jiriks74 Date: Tue, 1 Oct 2024 12:55:40 +0200 Subject: [PATCH] feat(plugins): Add `workspace-diagnostics.nvim` and `trouble.nvim` Fix `nvim-navic` for some LSPs --- flake.lock | 19 +++++++++++- flake.nix | 4 +++ nix/neovim-overlay.nix | 2 ++ nvim/ftplugin/asm.lua | 4 +++ nvim/ftplugin/c.lua | 31 ++++++++++--------- nvim/ftplugin/lua.lua | 4 +++ nvim/ftplugin/nix.lua | 4 +++ nvim/ftplugin/sh.lua | 29 +++--------------- nvim/plugin/aerial.lua | 2 +- nvim/plugin/keymaps.lua | 67 ++++++++++++++++++++++++++--------------- nvim/plugin/plugins.lua | 1 + 11 files changed, 101 insertions(+), 66 deletions(-) diff --git a/flake.lock b/flake.lock index 80b6516..68ab240 100644 --- a/flake.lock +++ b/flake.lock @@ -216,7 +216,8 @@ "flake-utils": "flake-utils", "gen-luarc": "gen-luarc", "nixpkgs": "nixpkgs_2", - "presence-nvim": "presence-nvim" + "presence-nvim": "presence-nvim", + "workspace-diagnostics-nvim": "workspace-diagnostics-nvim" } }, "systems": { @@ -233,6 +234,22 @@ "repo": "default", "type": "github" } + }, + "workspace-diagnostics-nvim": { + "flake": false, + "locked": { + "lastModified": 1723294887, + "narHash": "sha256-lBj4KUPmmhtpffYky/HpaTwY++d/Q9socp/Ys+4VeX0=", + "owner": "artemave", + "repo": "workspace-diagnostics.nvim", + "rev": "573ff93c47898967efdfbc6587a1a39e3c2d365e", + "type": "github" + }, + "original": { + "owner": "artemave", + "repo": "workspace-diagnostics.nvim", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 7d9420f..11fe841 100644 --- a/flake.nix +++ b/flake.nix @@ -12,6 +12,10 @@ url = "github:jiriks74/presence.nvim"; flake = false; }; + workspace-diagnostics-nvim = { + url = "github:artemave/workspace-diagnostics.nvim"; + flake = false; + }; # wf-nvim = { # url = "github:Cassin01/wf.nvim"; # flake = false; diff --git a/nix/neovim-overlay.nix b/nix/neovim-overlay.nix index ce0dcce..a2acd70 100644 --- a/nix/neovim-overlay.nix +++ b/nix/neovim-overlay.nix @@ -99,6 +99,7 @@ with final.pkgs.lib; let nvim-unception # Prevent nested neovim sessions | nvim-unception better-escape-nvim # Map keys without delay when typing | https://github.com/max397574/better-escape.nvim toggleterm-nvim # A neovim lua plugin to help easily manage multiple terminal windows | https://github.com/akinsho/toggleterm.nvim?tab=readme-ov-file + trouble-nvim # A pretty diagnostics list | https://github.com/folke/trouble.nvim # ^ Useful utilities # libraries that other plugins depend on @@ -112,6 +113,7 @@ with final.pkgs.lib; let # bleeding-edge plugins from flake inputs (mkNvimPlugin inputs.presence-nvim "presence.nvim") + (mkNvimPlugin inputs.workspace-diagnostics-nvim "workspace-diagnostics.nvim") # (mkNvimPlugin inputs.wf-nvim "wf.nvim") # (example) keymap hints | https://github.com/Cassin01/wf.nvim # ^ bleeding-edge plugins from flake inputs ]; diff --git a/nvim/ftplugin/asm.lua b/nvim/ftplugin/asm.lua index 17ceae7..3864aa0 100644 --- a/nvim/ftplugin/asm.lua +++ b/nvim/ftplugin/asm.lua @@ -16,5 +16,9 @@ vim.lsp.start { cmd = { 'asm-lsp' }, root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]), capabilities = require('user.lsp').make_client_capabilities(), + on_attach = function(client, bufnr) + require("nvim-navic").attach(client, bufnr) + require("workspace-diagnostics").populate_workspace_diagnostics(client, bufnr) + end, -- capabilities = { offsetEncoding = "utf-8" }, } diff --git a/nvim/ftplugin/c.lua b/nvim/ftplugin/c.lua index 668ae14..934bfe5 100644 --- a/nvim/ftplugin/c.lua +++ b/nvim/ftplugin/c.lua @@ -17,8 +17,9 @@ vim.lsp.start { root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]), capabilities = require('user.lsp').make_client_capabilities(), on_attach = function(client, bufnr) - require("nvim-navic").attach(client, bufnr) - end + require("nvim-navic").attach(client, bufnr) + require("workspace-diagnostics").populate_workspace_diagnostics(client, bufnr) + end } local dap = require("dap") @@ -59,19 +60,19 @@ if vim.fn.executable('OpenDebugAD7') == 1 then return coroutine.create(function(coro) local opts = {} pickers - .new(opts, { - prompt_title = "Path to executable", - finder = finders.new_oneshot_job({ "fd", "--hidden", "--no-ignore", "--type", "x" }, {}), - sorter = conf.generic_sorter(opts), - attach_mappings = function(buffer_number) - actions.select_default:replace(function() - actions.close(buffer_number) - coroutine.resume(coro, action_state.get_selected_entry()[1]) - end) - return true - end, - }) - :find() + .new(opts, { + prompt_title = "Path to executable", + finder = finders.new_oneshot_job({ "fd", "--hidden", "--no-ignore", "--type", "x" }, {}), + sorter = conf.generic_sorter(opts), + attach_mappings = function(buffer_number) + actions.select_default:replace(function() + actions.close(buffer_number) + coroutine.resume(coro, action_state.get_selected_entry()[1]) + end) + return true + end, + }) + :find() end) end, stopAtBeginningOfMainSubprogram = true, diff --git a/nvim/ftplugin/lua.lua b/nvim/ftplugin/lua.lua index caec13e..54917a7 100644 --- a/nvim/ftplugin/lua.lua +++ b/nvim/ftplugin/lua.lua @@ -25,6 +25,10 @@ vim.lsp.start { cmd = { lua_ls_cmd }, root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]), capabilities = require('user.lsp').make_client_capabilities(), + on_attach = function(client, bufnr) + require("workspace-diagnostics").populate_workspace_diagnostics(client, bufnr) + require("nvim-navic").attach(client, bufnr) + end, settings = { Lua = { runtime = { diff --git a/nvim/ftplugin/nix.lua b/nvim/ftplugin/nix.lua index 8691e2a..cc8d728 100644 --- a/nvim/ftplugin/nix.lua +++ b/nvim/ftplugin/nix.lua @@ -15,4 +15,8 @@ vim.lsp.start { cmd = { 'nil' }, root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]), capabilities = require('user.lsp').make_client_capabilities(), + on_attach = function(client, bufnr) + require("nvim-navic").attach(client, bufnr) + require("workspace-diagnostics").populate_workspace_diagnostics(client, bufnr) + end, } diff --git a/nvim/ftplugin/sh.lua b/nvim/ftplugin/sh.lua index 8c5c068..20541b2 100644 --- a/nvim/ftplugin/sh.lua +++ b/nvim/ftplugin/sh.lua @@ -15,29 +15,8 @@ vim.lsp.start { root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]), -- capabilities = require('user.lsp').make_client_capabilities(), single_file_support = true, + on_attach = function(client, bufnr) + require("nvim-navic").attach(client, bufnr) + require("workspace-diagnostics").populate_workspace_diagnostics(client, bufnr) + end, } - --- local dap = require("dap") --- --- if require('user.file_exists').file_exists(vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]) .. "/.vscode/launch.json") then --- require("dap.ext.vscode").load_launchjs(nil, { cppdbg = { "c", "cpp", "asm" } }) --- end --- --- dap.adapters.gdb = { --- type = "executable", --- command = "gdb", --- args = { "-i", "dap" } --- } --- --- dap.configurations.c = { --- { --- name = "Launch", --- type = "gdb", --- request = "launch", --- program = function() --- return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') --- end, --- cwd = "${workspaceFolder}", --- stopAtBeginningOfMainSubprogram = false, --- }, --- } diff --git a/nvim/plugin/aerial.lua b/nvim/plugin/aerial.lua index d0d4627..72e1428 100644 --- a/nvim/plugin/aerial.lua +++ b/nvim/plugin/aerial.lua @@ -12,6 +12,6 @@ require("aerial").setup({ -- end, }) -- You probably also want to set a keymap to toggle aerial -vim.keymap.set("n", "a", "AerialToggle!") +vim.keymap.set("n", "a", "AerialToggle! right") diff --git a/nvim/plugin/keymaps.lua b/nvim/plugin/keymaps.lua index de14642..adf8037 100644 --- a/nvim/plugin/keymaps.lua +++ b/nvim/plugin/keymaps.lua @@ -13,34 +13,53 @@ keymap.set('n', 'Y', 'y$', { silent = true, desc = '[Y]ank to end of line' }) require('which-key').add({ -- Buffer list navigation, ordering, ... - { "", "BufferLineTogglePin", desc = '[p]in buffer' }, - { "gB", "BufferLinePick", desc = '[g]o to [b]uffer' }, - { '>b', "BufferLineMoveNext", desc = 'move [b]uffer right' }, - { 'BufferLineMovePrev", desc = 'move [b]uffer left' }, - { '[b', "BufferLineCyclePrev", desc = 'previous [b]uffer' }, - { ']b', "BufferLineCycleNext", desc = 'next [b]uffer' }, - { '[B', vim.cmd.bfirst, desc = 'first [B]uffer' }, - { ']B', vim.cmd.blast, desc = 'last [B]uffer' }, - { 'tn', vim.cmd.tabnew, desc = '[t]ab: [n]ew' }, - { 'tq', "bd", desc = '[t]ab: [q]uit/close' }, - { 'c', "bd", desc = '[c]lose tab' }, + { "", "BufferLineTogglePin", desc = '[p]in buffer' }, + { "gB", "BufferLinePick", desc = '[g]o to [b]uffer' }, + { '>b', "BufferLineMoveNext", desc = 'move [b]uffer right' }, + { 'BufferLineMovePrev", desc = 'move [b]uffer left' }, + { '[b', "BufferLineCyclePrev", desc = 'previous [b]uffer' }, + { ']b', "BufferLineCycleNext", desc = 'next [b]uffer' }, + { '[B', vim.cmd.bfirst, desc = 'first [B]uffer' }, + { ']B', vim.cmd.blast, desc = 'last [B]uffer' }, + { 'tn', vim.cmd.tabnew, desc = '[t]ab: [n]ew' }, + { 'tq', "bd", desc = '[t]ab: [q]uit/close' }, + { 'c', "bd", desc = '[c]lose tab' }, -- Window resizing - { "", "resize -2", desc = "resize split up" }, - { "", "resize +2", desc = "resize split down" }, - { "", "vertical resize +2", desc = "resize split left" }, - { "", "vertical resize -2", desc = "resize split right" }, + { "", "resize -2", desc = "resize split up" }, + { "", "resize +2", desc = "resize split down" }, + { "", "vertical resize +2", desc = "resize split left" }, + { "", "vertical resize -2", desc = "resize split right" }, -- ToggleTerm - { "Tf", "ToggleTerm direction=float", desc = "[T]oggleterm [f]loat" }, - { "Th", "ToggleTerm size=10 direction=horizontal", desc = "[T]oggleterm [h]orizontal split" }, - { "Tv", "ToggleTerm size=80 direction=vertical", desc = "[T]oggleterm [v]ertical split" }, - { "", 'execute v:count . "ToggleTerm"', desc = "Toggle terminal" }, - { mode = "t", "", "ToggleTerm", desc = "Toggle terminal" }, - { mode = "i", "", "ToggleTerm", desc = "Toggle terminal" }, - { "", 'execute v:count . "ToggleTerm"', desc = "Toggle terminal" }, -- requires terminal that supports binding - { "", "ToggleTerm", desc = "Toggle terminal" }, -- requires terminal that supports binding - { "", "ToggleTerm", desc = "Toggle terminal" }, -- requires terminal that supports binding ` + { "Tf", "ToggleTerm direction=float", desc = "[T]oggleterm [f]loat" }, + { "Th", "ToggleTerm size=10 direction=horizontal", desc = "[T]oggleterm [h]orizontal split" }, + { "Tv", "ToggleTerm size=80 direction=vertical", desc = "[T]oggleterm [v]ertical split" }, + { "", 'execute v:count . "ToggleTerm"', desc = "Toggle terminal" }, + { mode = "t", "", "ToggleTerm", desc = "Toggle terminal" }, + { mode = "i", "", "ToggleTerm", desc = "Toggle terminal" }, + { "", 'execute v:count . "ToggleTerm"', desc = "Toggle terminal" }, -- requires terminal that supports binding + { "", "ToggleTerm", desc = "Toggle terminal" }, -- requires terminal that supports binding + { "", "ToggleTerm", desc = "Toggle terminal" }, -- requires terminal that supports binding ` + + -- Trouble + { "x", group = "trouble" }, + { "xt", "Trouble diagnostics toggle", desc = "trouble: [t]oggle", }, + { "xX", "Trouble diagnostics toggle filter.buf=0", desc = "trouble: [b]uffer diagnostics", }, + { "xs", "Trouble symbols toggle focus=false", desc = "trouble: [s]ymbols (Trouble)", }, + { "xl", "Trouble lsp toggle focus=false win.position=right", desc = "trouble: [l]sp definitions / references / ...", }, + { "xL", "Trouble loclist toggle", desc = "trouble: [L]ocation list", }, + { "xQ", "Trouble qflist toggle", desc = "trouble: [q]uickfix list", }, + { + "xw", + noremap = true, + callback = function() + for _, client in ipairs(vim.lsp.buf_get_clients()) do + require("workspace-diagnostics").populate_workspace_diagnostics(client, 0) + end + end, + desc = "trouble: load [w]orkspace" + }, }) -- Toggle the quickfix list (only opens if it is populated) diff --git a/nvim/plugin/plugins.lua b/nvim/plugin/plugins.lua index 5731835..71ec690 100644 --- a/nvim/plugin/plugins.lua +++ b/nvim/plugin/plugins.lua @@ -16,3 +16,4 @@ require("better_escape").setup() require("todo-comments").setup() require("bufferline").setup{} require("toggleterm").setup() +require("trouble").setup()