* chore: add type annotations to (almost) all functions
* stylua
* Add classes for symlink nodes
* Replace deprecated `@vararg`
* Move node classes to `node` module
* Fix `Symlink*` classes
* add vim and libuv runtime for luals, qualify libuv types
* add scripts/luals-check, not quite ready for CI
* additional nil checks for git/init.lua and git/runner.lua
* additional nil checks for nvim-tree.lua
* wrap vim.cmd-as-a-function calls inside functions
* vim.tbl_filter predicate returns booleans
* Revert "add scripts/luals-check, not quite ready for CI"
This reverts commit c70229cad9.
* Add `MinimalNode` class in `marks` module
* Fix various LSP warnings
* stylua
* Fix `Explorer` class, update related annotations and add necessary checks
* Add missing annotations to `live-filter`
* Add temporary aliases for `uv.*` types
* Resolve remaining LSP warnings
* Revert changes not related to internal types
* Minor adjustments
* Update doc comments style
* Minor adjustments (pt. 2)
---------
Co-authored-by: Alexander Courtis <alex@courtis.org>
54 lines
1.2 KiB
Lua
54 lines
1.2 KiB
Lua
local renderer = require "nvim-tree.renderer"
|
|
local utils = require "nvim-tree.utils"
|
|
local core = require "nvim-tree.core"
|
|
local lib = require "nvim-tree.lib"
|
|
local Iterator = require "nvim-tree.iterators.node-iterator"
|
|
|
|
local M = {}
|
|
|
|
---@return fun(path: string): boolean
|
|
local function buf_match()
|
|
local buffer_paths = vim.tbl_map(function(buffer)
|
|
return vim.api.nvim_buf_get_name(buffer)
|
|
end, vim.api.nvim_list_bufs())
|
|
|
|
return function(path)
|
|
for _, buffer_path in ipairs(buffer_paths) do
|
|
local matches = utils.str_find(buffer_path, path)
|
|
if matches then
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
end
|
|
|
|
---@param keep_buffers boolean
|
|
function M.fn(keep_buffers)
|
|
local node = lib.get_node_at_cursor()
|
|
local explorer = core.get_explorer()
|
|
|
|
if explorer == nil then
|
|
return
|
|
end
|
|
|
|
local matches = buf_match()
|
|
|
|
Iterator.builder(explorer.nodes)
|
|
:hidden()
|
|
:applier(function(n)
|
|
if n.nodes ~= nil then
|
|
n.open = keep_buffers == true and matches(n.absolute_path)
|
|
end
|
|
end)
|
|
:recursor(function(n)
|
|
return n.group_next and { n.group_next } or n.nodes
|
|
end)
|
|
:iterate()
|
|
|
|
renderer.draw()
|
|
utils.focus_node_or_parent(node)
|
|
end
|
|
|
|
return M
|