From 7f8edb90ad9dd8523de40435685cfc0c110c220f Mon Sep 17 00:00:00 2001 From: Fasamii Date: Sat, 7 Feb 2026 14:15:00 +0100 Subject: Theres no reliable way to get path of netrw file (scrapping the lsp integration completly) --- lua/netrw-icons/init.lua | 227 +++++++++++++++++++---------------------------- 1 file changed, 93 insertions(+), 134 deletions(-) (limited to 'lua/netrw-icons/init.lua') diff --git a/lua/netrw-icons/init.lua b/lua/netrw-icons/init.lua index b9bfe7e..9d7eec8 100644 --- a/lua/netrw-icons/init.lua +++ b/lua/netrw-icons/init.lua @@ -82,93 +82,61 @@ local function get_icon(node) return nil; end -local function get_lsp_diagnostics() - local all_diagnostics = vim.diagnostic.get(nil); - - local file_diagnostics_map = {}; - local dir_diagnostics_map = {}; - - for _, diag in ipairs(all_diagnostics) do - local diag_path = vim.api.nvim_buf_get_name(diag.bufnr); - diag_path = vim.fn.fnamemodify(diag_path, ":p"); - - if not file_diagnostics_map[diag_path] then - file_diagnostics_map[diag_path] = { info = 0, hint = 0, warn = 0, error = 0 }; - end - - if diag.severity == vim.diagnostic.severity.ERROR and M.options.lsp.error then - file_diagnostics_map[diag_path].error = file_diagnostics_map[diag_path].error + 1 - elseif diag.severity == vim.diagnostic.severity.WARN and M.options.lsp.warn then - file_diagnostics_map[diag_path].warn = file_diagnostics_map[diag_path].warn + 1 - elseif diag.severity == vim.diagnostic.severity.INFO and M.options.lsp.info then - file_diagnostics_map[diag_path].info = file_diagnostics_map[diag_path].info + 1 - elseif diag.severity == vim.diagnostic.severity.HINT and M.options.lsp.hint then - file_diagnostics_map[diag_path].hint = file_diagnostics_map[diag_path].hint + 1 - end - end - - if M.options.lsp_sum_dir then - for file_path, counts in pairs(file_diagnostics_map) do - file_path = file_path:gsub("/+$", "") - - local dir = file_path:match("(.+)/[^/]+$") - while dir do - local dir_key = dir .. "/" - - if not dir_diagnostics_map[dir_key] then - dir_diagnostics_map[dir_key] = { - info = 0, - hint = 0, - warn = 0, - error = 0, - } - end - - dir_diagnostics_map[dir_key].info = dir_diagnostics_map[dir_key].info + counts.info - dir_diagnostics_map[dir_key].hint = dir_diagnostics_map[dir_key].hint + counts.hint - dir_diagnostics_map[dir_key].warn = dir_diagnostics_map[dir_key].warn + counts.warn - dir_diagnostics_map[dir_key].error = dir_diagnostics_map[dir_key].error + counts.error - - if dir == "/" then - break - end - - dir = dir:match("(.+)/[^/]+$") - end - end - end - - return file_diagnostics_map, dir_diagnostics_map; -end - -local function format_diagnostic(count, config, hi) - if not config then - return nil; - end - - if count == 0 then - return nil; - end - - local prefix = ""; - if type(config) == "string" then - prefix = config; - end +-- local function get_lsp_diagnostics() +-- local all_diagnostics = vim.diagnostic.get(nil); +-- +-- local file_diagnostics_map = {}; +-- +-- for _, diag in ipairs(all_diagnostics) do +-- local diag_path = vim.api.nvim_buf_get_name(diag.bufnr); +-- diag_path = vim.fn.fnamemodify(diag_path, ":p"); +-- +-- if not file_diagnostics_map[diag_path] then +-- file_diagnostics_map[diag_path] = { info = 0, hint = 0, warn = 0, error = 0 }; +-- end +-- +-- if diag.severity == vim.diagnostic.severity.ERROR and M.options.lsp.error then +-- file_diagnostics_map[diag_path].error = file_diagnostics_map[diag_path].error + 1 +-- elseif diag.severity == vim.diagnostic.severity.WARN and M.options.lsp.warn then +-- file_diagnostics_map[diag_path].warn = file_diagnostics_map[diag_path].warn + 1 +-- elseif diag.severity == vim.diagnostic.severity.INFO and M.options.lsp.info then +-- file_diagnostics_map[diag_path].info = file_diagnostics_map[diag_path].info + 1 +-- elseif diag.severity == vim.diagnostic.severity.HINT and M.options.lsp.hint then +-- file_diagnostics_map[diag_path].hint = file_diagnostics_map[diag_path].hint + 1 +-- end +-- end +-- +-- return file_diagnostics_map; +-- end - return { (prefix .. tostring(count)), hi } -end +-- local function format_diagnostic(count, config, hi) +-- if not config then +-- return nil; +-- end +-- +-- if count == 0 then +-- return nil; +-- end +-- +-- local prefix = ""; +-- if type(config) == "string" then +-- prefix = config; +-- end +-- +-- return { (prefix .. tostring(count)), hi } +-- end local function draw(bufnr) local namespace_icons = vim.api.nvim_create_namespace("netrw-icons") - local namespace_diagnostics = vim.api.nvim_create_namespace("netrw-diagnostics") + -- local namespace_diagnostics = vim.api.nvim_create_namespace("netrw-diagnostics") local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) - local file_diagnostics_map, dir_diagnostics_map = nil, nil; - if M.options.lsp then - file_diagnostics_map, dir_diagnostics_map = get_lsp_diagnostics(); - end + -- local file_diagnostics_map = nil; + -- if M.options.lsp then + -- file_diagnostics_map = get_lsp_diagnostics(); + -- end for i, line in ipairs(lines) do local node = parse.get_node(line) @@ -189,49 +157,44 @@ local function draw(bufnr) virt_text = { virt_text }, }); end - if M.options.lsp then - local diagnostics = nil; - - if node.type == parse.TYPE_DIR and M.options.lsp_sum_dir then - if dir_diagnostics_map then - diagnostics = dir_diagnostics_map[node.path]; - end - else - if file_diagnostics_map then - diagnostics = file_diagnostics_map[node.path]; - end - end - if diagnostics then - local virt_text = { { " " } }; - local diag_items = { - { count = diagnostics.error, config = M.options.lsp.error, hl = "DiagnosticError" }, - { count = diagnostics.warn, config = M.options.lsp.warn, hl = "DiagnosticWarn" }, - { count = diagnostics.hint, config = M.options.lsp.hint, hl = "DiagnosticHint" }, - { count = diagnostics.info, config = M.options.lsp.info, hl = "DiagnosticInfo" }, - }; - - local has_diagnostics = false; - for _, item in ipairs(diag_items) do - local formated = format_diagnostic(item.count, item.config, item.hl); - if formated then - if has_diagnostics then - table.insert(virt_text, { " " }); - end - table.insert(virt_text, formated); - has_diagnostics = true; - end - end - - if has_diagnostics then - vim.api.nvim_buf_set_extmark(bufnr, namespace_diagnostics, i - 1, node.lsp, { - id = i, - virt_text_pos = "inline", - virt_text = virt_text, - }); - end - end - end + -- if M.options.lsp then + -- local diagnostics = nil; + -- + -- if file_diagnostics_map then + -- diagnostics = file_diagnostics_map[node.path]; + -- end + -- + -- if diagnostics then + -- local virt_text = { { " " } }; + -- local diag_items = { + -- { count = diagnostics.error, config = M.options.lsp.error, hl = "DiagnosticError" }, + -- { count = diagnostics.warn, config = M.options.lsp.warn, hl = "DiagnosticWarn" }, + -- { count = diagnostics.hint, config = M.options.lsp.hint, hl = "DiagnosticHint" }, + -- { count = diagnostics.info, config = M.options.lsp.info, hl = "DiagnosticInfo" }, + -- }; + -- + -- local has_diagnostics = false; + -- for _, item in ipairs(diag_items) do + -- local formated = format_diagnostic(item.count, item.config, item.hl); + -- if formated then + -- if has_diagnostics then + -- table.insert(virt_text, { " " }); + -- end + -- table.insert(virt_text, formated); + -- has_diagnostics = true; + -- end + -- end + -- + -- if has_diagnostics then + -- vim.api.nvim_buf_set_extmark(bufnr, namespace_diagnostics, i - 1, node.lsp, { + -- id = i, + -- virt_text_pos = "inline", + -- virt_text = virt_text, + -- }); + -- end + -- end + -- end end end end @@ -249,25 +212,21 @@ local default = { dir = " ", sym = " ", - lsp = { - info = false, - hint = false, - warn = "W-", - error = "E-", - }, - - lsp_sum_dir = true, + -- lsp = { + -- info = false, + -- hint = false, + -- warn = "W-", + -- error = "E-", + -- }, } ---@param options Config|nil function M.setup(options) M.options = vim.tbl_deep_extend("force", {}, default, options or {}) - if M.options.file or M.options.dir then - icon_provider = get_icon_provider(M.options.prefer) - if not icon_provider then - error("No icon provider found"); - end + icon_provider = get_icon_provider(M.options.prefer) + if not icon_provider then + error("[netrw-icons] No icon provider found"); end vim.api.nvim_create_autocmd("BufModifiedSet", { -- cgit v1.3