summaryrefslogtreecommitdiffstats
path: root/lua/netrw-icons/parse.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/netrw-icons/parse.lua')
-rw-r--r--lua/netrw-icons/parse.lua221
1 files changed, 107 insertions, 114 deletions
diff --git a/lua/netrw-icons/parse.lua b/lua/netrw-icons/parse.lua
index cefb9b2..911a1c6 100644
--- a/lua/netrw-icons/parse.lua
+++ b/lua/netrw-icons/parse.lua
@@ -12,106 +12,106 @@ M.TYPE_DIR = 0
M.TYPE_FILE = 1
M.TYPE_SYMLINK = 2
----@alias PWord {dir:string, node:string, link:string|nil, extension:string|nil, type:number, icon_col:number, name_col:number, lsp_col:number}
+---@alias rwNode{name:string, icon:number, type:number}
----@param line string
----@param curdir string
----@return PWord|nil
-local parse_liststyle_0 = function(line, curdir)
- local _, _, node, link = string.find(line, "^(.+)@\t%s*%-%->%s*(.+)")
- if node then
- return {
- dir = curdir,
- icon_col = 0,
- name_col = 0,
- lsp_col = #node,
- node = node,
- extension = vim.fn.fnamemodify(node, ":e"),
- link = link,
- type = M.TYPE_SYMLINK,
- }
- end
-
- local _, _, dir = string.find(line, "^(.*)/")
- if dir then
- return {
- dir = curdir,
- icon_col = 0,
- name_col = 0,
- lsp_col = #dir + 1, -- +1 for the "/"
- node = dir,
- type = M.TYPE_DIR,
- }
- end
-
- local ext = vim.fn.fnamemodify(line, ":e")
- local clean_line = line
- if string.sub(ext, -1) == "*" then
- ext = string.sub(ext, 1, -2)
- clean_line = string.sub(line, 1, -2)
- end
-
- return {
- dir = curdir,
- icon_col = 0,
- name_col = 0,
- lsp_col = #clean_line,
- node = clean_line,
- extension = ext,
- type = M.TYPE_FILE,
- }
-end
-
----@param line string
----@param curdir string
----@return PWord|nil
-local parse_liststyle_1 = function(line, curdir)
- local _, _, node, link = string.find(line, "^(.+)@%s+")
- if node then
- return {
- dir = curdir,
- icon_col = 0,
- name_col = 0,
- lsp_col = #node,
- node = node,
- extension = vim.fn.fnamemodify(node, ":e"),
- link = link,
- type = M.TYPE_SYMLINK,
- }
- end
-
- local _, _, dir = string.find(line, "^(.*)/")
- if dir then
- return {
- dir = curdir,
- icon_col = 0,
- name_col = 0,
- lsp_col = #dir + 1,
- node = dir,
- type = M.TYPE_DIR,
- }
- end
-
- local file = vim.fn.substitute(line, "^\\(\\%(\\S\\+ \\)*\\S\\+\\).\\{-}$", "\\1", "e")
- local ext = vim.fn.fnamemodify(file, ":e")
- if string.sub(ext, -1) == "*" then
- ext = string.sub(ext, 1, -2)
- file = string.sub(file, 1, -2)
- end
-
- return {
- dir = curdir,
- icon_col = 0,
- name_col = 0,
- lsp_col = #file,
- node = file,
- extension = ext,
- type = M.TYPE_FILE,
- }
-end
+-- ---@param line string
+-- ---@param curdir string
+-- ---@return rwNode|nil
+-- local parse_liststyle_0 = function(line, curdir)
+-- local _, _, node, link = string.find(line, "^(.+)@\t%s*%-%->%s*(.+)")
+-- if node then
+-- return {
+-- dir = curdir,
+-- icon_col = 0,
+-- name_col = 0,
+-- lsp_col = #node,
+-- node = node,
+-- extension = vim.fn.fnamemodify(node, ":e"),
+-- link = link,
+-- type = M.TYPE_SYMLINK,
+-- }
+-- end
+--
+-- local _, _, dir = string.find(line, "^(.*)/")
+-- if dir then
+-- return {
+-- dir = curdir,
+-- icon_col = 0,
+-- name_col = 0,
+-- lsp_col = #dir + 1, -- +1 for the "/"
+-- node = dir,
+-- type = M.TYPE_DIR,
+-- }
+-- end
+--
+-- local ext = vim.fn.fnamemodify(line, ":e")
+-- local clean_line = line
+-- if string.sub(ext, -1) == "*" then
+-- ext = string.sub(ext, 1, -2)
+-- clean_line = string.sub(line, 1, -2)
+-- end
+--
+-- return {
+-- dir = curdir,
+-- icon_col = 0,
+-- name_col = 0,
+-- lsp_col = #clean_line,
+-- node = clean_line,
+-- extension = ext,
+-- type = M.TYPE_FILE,
+-- }
+-- end
+--
+-- ---@param line string
+-- ---@param curdir string
+-- ---@return rwNode|nil
+-- local parse_liststyle_1 = function(line, curdir)
+-- local _, _, node, link = string.find(line, "^(.+)@%s+")
+-- if node then
+-- return {
+-- dir = curdir,
+-- icon_col = 0,
+-- name_col = 0,
+-- lsp_col = #node,
+-- node = node,
+-- extension = vim.fn.fnamemodify(node, ":e"),
+-- link = link,
+-- type = M.TYPE_SYMLINK,
+-- }
+-- end
+--
+-- local _, _, dir = string.find(line, "^(.*)/")
+-- if dir then
+-- return {
+-- dir = curdir,
+-- icon_col = 0,
+-- name_col = 0,
+-- lsp_col = #dir + 1,
+-- node = dir,
+-- type = M.TYPE_DIR,
+-- }
+-- end
+--
+-- local file = vim.fn.substitute(line, "^\\(\\%(\\S\\+ \\)*\\S\\+\\).\\{-}$", "\\1", "e")
+-- local ext = vim.fn.fnamemodify(file, ":e")
+-- if string.sub(ext, -1) == "*" then
+-- ext = string.sub(ext, 1, -2)
+-- file = string.sub(file, 1, -2)
+-- end
+--
+-- return {
+-- dir = curdir,
+-- icon_col = 0,
+-- name_col = 0,
+-- lsp_col = #file,
+-- node = file,
+-- extension = ext,
+-- type = M.TYPE_FILE,
+-- }
+-- end
---@param line string
----@return PWord|nil
+---@return rwNode|nil
local parse_liststyle_3 = function(line)
local current_dir = vim.b.netrw_curdir;
local type = M.TYPE_FILE;
@@ -123,9 +123,12 @@ local parse_liststyle_3 = function(line)
return nil;
end
+ local name = content;
+
local _, _, link, link_target = string.find(content, "^(.+)@\t%s*%-%->%s*(.+)")
if link then
type = M.TYPE_SYMLINK;
+ name = link_target;
end
local _, _, dir = string.find(content, "^(.*)/")
@@ -134,33 +137,23 @@ local parse_liststyle_3 = function(line)
end
return {
- name = link_target or content,
- path = current_dir .. "/" .. (link_target or content),
+ name = name,
+ -- path = current_dir .. "/" .. name,
icon = tree_end,
- lsp = tree_end + #content,
+ -- lsp = tree_end + #content,
type = type,
}
end
---@param line string
----@return PWord|nil
+---@return rwNode|nil
M.get_node = function(line)
- if string.find(line, '^"') then
- return nil
- end
-
- if line == "" then
- return nil
- end
+ if string.find(line, '^"') then return nil end
+ if line == "" then return nil end
- local curdir = vim.b.netrw_curdir
local liststyle = vim.b.netrw_liststyle
- if liststyle == 0 then
- return parse_liststyle_0(line, curdir)
- elseif liststyle == 1 then
- return parse_liststyle_1(line, curdir)
- elseif liststyle == 3 then
+ if liststyle == 3 then
return parse_liststyle_3(line)
end