summaryrefslogtreecommitdiffstats
path: root/lua/netrw-icons
diff options
context:
space:
mode:
authorFasamii <fasami0512@gmail.com>2026-02-05 23:36:45 +0100
committerFasamii <fasami0512@gmail.com>2026-02-05 23:36:45 +0100
commitb57179a051fe0d78d411880bc059b67c9b9f4b6f (patch)
tree26f7543d4520024b8037e4a7d0d22412810af474 /lua/netrw-icons
parent0097990b8b8f205ba79163838a93ed811b7229f4 (diff)
downloadnetrw-icons.nvim-b57179a051fe0d78d411880bc059b67c9b9f4b6f.tar.gz
netrw-icons.nvim-b57179a051fe0d78d411880bc059b67c9b9f4b6f.tar.bz2
netrw-icons.nvim-b57179a051fe0d78d411880bc059b67c9b9f4b6f.tar.xz
netrw-icons.nvim-b57179a051fe0d78d411880bc059b67c9b9f4b6f.tar.zst
whitespace misalignment fix
Diffstat (limited to 'lua/netrw-icons')
-rw-r--r--lua/netrw-icons/init.lua98
-rw-r--r--lua/netrw-icons/parse.lua66
2 files changed, 65 insertions, 99 deletions
diff --git a/lua/netrw-icons/init.lua b/lua/netrw-icons/init.lua
index 4f378a2..38da421 100644
--- a/lua/netrw-icons/init.lua
+++ b/lua/netrw-icons/init.lua
@@ -43,14 +43,17 @@ local function get_icon_from_provider(name)
local provider = icon_provider.provider;
local type = icon_provider.type;
if type == "devicons" then
- local symbol, hi = provider.get_icon(name, nil, { strict = true, default = false });
+ local symbol, hi = provider.get_icon(name, nil, { strict = true, default = M.options.file_default });
if symbol then
- return { symbol = symbol, hi = hi };
+ return { symbol = symbol .. " ", hi = hi };
end
elseif type == "miniicons" then
- local symbol, hi = provider.get("file", name)
+ local symbol, hi, is_default = provider.get("file", name)
if symbol then
- return { symbol = symbol, hi = hi };
+ if is_default and not M.options.file_default then
+ symbol = "";
+ end
+ return { symbol = symbol .. " ", hi = hi };
end
end
end
@@ -62,16 +65,16 @@ end
local function get_icon(node)
if node.type == parse.TYPE_DIR and M.options.dir then
if M.options.dir then
- return { symbol = M.options.dir, hi = "Normal" };
+ return { symbol = M.options.dir, hi = "Directory" };
end
elseif node.type == parse.TYPE_SYMLINK and M.options.sym then
if M.options.sym then
- return { symbol = M.options.sym, hi = "Normal" };
+ return { symbol = M.options.sym, hi = "Question" };
end
elseif node.type == parse.TYPE_FILE and M.options.file then
local file_type = vim.fn.fnamemodify(node.name, ":e");
if string.sub(file_type, -1) == "*" then
- return get_icon_from_provider("exe");
+ return get_icon_from_provider("exe")
end
return get_icon_from_provider(node.name);
end
@@ -79,27 +82,39 @@ local function get_icon(node)
return nil;
end
--- local function get_lsp_diagnostics(node)
--- local diagnostics = {}
--- local filepath = node.dir .. "/" .. node.node
---
--- -- FIXME: that foo takes bufnr not path
--- local diag = vim.diagnostic.get(nil, { path = filepath })
---
--- for _, d in ipairs(diag) do
--- if d.severity == vim.diagnostic.severity.ERROR and M.options.lsp.error then
--- table.insert(diagnostics, { icon = "E", hl = "DiagnosticError" })
--- elseif d.severity == vim.diagnostic.severity.WARN and M.options.lsp.warn then
--- table.insert(diagnostics, { icon = "W", hl = "DiagnosticWarn" })
--- elseif d.severity == vim.diagnostic.severity.INFO and M.options.lsp.info then
--- table.insert(diagnostics, { icon = "I", hl = "DiagnosticInfo" })
--- elseif d.severity == vim.diagnostic.severity.HINT and M.options.lsp.hint then
--- table.insert(diagnostics, { icon = "H", hl = "DiagnosticHint" })
--- end
--- end
---
--- return diagnostics
--- end
+local function path_to_bufnr(path)
+ path = vim.fn.fnamemodify(path, ":p");
+
+ for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
+ if vim.api.nvim_buf_is_loaded(bufnr) then
+ local name = vim.api.nvim_buf_get_name(bufnr);
+ if name == path then
+ return bufnr;
+ end
+ end
+ end
+
+ return nil
+end
+
+local function get_lsp_diagnostics(node)
+ -- local diagnostics = vim.diagnostic.get(path_to_bufnr(node.path))
+
+ -- for _, d in ipairs(diag) do
+ -- if d.severity == vim.diagnostic.severity.ERROR and M.options.lsp.error then
+ -- table.insert(diagnostics, { icon = "E", hl = "DiagnosticError" })
+ -- elseif d.severity == vim.diagnostic.severity.WARN and M.options.lsp.warn then
+ -- table.insert(diagnostics, { icon = "W", hl = "DiagnosticWarn" })
+ -- elseif d.severity == vim.diagnostic.severity.INFO and M.options.lsp.info then
+ -- table.insert(diagnostics, { icon = "I", hl = "DiagnosticInfo" })
+ -- elseif d.severity == vim.diagnostic.severity.HINT and M.options.lsp.hint then
+ -- table.insert(diagnostics, { icon = "H", hl = "DiagnosticHint" })
+ -- end
+ -- end
+
+ -- return diagnostics
+ return nil;
+end
local function draw(bufnr)
local namespace = vim.api.nvim_create_namespace("netrw")
@@ -110,18 +125,32 @@ local function draw(bufnr)
for i, line in ipairs(lines) do
local node = parse.get_node(line)
- -- vim.print("[" .. line .. "] - ");
- -- vim.print(node);
-
if node then
local icon = get_icon(node);
if icon then
- vim.api.nvim_buf_set_extmark(bufnr, namespace, i - 1, node.icon - 1, {
+ local symbol = icon.symbol;
+ local virt_text = { symbol };
+ if icon.hi then
+ virt_text[2] = icon.hi;
+ end
+ vim.api.nvim_buf_set_extmark(bufnr, namespace, i - 1, node.icon, {
id = i,
virt_text_pos = "inline",
- virt_text = { { " " .. icon.symbol, icon.hi } },
+ virt_text = { virt_text },
});
end
+ if M.options.lsp then
+ local diagnostics = get_lsp_diagnostics(node);
+ if diagnostics then
+ local virt_text = { " " .. "ERROR" };
+
+ vim.api.nvim_buf_set_extmark(bufnr, namespace, i - 1, node.lsp, {
+ id = i,
+ virt_text_pos = "inline",
+ virt_text = { virt_text },
+ });
+ end
+ end
end
end
end
@@ -133,7 +162,8 @@ M.options = {}
local default = {
prefer = nil,
file = true,
- dir = "",
+ file_default = true,
+ dir = " ",
sym = false,
lsp = {
info = false,
diff --git a/lua/netrw-icons/parse.lua b/lua/netrw-icons/parse.lua
index c2f245c..9851f78 100644
--- a/lua/netrw-icons/parse.lua
+++ b/lua/netrw-icons/parse.lua
@@ -136,75 +136,11 @@ local parse_liststyle_3 = function(line)
return {
name = link_target or content,
icon = tree_end,
+ lsp = tree_end + #(link_target or content),
type = type,
}
end
-
-
-
--- local _, to = string.find(line, "^[|%s]*")
--- if to ~= 0 then
--- error("to: " .. to);
--- end
--- local pipelessLine = string.sub(line, to + 1, #line)
---
--- if pipelessLine == "" then
--- return nil
--- end
---
--- local _, _, node, link = string.find(pipelessLine, "^(.+)@\t%s*%-%->%s*(.+)")
--- if node then
--- return {
--- dir = curdir,
--- icon_col = to,
--- name_col = to,
--- lsp_col = to + #node,
--- node = node,
--- extension = vim.fn.fnamemodify(node, ":e"),
--- link = link,
--- type = M.TYPE_SYMLINK,
--- }
--- end
---
--- local _, _, dir = string.find(pipelessLine, "^(.*)/")
--- if dir then
--- return {
--- dir = curdir,
--- icon_col = to,
--- name_col = to,
--- lsp_col = to + #dir + 1,
--- node = dir,
--- type = M.TYPE_DIR,
--- }
--- end
---
--- local ext = vim.fn.fnamemodify(pipelessLine, ":e")
--- local clean_line = pipelessLine
--- if string.sub(ext, -1) == "*" then
--- ext = string.sub(ext, 1, -2)
--- clean_line = string.sub(pipelessLine, 1, -2)
--- end
---
--- return {
--- current_dir = vim.b.netrw_curdir,
--- icon_col = to,
--- name_col = to,
--- lsp_col = to + #clean_line,
--- node = clean_line,
--- extension = ext,
--- type = M.TYPE_FILE,
--- }
-
--- return {
--- name = "name of the file",
--- type = "type of the netrw element (dir, file, symlink)"
--- path = "full path of the file",
--- icon = "character after the | netrw symbol",
--- lsp = "two characters after the filename end",
--- }
--- end
-
---@param line string
---@return PWord|nil
M.get_node = function(line)