From 0712e89f57ae108db0ff40892d6124814c874f37 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Fri, 2 May 2025 19:52:17 +0300 Subject: Refactored extra code into autocmds, user commands and extra --- .config/nvim/lua/extra.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .config/nvim/lua/extra.lua (limited to '.config/nvim/lua/extra.lua') 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 -- cgit v1.3.1