diff options
| author | Kyren223 <Kyren223@proton.me> | 2025-05-02 19:52:17 +0300 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2025-05-02 19:52:17 +0300 |
| commit | 0712e89f57ae108db0ff40892d6124814c874f37 (patch) | |
| tree | af0c5f1ebce9d9c564d5e24fd81b56e57803df3f /.config/nvim/lua/extra.lua | |
| parent | 41252961ed8c64c668c7285fad0cb44265c9e00e (diff) | |
Refactored extra code into autocmds, user commands and extra
Diffstat (limited to '.config/nvim/lua/extra.lua')
| -rw-r--r-- | .config/nvim/lua/extra.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/.config/nvim/lua/extra.lua b/.config/nvim/lua/extra.lua new file mode 100644 index 0000000..00d2b7c --- /dev/null +++ b/.config/nvim/lua/extra.lua @@ -0,0 +1,37 @@ +-- show unused zig variables as "DiagnosticUnnecessary" instead of error +local orig_underline_show = vim.diagnostic.handlers.underline.show +local custom_ns = vim.api.nvim_create_namespace('custom_unused_ns') + +vim.diagnostic.handlers.underline.show = function(namespace, bufnr, diagnostics, opts) + local normal_diags = {} + local custom_diags = {} + for _, diag in ipairs(diagnostics) do + if diag.message:find('unused', 1, true) then + table.insert(custom_diags, diag) + else + table.insert(normal_diags, diag) + end + end + if #normal_diags > 0 and orig_underline_show ~= nil then + orig_underline_show(namespace, bufnr, normal_diags, opts) + end + for _, diag in ipairs(custom_diags) do + vim.highlight.range( + bufnr, + custom_ns, + 'DiagnosticUnnecessary', + { diag.lnum, diag.col }, + { diag.end_lnum, diag.end_col }, + { inclusive = false } + ) + end +end + +local orig_underline_hide = vim.diagnostic.handlers.underline.hide + +vim.diagnostic.handlers.underline.hide = function(namespace, bufnr) + if orig_underline_hide ~= nil then + orig_underline_hide(namespace, bufnr) + end + vim.api.nvim_buf_clear_namespace(bufnr, custom_ns, 0, -1) +end |
