From 5977281eeac0ba0187a1eae5d17c104282c08e7f Mon Sep 17 00:00:00 2001 From: spike Date: Sat, 5 Nov 2022 19:46:15 +0100 Subject: [PATCH] toggle diagnostics severity --- after/plugin/diagnostics.lua | 1 + after/plugin/grapple.lua | 6 +++ init.lua | 2 +- lua/core/mappings.lua | 50 +++++++++++++++----- lua/custom/chadrc.lua | 4 ++ lua/custom/init.lua | 3 +- lua/custom/plugins/configs/navigator.lua | 4 +- lua/custom/plugins/configs/plantuml.lua | 2 +- lua/custom/plugins/init.lua | 27 ++++++++++- lua/spike/diagnostics.lua | 58 +++++++++++++++++++++--- lua/spike/{utils.lua => utils/init.lua} | 0 mysnippets/lua.lua | 5 -- 12 files changed, 130 insertions(+), 32 deletions(-) create mode 100644 after/plugin/diagnostics.lua create mode 100644 after/plugin/grapple.lua rename lua/spike/{utils.lua => utils/init.lua} (100%) diff --git a/after/plugin/diagnostics.lua b/after/plugin/diagnostics.lua new file mode 100644 index 0000000..b1ccf64 --- /dev/null +++ b/after/plugin/diagnostics.lua @@ -0,0 +1 @@ +require 'spike.diagnostics'.set_diagnostics_level(vim.diagnostic.severity.WARN) diff --git a/after/plugin/grapple.lua b/after/plugin/grapple.lua new file mode 100644 index 0000000..bbdd963 --- /dev/null +++ b/after/plugin/grapple.lua @@ -0,0 +1,6 @@ +local ok, grapple = pcall(require, "grapple") +if not ok then + vim.notify("missing module grapple", vim.log.levels.WARN) + return +end + diff --git a/init.lua b/init.lua index 46cb33d..26fbc3d 100644 --- a/init.lua +++ b/init.lua @@ -26,5 +26,5 @@ end -- pcall(require, "custom") -local vimscriptsfolder = vim.env.XDG_CONFIG_HOME .. "/nvim/myvimscript" -- relative to .config/nvim dir +local vimscriptsfolder = vim.env["XDG_CONFIG_HOME"] .. "/nvim/myvimscript" -- relative to .config/nvim dir vim.opt.runtimepath:prepend(vimscriptsfolder) diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index ca5dc6b..48e23b8 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -90,6 +90,10 @@ M.general = { --{{{ ["d"] = { "DelayTrainToggle", "disable delay train" }, + ["dge"] = { " lua require'spike.diagnostics'.set_diagnostics_level(1)", "diagnostic severity level error"}, + ["dgw"] = { " lua require'spike.diagnostics'.set_diagnostics_level(2)", "diagnostic severity level warning"}, + ["dgi"] = { " lua require'spike.diagnostics'.set_diagnostics_level(3)", "diagnostic severity level info"}, + ["dgh"] = { " lua require'spike.diagnostics'.set_diagnostics_level(4)", "diagnostic severity level hint"}, -- update nvchad -- ["uu"] = { " :NvChadUpdate ", "update nvchad" }, @@ -369,7 +373,12 @@ M.general = { --{{{ -- operator pending o = { - ["S"] = {"(leap-forward-to)"}, + ["S"] = { "(leap-forward-to)" }, + }, + + -- select mode (with completion) + s = { + [""] = {"i"}, -- delete and go to insert mode }, -- visual exclusive mode (ignore select) @@ -391,10 +400,10 @@ M.general = { --{{{ ["L"] = { "STSSelectChildNode", "select prev sibling node" }, -- swap nodes tip: start first with master/child node selection then use these - [""] = { "STSSwapPrevVisual", "select prev sibling node" }, - [""] = { "STSSwapPrevVisual", "select prev sibling node" }, - [""] = { "STSSwapNextVisual", "select next sibling node" }, - [""] = { "STSSwapNextVisual", "select next sibling node" }, + [""] = { "STSSwapPrevVisual", "swap prev sibling node" }, + [""] = { "STSSwapPrevVisual", "swap prev sibling node" }, + [""] = { "STSSwapNextVisual", "swap next sibling node" }, + [""] = { "STSSwapNextVisual", "swap next sibling node" }, }, -- }}} } --}}} @@ -926,8 +935,8 @@ M.golang = { M["todo-comments"] = { plugin = true, n = { - ["]t"] = {" lua require'todo-comments'.jump_next()", "jump to next todo"}, - ["[t"] = {" lua require'todo-comments'.jump_prev()", "jump to prev todo"} + ["]t"] = { " lua require'todo-comments'.jump_next()", "jump to next todo" }, + ["[t"] = { " lua require'todo-comments'.jump_prev()", "jump to prev todo" } } } @@ -942,21 +951,38 @@ M.gitsigns = { "Git stage buffer", }, ["gR"] = { " lua require'gitsigns'.reset_buffer_index()", - "Git stage buffer", + "Git reset buffer index", }, ["gp"] = { " lua require'gitsigns'.preview_hunk()", - "Git stage buffer", + "Git preview hunk", }, - ["gu"] = {" lua require'gitsigns'.undo_stage_hunk()", + ["gu"] = { " lua require'gitsigns'.undo_stage_hunk()", "Git undo stage hunk", }, - ["]h"] = { " lua require'gitsigns'.next_hunk()", + ["]h"] = { " lua require'gitsigns'.next_hunk()", "Git next hunk", }, - ["[h"] = { " lua require'gitsigns'.prev_hunk()", + ["[h"] = { " lua require'gitsigns'.prev_hunk()", "Git prev hunk", } } } +M.grapple = { + plugin = true, + n = { + [",J"] = { " lua require'grapple'.cycle_forward()" }, + [",K"] = { " lua require'grapple'.cycle_backward()" }, + [",T"] = { " GrappleTag"}, + [",N"] = { function() + vim.ui.input({ prompt = "tag: " }, function(input) + require("grapple").tag({ name = input }) + end) + end, "grapple tag with name" }, + [",,m"] = { " lua require'grapple'.select({name='mappings'})" }, + [",,p"] = { " lua require'grapple'.select({name='plugins'})" }, + [",,P"] = { " lua require'grapple'.select({name='Plugins'})" }, + } +} + return M diff --git a/lua/custom/chadrc.lua b/lua/custom/chadrc.lua index fa3fffb..3a5a094 100644 --- a/lua/custom/chadrc.lua +++ b/lua/custom/chadrc.lua @@ -17,6 +17,10 @@ M.ui = { theme = "gruvbox_material", theme_toggle = { "gruvbox_material", "gruvbox_light" }, hl_override = { + IndentBlanklineContextChar = { + fg = "yellow", + nocombine = true, + }, Comment = { fg = "light_grey" }, diff --git a/lua/custom/init.lua b/lua/custom/init.lua index 2abc5b2..459c2bd 100644 --- a/lua/custom/init.lua +++ b/lua/custom/init.lua @@ -9,8 +9,7 @@ -- if character under cursor is number -- use normal C-x or close window --- local vimscriptsfolder = vim.env.XDG_CONFIG_HOME .. "/nvim/myvimscript" -- relative to .config/nvim dir --- vim.opt.runtimepath:prepend(vimscriptsfolder) +-- -- highlights { diff --git a/lua/custom/plugins/configs/navigator.lua b/lua/custom/plugins/configs/navigator.lua index 53b28e8..87a1c81 100644 --- a/lua/custom/plugins/configs/navigator.lua +++ b/lua/custom/plugins/configs/navigator.lua @@ -48,7 +48,7 @@ local config = { { key = 'D', func = vim.lsp.buf.type_definition, desc = 'lsp type_definition' }, { key = 'gL', func = require('navigator.diagnostics').show_diagnostics, desc = 'lsp show_diagnostics' }, { key = 'gG', func = require('navigator.diagnostics').show_buf_diagnostics, desc = 'lsp show_buf_diagnostics' }, - -- { key = 'dt', func = require('navigator.diagnostics').toggle_diagnostics, desc = 'lsp toggle_diagnostics' }, + { key = 'dt', func = require('navigator.diagnostics').toggle_diagnostics, desc = 'lsp toggle_diagnostics' }, { key = 'td', func = require('spike.diagnostics').toggle, desc = 'lsp toggle_diagnostics' }, { key = ']d', func = vim.diagnostic.goto_next, desc = 'lsp next diagnostics' }, { key = '[d', func = vim.diagnostic.goto_prev, desc = 'lsp prev diagnostics' }, @@ -140,7 +140,7 @@ local config = { source = true }, -- show virtual for diagnostic message update_in_insert = false, -- update diagnostic message in insert mode - severity_sort = { reverse = true }, + severity_sort = { reverse = false }, }, diagnostic_scrollbar_sign = false, diff --git a/lua/custom/plugins/configs/plantuml.lua b/lua/custom/plugins/configs/plantuml.lua index c5daacc..0610eb9 100644 --- a/lua/custom/plugins/configs/plantuml.lua +++ b/lua/custom/plugins/configs/plantuml.lua @@ -17,11 +17,11 @@ M.lazy_load_module = function() vim.defer_fn(function() require("packer").loader("plantuml-syntax") end,0) + return end end firstline = vim.api.nvim_buf_get_lines(0,0,1,true)[1] - P(firstline) if firestline ~= "" and firstline:match("^@startuml%s*") then vim.defer_fn(function() require("packer").loader("plantuml-syntax") diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index 14394ed..5e672c0 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -300,6 +300,20 @@ return { end }, -- }}} + ["cbochs/grapple.nvim"] = { + setup = function() + require("core.utils").load_mappings "grapple" + end, + config = function() + require("grapple").setup({ + -- Your configuration goes here + -- Leave empty to use the default configuration + -- Please see the Configuration section below for more information + save_path = vim.fn.stdpath("data") .. "/" .. "grapple.json", + + }) + end + }, -- tmux helpers ["christoomey/vim-tmux-navigator"] = { cond = function() @@ -416,6 +430,8 @@ return { "mason", "guihua*", "terminal*", + "db*", + "aerial*", }, }) end @@ -646,12 +662,19 @@ return { ft = {"plantuml"}, }, ["scrooloose/vim-slumlord"] = { - ft = {"plantuml"}, - } + opt = true, + -- ft = {"plantuml"}, + }, -- sql tools -- https://github.com/tpope/vim-dadbod -- https://github.com/kristijanhusak/vim-dadbod-ui + ["tpope/vim-dadbod"] = { + ft = "sql", + }, + ["kristijanhusak/vim-dadbod-ui"] = { + after = {"vim-dadbod"}, + } } diff --git a/lua/spike/diagnostics.lua b/lua/spike/diagnostics.lua index 7338764..a5200aa 100644 --- a/lua/spike/diagnostics.lua +++ b/lua/spike/diagnostics.lua @@ -2,13 +2,15 @@ M = {} M.shown = true -- toggle diagnostics with show/hide -M.toggle = function () - if M.shown then - M.shown = false - return vim.diagnostic.hide() - end - M.shown = true - vim.diagnostic.show() +M.toggle = function() + if M.shown then + M.shown = false + return vim.diagnostic.hide() + end + + + M.shown = true + vim.diagnostic.show() end -- my customized attach @@ -16,4 +18,46 @@ end -- end +-- return M +-- +local orig_diag_virt_handler = vim.diagnostic.handlers.virtual_text +local ns = vim.api.nvim_create_namespace("my_diagnostics") + +local filter_diagnostics = function(diagnostics, level) + local filtered_diag = {} + for _, d in ipairs(diagnostics) do + if d.severity <= level then + table.insert(filtered_diag, 0, d) + end + end + return filtered_diag +end + +--NOTE: apply diagnostics filter to current buffer / all buffers +M.set_diagnostics_level = function(level) + -- hide all diagnostics + vim.diagnostic.hide(nil, 0) + + -- vim.diagnostic.reset() + vim.diagnostic.handlers.virtual_text = { + show = function(_, bufnr, _, opts) + -- get all diagnostics for local buffer + local diagnostics = vim.diagnostic.get(bufnr) + filtered = filter_diagnostics(diagnostics, level) + -- filter diags based on severity + orig_diag_virt_handler.show(ns, bufnr, filtered, opts) + end, + hide = function(_, bufnr) + orig_diag_virt_handler.hide(ns, bufnr) + end + } + + local diags = vim.diagnostic.get(0) + if #diags > 0 then + filtered = filter_diagnostics(diags, level) + vim.diagnostic.show(ns, 0, filtered) + end + +end + return M diff --git a/lua/spike/utils.lua b/lua/spike/utils/init.lua similarity index 100% rename from lua/spike/utils.lua rename to lua/spike/utils/init.lua diff --git a/mysnippets/lua.lua b/mysnippets/lua.lua index fdceb45..b237e57 100644 --- a/mysnippets/lua.lua +++ b/mysnippets/lua.lua @@ -1,11 +1,6 @@ ---@diagnostic disable: undefined-global return { - - s("testluasnip", { - t"Hello lua snippet" - }), - s({ trig = "lm", dscr = "local lua module"}, fmt([[ local M = {{}}