nvim-tree.lua icon indicating copy to clipboard operation
nvim-tree.lua copied to clipboard

[feature]: file nesting a la jetbrains

Open bennypowers opened this issue 3 years ago • 2 comments

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:

example of nesting

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


bennypowers avatar Feb 01 '22 12:02 bennypowers

Hi, i'll completely be honest with you, in the current state of the plugin, it would be VERY hard to implement this. Some refactoring are planned to make the api more usable and the plugin more extensible. Before that, it won't be implemented.

kyazdani42 avatar Feb 02 '22 08:02 kyazdani42

That's understandable. I'd be interested to track the progress of that refactor, and I hope you'll keep this feature in mind while you do it. This is a cute 'nice-to-have' that I think would benefit many users.

nvim-tree is really nice. Thank you for publishing and maintaining it!

bennypowers avatar Feb 02 '22 08:02 bennypowers

Thanks for the feature request.

Unfortunately, nvim-tree is in a stable, feature complete state and we do not intend to add such features.

alex-courtis avatar Oct 15 '22 04:10 alex-courtis