Closed
Description
Jetbrains (webstorm, etc) has a feature where file entries in the tree can collapse into one another. For example, a user can configure the tree to show *.ts
files as a subtree, with siblings matching $1.d.ts
$1.js
and $1.js.map
as the subtree's children:
I made an initial attempt at implementing this in populate.lua but my lua and vim skills are not quite up to snuff just yet. If the idea interests you, please take a look
initial imp
local file_groups = {
ts = { "d.ts", "js", "js.map" },
}
local function ends_with(str, suffix)
return str:sub(-string.len(suffix)) == suffix
end
local function file_new(cwd, name, status, parent_ignored, files)
local absolute_path = utils.path_join({ cwd, name })
local ext = string.match(name, ".?[^.]+%.(.*)") or ""
local is_exec
if M.is_windows then
is_exec = utils.is_windows_exe(ext)
else
is_exec = luv.fs_access(absolute_path, "X")
end
local node = {
name = name,
absolute_path = absolute_path,
executable = is_exec,
extension = ext,
git_status = parent_ignored and "!!" or status.files and status.files[absolute_path],
}
local child_suffixes = file_groups[ext]
if child_suffixes then
local entries = {}
for idx, _name in ipairs(files) do
for _, suf in ipairs(child_suffixes) do
if ends_with(_name, suf) then
table.insert(entries, _name)
table.remove(files, idx)
end
end
end
if #entries ~= 0 then
node.entries = entries
end
end
return node
end