mirror of
https://github.com/nvim-tree/nvim-tree.lua.git
synced 2026-07-28 15:59:44 +05:30
Compare commits
25 Commits
nvim-tree-
...
nvim-tree-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
531b807b8f | ||
|
|
c760c92667 | ||
|
|
8e8be709c9 | ||
|
|
fb343438d4 | ||
|
|
82f58063d6 | ||
|
|
07f541fcaa | ||
|
|
f9bfc0059e | ||
|
|
24cfcc9437 | ||
|
|
5f65bd3d93 | ||
|
|
5a1d08bc0c | ||
|
|
d277467fc0 | ||
|
|
509962f21a | ||
|
|
85d1145ac7 | ||
|
|
7adc5679fe | ||
|
|
31503ad5d8 | ||
|
|
02ccbcd4af | ||
|
|
3603f069ff | ||
|
|
4cbe79526f | ||
|
|
b548cfef00 | ||
|
|
ec0efb06b0 | ||
|
|
43a3bb4b26 | ||
|
|
6eaf74c991 | ||
|
|
3d385d3346 | ||
|
|
f37ebac811 | ||
|
|
dfeeb12aaa |
11
.github/workflows/ci.yml
vendored
11
.github/workflows/ci.yml
vendored
@@ -5,6 +5,8 @@ on:
|
||||
push:
|
||||
branches: [master]
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 0 * * 0' # weekly on sundays
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
@@ -24,10 +26,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v6
|
||||
uses: actions/checkout@v7
|
||||
|
||||
- name: install lua ${{ matrix.lua_version }}
|
||||
uses: leafo/gh-actions-lua@v12
|
||||
uses: leafo/gh-actions-lua@v13
|
||||
with:
|
||||
luaVersion: ${{ matrix.lua_version }}
|
||||
|
||||
@@ -58,7 +60,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v6
|
||||
uses: actions/checkout@v7
|
||||
|
||||
- name: install nvim ${{ matrix.nvim_version }}
|
||||
uses: rhysd/action-setup-vim@v1
|
||||
@@ -87,11 +89,12 @@ jobs:
|
||||
- run: make format-check
|
||||
|
||||
- name: build Nvim from source
|
||||
if: ${{ matrix.nvim_version == 'stable' }}
|
||||
run: |
|
||||
mkdir -p "${DIR_NVIM_SRC}"
|
||||
curl -L "https://github.com/neovim/neovim/archive/refs/tags/${{ matrix.nvim_version }}.tar.gz" | tar zx --directory "${DIR_NVIM_SRC}/.."
|
||||
cd "${DIR_NVIM_SRC}"
|
||||
make doc
|
||||
make lintdoc
|
||||
|
||||
- run: make help-check
|
||||
if: ${{ matrix.nvim_version == 'stable' }}
|
||||
|
||||
2
.github/workflows/luarocks-release.yml
vendored
2
.github/workflows/luarocks-release.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
luarocks-upload:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v7
|
||||
- name: LuaRocks Upload
|
||||
uses: nvim-neorocks/luarocks-tag-release@v7
|
||||
env:
|
||||
|
||||
4
.github/workflows/release-please.yml
vendored
4
.github/workflows/release-please.yml
vendored
@@ -14,9 +14,9 @@ jobs:
|
||||
release-please:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: googleapis/release-please-action@v4
|
||||
- uses: googleapis/release-please-action@v5
|
||||
id: release
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v7
|
||||
- name: tag major and minor versions
|
||||
if: ${{ steps.release.outputs.release_created }}
|
||||
run: |
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
".": "1.16.0"
|
||||
".": "1.18.0"
|
||||
}
|
||||
|
||||
40
CHANGELOG.md
40
CHANGELOG.md
@@ -1,5 +1,45 @@
|
||||
# Changelog
|
||||
|
||||
## [1.18.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.17.0...nvim-tree-v1.18.0) (2026-07-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **#1549:** p will paste files from another nvim-tree instance, gp will cut/paste ([#3336](https://github.com/nvim-tree/nvim-tree.lua/issues/3336)) ([c760c92](https://github.com/nvim-tree/nvim-tree.lua/commit/c760c92667fe5febf99e2a5bb8a543b0208c743b))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **#3312:** correct cursor when full name shown, requires nvim 0.12.2+ ([#3316](https://github.com/nvim-tree/nvim-tree.lua/issues/3316)) ([d277467](https://github.com/nvim-tree/nvim-tree.lua/commit/d277467fc0d1d0e2bca88165a1de6b526f9f6fe8))
|
||||
* **#3324:** deprecated BufModifiedSet event replaced by OptionSet event for Nvim 0.13+ ([#3325](https://github.com/nvim-tree/nvim-tree.lua/issues/3325)) ([f9bfc00](https://github.com/nvim-tree/nvim-tree.lua/commit/f9bfc0059eca24546b69a7006110463da4808f8f))
|
||||
* **#3327:** pass nvim_tree.api.node.open.Opts to all applicable nvim_tree.api.node.open function ([#3329](https://github.com/nvim-tree/nvim-tree.lua/issues/3329)) ([07f541f](https://github.com/nvim-tree/nvim-tree.lua/commit/07f541fcaa4a5ae019598240362449ab7e9812b3))
|
||||
* **full-name:** lower `zindex` to get consistent cursor shape ([d277467](https://github.com/nvim-tree/nvim-tree.lua/commit/d277467fc0d1d0e2bca88165a1de6b526f9f6fe8))
|
||||
|
||||
## [1.17.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.16.0...nvim-tree-v1.17.0) (2026-04-07)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **#3292:** add nvim_tree.config.filesystem_watchers.whitelist_dirs - strongly recommended for windows ([#3298](https://github.com/nvim-tree/nvim-tree.lua/issues/3298)) ([6eaf74c](https://github.com/nvim-tree/nvim-tree.lua/commit/6eaf74c9919d121d2806ac3c20e757e66bd29c31))
|
||||
* **#3310:** minimum neovim version 0.10 ([#3311](https://github.com/nvim-tree/nvim-tree.lua/issues/3311)) ([7adc567](https://github.com/nvim-tree/nvim-tree.lua/commit/7adc5679feb439275255aa9e95c434cca206d10c))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **#3257:** error when calling api.tree.find_file ([#3304](https://github.com/nvim-tree/nvim-tree.lua/issues/3304)) ([b548cfe](https://github.com/nvim-tree/nvim-tree.lua/commit/b548cfef00a79f0b3e3af24f91ae6bd14f22af95))
|
||||
* **#3293:** marks.bulk operations filter descendant nodes ([#3294](https://github.com/nvim-tree/nvim-tree.lua/issues/3294)) ([f37ebac](https://github.com/nvim-tree/nvim-tree.lua/commit/f37ebac81164e1445c499cdd6de86e6d8e5d57e4))
|
||||
* **#3301:** setup with empty config fails ([#3303](https://github.com/nvim-tree/nvim-tree.lua/issues/3303)) ([ec0efb0](https://github.com/nvim-tree/nvim-tree.lua/commit/ec0efb06b0abfa56492acfc8c34ac8958d18601e))
|
||||
* system open native requires nvim 0.10 ([#3309](https://github.com/nvim-tree/nvim-tree.lua/issues/3309)) ([02ccbcd](https://github.com/nvim-tree/nvim-tree.lua/commit/02ccbcd4af9a7fa159251f721d763c0d16f91703))
|
||||
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* **#3231:** decrease setup time: optimise setup and defer requires until tree open ([#3308](https://github.com/nvim-tree/nvim-tree.lua/issues/3308)) ([31503ad](https://github.com/nvim-tree/nvim-tree.lua/commit/31503ad5d869fca61461d82a9126f62480ecb0ab))
|
||||
* **#3257:** remove setup for actions modules, full-name and explorer ([#3299](https://github.com/nvim-tree/nvim-tree.lua/issues/3299)) ([43a3bb4](https://github.com/nvim-tree/nvim-tree.lua/commit/43a3bb4b26b4578a704f24bb6a4889b454c0eb65))
|
||||
* **#3257:** remove setup for modules: buffers, diagnostics, git, help, keymap, lib, watcher ([#3295](https://github.com/nvim-tree/nvim-tree.lua/issues/3295)) ([3d385d3](https://github.com/nvim-tree/nvim-tree.lua/commit/3d385d3346e4883d60dc37cf642bd47bed78a46e))
|
||||
* **#3257:** remove setup for renderer, log, appearance ([#3307](https://github.com/nvim-tree/nvim-tree.lua/issues/3307)) ([3603f06](https://github.com/nvim-tree/nvim-tree.lua/commit/3603f069ff783c31986894a56c2a6755331b0802))
|
||||
* **#3257:** remove setup for view, extracting view-state ([#3306](https://github.com/nvim-tree/nvim-tree.lua/issues/3306)) ([4cbe795](https://github.com/nvim-tree/nvim-tree.lua/commit/4cbe79526f8bc0bdb1a500d261dc5cc1be4e77d5))
|
||||
|
||||
## [1.16.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.15.0...nvim-tree-v1.16.0) (2026-03-17)
|
||||
|
||||
|
||||
|
||||
@@ -132,10 +132,10 @@ Whenever new neovim API is introduced, please ensure that it is available in old
|
||||
See `nvim-tree.setup` for the oldest supported version of neovim. If the API is not availble in that version, a backwards compatibility shim must be used e.g.
|
||||
|
||||
```lua
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
modified = vim.api.nvim_get_option_value("modified", { buf = target_bufid })
|
||||
if vim.fn.has("nvim-0.11") == 1 and vim.hl and vim.hl.range then
|
||||
vim.hl.range(0, ns_id, details.hl_group, { 0, col }, { 0, details.end_col, }, {})
|
||||
else
|
||||
modified = vim.api.nvim_buf_get_option(target_bufid, "modified") ---@diagnostic disable-line: deprecated
|
||||
vim.api.nvim_buf_add_highlight(0, ns_id, details.hl_group, 0, col, details.end_col) ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
```
|
||||
|
||||
@@ -184,7 +184,7 @@ make help-update
|
||||
- Generate config classes `*nvim-tree-config*`
|
||||
- Generate API `*nvim-tree-api*`
|
||||
|
||||
## Checking And Linting
|
||||
## Checking
|
||||
|
||||
This is run in CI. Commit or stage your changes and run:
|
||||
|
||||
@@ -194,7 +194,6 @@ make help-check
|
||||
|
||||
- Re-runs `make help-update`
|
||||
- Checks that `git diff` is empty, to ensure that all content has been generated. This is why a stage or commit is necessary.
|
||||
- Lints `doc/nvim-tree-lua.txt` using `scripts/vimdoc.sh lintdoc` to check for no broken links etc.
|
||||
|
||||
# Windows
|
||||
|
||||
|
||||
4
Makefile
4
Makefile
@@ -43,11 +43,9 @@ help-update:
|
||||
|
||||
#
|
||||
# CI
|
||||
# --ignore-blank-lines is used as nightly has removed unnecessary blank lines that stable (0.11.5) currently inserts
|
||||
#
|
||||
help-check: help-update
|
||||
scripts/vimdoc.sh lintdoc
|
||||
git diff --ignore-blank-lines --exit-code doc/nvim-tree-lua.txt
|
||||
git diff --exit-code doc/nvim-tree-lua.txt
|
||||
|
||||
|
||||
.PHONY: all lint style check luacheck style-check style-doc luals format-fix format-check help-update help-check
|
||||
|
||||
@@ -51,7 +51,7 @@ markdown-toc --maxdepth=2 -i README.md
|
||||
|
||||
# Requirements
|
||||
|
||||
[neovim >=0.9.0](https://github.com/neovim/neovim/wiki/Installing-Neovim)
|
||||
[Nvim >= 0.10](https://github.com/neovim/neovim/wiki/Installing-Neovim). At least `n - 0.1` stable Nvim compatibility is guaranteed. You may use a `compat-nvim-0.X` tag for earlier Nvim versions, however they will receive no updates or support.
|
||||
|
||||
[nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) is optional and used to display file icons. It requires a [patched font](https://www.nerdfonts.com/). Your terminal emulator must be configured to use that font, usually "Hack Nerd Font"
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,326 +1,59 @@
|
||||
local api = require("nvim-tree.api")
|
||||
local log = require("nvim-tree.log")
|
||||
local view = require("nvim-tree.view")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local actions = require("nvim-tree.actions")
|
||||
local core = require("nvim-tree.core")
|
||||
local notify = require("nvim-tree.notify")
|
||||
local config = require("nvim-tree.config")
|
||||
local M = {}
|
||||
|
||||
local M = {
|
||||
init_root = "",
|
||||
}
|
||||
|
||||
--- Helper function to execute some explorer method safely
|
||||
---@param fn string # key of explorer
|
||||
---@param ... any|nil
|
||||
---@return function|nil
|
||||
local function explorer_fn(fn, ...)
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
return explorer[fn](explorer, ...)
|
||||
end
|
||||
end
|
||||
|
||||
--- Update the tree root to a directory or the directory containing
|
||||
---@param path string relative or absolute
|
||||
---@param bufnr number|nil
|
||||
function M.change_root(path, bufnr)
|
||||
-- skip if current file is in ignore_list
|
||||
if type(bufnr) == "number" then
|
||||
local ft
|
||||
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
ft = vim.api.nvim_get_option_value("filetype", { buf = bufnr }) or ""
|
||||
else
|
||||
ft = vim.api.nvim_buf_get_option(bufnr, "filetype") or "" ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
|
||||
for _, value in pairs(config.g.update_focused_file.update_root.ignore_list) do
|
||||
if utils.str_find(path, value) or utils.str_find(ft, value) then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- don't find inexistent
|
||||
if vim.fn.filereadable(path) == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local cwd = core.get_cwd()
|
||||
if cwd == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local vim_cwd = vim.fn.getcwd()
|
||||
|
||||
-- test if in vim_cwd
|
||||
if utils.path_relative(path, vim_cwd) ~= path then
|
||||
if vim_cwd ~= cwd then
|
||||
explorer_fn("change_dir", vim_cwd)
|
||||
end
|
||||
return
|
||||
end
|
||||
-- test if in cwd
|
||||
if utils.path_relative(path, cwd) ~= path then
|
||||
return
|
||||
end
|
||||
|
||||
-- otherwise test M.init_root
|
||||
if config.g.prefer_startup_root and utils.path_relative(path, M.init_root) ~= path then
|
||||
explorer_fn("change_dir", M.init_root)
|
||||
return
|
||||
end
|
||||
-- otherwise root_dirs
|
||||
for _, dir in pairs(config.g.root_dirs) do
|
||||
dir = vim.fn.fnamemodify(dir, ":p")
|
||||
if utils.path_relative(path, dir) ~= path then
|
||||
explorer_fn("change_dir", dir)
|
||||
return
|
||||
end
|
||||
end
|
||||
-- finally fall back to the folder containing the file
|
||||
explorer_fn("change_dir", vim.fn.fnamemodify(path, ":p:h"))
|
||||
end
|
||||
|
||||
function M.tab_enter()
|
||||
if view.is_visible({ any_tabpage = true }) then
|
||||
local bufname = vim.api.nvim_buf_get_name(0)
|
||||
|
||||
local ft
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
ft = vim.api.nvim_get_option_value("filetype", { buf = 0 }) or ""
|
||||
else
|
||||
ft = vim.api.nvim_buf_get_option(0, "ft") ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
|
||||
for _, filter in ipairs(config.g.tab.sync.ignore) do
|
||||
if bufname:match(filter) ~= nil or ft:match(filter) ~= nil then
|
||||
return
|
||||
end
|
||||
end
|
||||
view.open({ focus_tree = false })
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.open_on_directory()
|
||||
local should_proceed = config.g.hijack_directories.auto_open or view.is_visible()
|
||||
if not should_proceed then
|
||||
return
|
||||
end
|
||||
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
local bufname = vim.api.nvim_buf_get_name(buf)
|
||||
if vim.fn.isdirectory(bufname) ~= 1 then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer then
|
||||
core.init(bufname)
|
||||
end
|
||||
|
||||
explorer_fn("force_dirchange", bufname, true, false)
|
||||
end
|
||||
|
||||
local function manage_netrw()
|
||||
if config.g.hijack_netrw then
|
||||
vim.cmd("silent! autocmd! FileExplorer *")
|
||||
vim.cmd("autocmd VimEnter * ++once silent! autocmd! FileExplorer *")
|
||||
end
|
||||
if config.g.disable_netrw then
|
||||
vim.g.loaded_netrw = 1
|
||||
vim.g.loaded_netrwPlugin = 1
|
||||
end
|
||||
end
|
||||
|
||||
---@param name string|nil
|
||||
function M.change_dir(name)
|
||||
if name then
|
||||
explorer_fn("change_dir", name)
|
||||
end
|
||||
|
||||
if config.g.update_focused_file.update_root.enable then
|
||||
actions.tree.find_file.fn()
|
||||
end
|
||||
end
|
||||
|
||||
local function setup_autocommands()
|
||||
local augroup_id = vim.api.nvim_create_augroup("NvimTree", { clear = true })
|
||||
local function create_nvim_tree_autocmd(name, custom_opts)
|
||||
local default_opts = { group = augroup_id }
|
||||
vim.api.nvim_create_autocmd(name, vim.tbl_extend("force", default_opts, custom_opts))
|
||||
end
|
||||
|
||||
-- prevent new opened file from opening in the same window as nvim-tree
|
||||
create_nvim_tree_autocmd("BufWipeout", {
|
||||
pattern = "NvimTree_*",
|
||||
callback = function()
|
||||
if not utils.is_nvim_tree_buf(0) then
|
||||
return
|
||||
end
|
||||
if config.g.actions.open_file.eject then
|
||||
view._prevent_buffer_override()
|
||||
else
|
||||
view.abandon_current_window()
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
if config.g.tab.sync.open then
|
||||
create_nvim_tree_autocmd("TabEnter", { callback = vim.schedule_wrap(M.tab_enter) })
|
||||
end
|
||||
if config.g.sync_root_with_cwd then
|
||||
create_nvim_tree_autocmd("DirChanged", {
|
||||
callback = function()
|
||||
M.change_dir(vim.loop.cwd())
|
||||
end,
|
||||
})
|
||||
end
|
||||
if config.g.update_focused_file.enable then
|
||||
create_nvim_tree_autocmd("BufEnter", {
|
||||
callback = function(event)
|
||||
local exclude = config.g.update_focused_file.exclude
|
||||
if type(exclude) == "function" and exclude(event) then
|
||||
return
|
||||
end
|
||||
utils.debounce("BufEnter:find_file", config.g.view.debounce_delay, function()
|
||||
actions.tree.find_file.fn()
|
||||
end)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if config.g.hijack_directories.enable and (config.g.disable_netrw or config.g.hijack_netrw) then
|
||||
create_nvim_tree_autocmd({ "BufEnter", "BufNewFile" }, { callback = M.open_on_directory, nested = true })
|
||||
end
|
||||
|
||||
if config.g.view.centralize_selection then
|
||||
create_nvim_tree_autocmd("BufEnter", {
|
||||
pattern = "NvimTree_*",
|
||||
callback = function()
|
||||
vim.schedule(function()
|
||||
vim.api.nvim_buf_call(0, function()
|
||||
local is_term_mode = vim.api.nvim_get_mode().mode == "t"
|
||||
if is_term_mode then
|
||||
return
|
||||
end
|
||||
vim.cmd([[norm! zz]])
|
||||
end)
|
||||
end)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if config.g.diagnostics.enable then
|
||||
create_nvim_tree_autocmd("DiagnosticChanged", {
|
||||
callback = function(ev)
|
||||
log.line("diagnostics", "DiagnosticChanged")
|
||||
require("nvim-tree.diagnostics").update_lsp(ev)
|
||||
end,
|
||||
})
|
||||
create_nvim_tree_autocmd("User", {
|
||||
pattern = "CocDiagnosticChange",
|
||||
callback = function()
|
||||
log.line("diagnostics", "CocDiagnosticChange")
|
||||
require("nvim-tree.diagnostics").update_coc()
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if config.g.view.float.enable and config.g.view.float.quit_on_focus_loss then
|
||||
create_nvim_tree_autocmd("WinLeave", {
|
||||
pattern = "NvimTree_*",
|
||||
callback = function()
|
||||
if utils.is_nvim_tree_buf(0) then
|
||||
view.close()
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
-- Handles event dispatch when tree is closed by `:q`
|
||||
create_nvim_tree_autocmd("WinClosed", {
|
||||
pattern = "*",
|
||||
---@param ev vim.api.keyset.create_autocmd.callback_args
|
||||
callback = function(ev)
|
||||
if not vim.api.nvim_buf_is_valid(ev.buf) then
|
||||
return
|
||||
end
|
||||
if vim.api.nvim_get_option_value("filetype", { buf = ev.buf }) == "NvimTree" then
|
||||
require("nvim-tree.events")._dispatch_on_tree_close()
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
function M.purge_all_state()
|
||||
view.close_all_tabs()
|
||||
view.abandon_all_windows()
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
require("nvim-tree.git").purge_state()
|
||||
explorer:destroy()
|
||||
core.reset_explorer()
|
||||
end
|
||||
-- purge orphaned that were not destroyed by their nodes
|
||||
require("nvim-tree.watcher").purge_watchers()
|
||||
end
|
||||
|
||||
---@param config_user? nvim_tree.config user supplied subset of config
|
||||
---`require("nvim-tree").setup` must be called once to initialise nvim-tree.
|
||||
---
|
||||
---Call again to apply a change in configuration without restarting Nvim.
|
||||
---
|
||||
---See :help nvim-tree-setup
|
||||
---
|
||||
---@param config_user? nvim_tree.config subset, uses defaults when nil
|
||||
function M.setup(config_user)
|
||||
if vim.fn.has("nvim-0.9") == 0 then
|
||||
notify.warn("nvim-tree.lua requires Neovim 0.9 or higher")
|
||||
local api = require("nvim-tree.api")
|
||||
local api_impl = require("nvim-tree.api.impl")
|
||||
local appearance = require("nvim-tree.appearance")
|
||||
local autocmd = require("nvim-tree.autocmd")
|
||||
local config = require("nvim-tree.config")
|
||||
local log = require("nvim-tree.log")
|
||||
local view_state = require("nvim-tree.view-state")
|
||||
|
||||
-- Nvim version check
|
||||
if vim.fn.has("nvim-0.10") == 0 then
|
||||
require("nvim-tree.notify").warn(
|
||||
"nvim-tree.lua requires Nvim >= 0.10. You may use a compat-nvim-0.X tag for earlier Nvim versions, however they will receive no updates or support.")
|
||||
return
|
||||
end
|
||||
|
||||
M.init_root = vim.fn.getcwd()
|
||||
|
||||
-- validate and merge with defaults as config.g
|
||||
config.setup(config_user)
|
||||
|
||||
manage_netrw()
|
||||
|
||||
require("nvim-tree.notify").setup(config.g)
|
||||
require("nvim-tree.log").setup(config.g)
|
||||
-- optionally create the log file
|
||||
log.start()
|
||||
|
||||
-- optionally log the configuration
|
||||
if log.enabled("config") then
|
||||
log.line("config", "default config + user")
|
||||
log.raw("config", "%s\n", vim.inspect(config.g))
|
||||
end
|
||||
|
||||
require("nvim-tree.actions").setup(config.g)
|
||||
require("nvim-tree.keymap").setup(config.g)
|
||||
require("nvim-tree.appearance").setup()
|
||||
require("nvim-tree.diagnostics").setup(config.g)
|
||||
require("nvim-tree.explorer"):setup(config.g)
|
||||
require("nvim-tree.explorer.watch").setup(config.g)
|
||||
require("nvim-tree.git").setup(config.g)
|
||||
require("nvim-tree.git.utils").setup(config.g)
|
||||
require("nvim-tree.view").setup(config.g)
|
||||
require("nvim-tree.lib").setup(config.g)
|
||||
require("nvim-tree.renderer.components").setup(config.g)
|
||||
require("nvim-tree.buffers").setup(config.g)
|
||||
require("nvim-tree.help").setup(config.g)
|
||||
require("nvim-tree.watcher").setup(config.g)
|
||||
-- idempotent highlight definition
|
||||
appearance.highlight()
|
||||
|
||||
setup_autocommands()
|
||||
-- set the initial view state based on config
|
||||
view_state.initialize()
|
||||
|
||||
-- idempotent au (re)definition
|
||||
autocmd.global()
|
||||
|
||||
-- subsequent calls to setup clear all state
|
||||
if vim.g.NvimTreeSetup == 1 then
|
||||
-- subsequent calls to setup
|
||||
M.purge_all_state()
|
||||
require("nvim-tree.core").purge_all_state()
|
||||
end
|
||||
|
||||
-- hydrate post setup API
|
||||
api_impl.hydrate_post_setup(api)
|
||||
|
||||
vim.g.NvimTreeSetup = 1
|
||||
vim.api.nvim_exec_autocmds("User", { pattern = "NvimTreeSetup" })
|
||||
|
||||
require("nvim-tree.api.impl.post").hydrate(api)
|
||||
end
|
||||
|
||||
vim.g.NvimTreeRequired = 1
|
||||
|
||||
@@ -1,10 +1,29 @@
|
||||
---@meta
|
||||
local nvim_tree = { api = { events = {} } }
|
||||
|
||||
---@enum nvim_tree.api.events.Event
|
||||
nvim_tree.api.events.Event = {
|
||||
Ready = "Ready",
|
||||
WillRenameNode = "WillRenameNode",
|
||||
NodeRenamed = "NodeRenamed",
|
||||
TreePreOpen = "TreePreOpen",
|
||||
TreeOpen = "TreeOpen",
|
||||
TreeClose = "TreeClose",
|
||||
WillCreateFile = "WillCreateFile",
|
||||
FileCreated = "FileCreated",
|
||||
WillRemoveFile = "WillRemoveFile",
|
||||
FileRemoved = "FileRemoved",
|
||||
FolderCreated = "FolderCreated",
|
||||
FolderRemoved = "FolderRemoved",
|
||||
Resize = "Resize",
|
||||
TreeAttachedPost = "TreeAttachedPost",
|
||||
TreeRendered = "TreeRendered",
|
||||
}
|
||||
|
||||
---
|
||||
---Register a handler for an event, see [nvim-tree-events].
|
||||
---
|
||||
---@param event_type string [nvim_tree_events_kind]
|
||||
---@param event_type nvim_tree.api.events.Event [nvim_tree_events_kind]
|
||||
---@param callback fun(payload: table?)
|
||||
function nvim_tree.api.events.subscribe(event_type, callback) end
|
||||
|
||||
|
||||
@@ -59,13 +59,25 @@ function nvim_tree.api.fs.create(node) end
|
||||
function nvim_tree.api.fs.cut(node) end
|
||||
|
||||
---
|
||||
---Paste from the nvim-tree clipboard.
|
||||
---Paste files from:
|
||||
---- current nvim-tree clipboard (if present)
|
||||
---- another nvim-tree instance via system clipboard
|
||||
---
|
||||
---If {node} is a file it will pasted in the parent directory.
|
||||
---
|
||||
---@param node? nvim_tree.api.Node
|
||||
function nvim_tree.api.fs.paste(node) end
|
||||
|
||||
---
|
||||
---Paste while cutting files from:
|
||||
---- current nvim-tree clipboard (if present)
|
||||
---- another nvim-tree instance via system clipboard
|
||||
---
|
||||
---If {node} is a file it will pasted in the parent directory.
|
||||
---
|
||||
---@param node? nvim_tree.api.Node
|
||||
function nvim_tree.api.fs.move(node) end
|
||||
|
||||
---
|
||||
---Print the contents of the nvim-tree clipboard.
|
||||
---
|
||||
|
||||
@@ -4,8 +4,9 @@ local nvim_tree = { api = { marks = {} } }
|
||||
---
|
||||
---Return the node if it is marked.
|
||||
---
|
||||
---@param node? nvim_tree.api.Node file or directory
|
||||
---@return nvim_tree.api.Node?
|
||||
function nvim_tree.api.marks.get() end
|
||||
function nvim_tree.api.marks.get(node) end
|
||||
|
||||
---
|
||||
---Retrieve all marked nodes.
|
||||
|
||||
@@ -16,6 +16,12 @@ nvim_tree.api.node.open = {}
|
||||
---@field focus? boolean
|
||||
|
||||
|
||||
---
|
||||
---Switch to window with selected file if it exists, otherwise open, see [:drop]
|
||||
---
|
||||
---@param node? nvim_tree.api.Node directory or file
|
||||
function nvim_tree.api.node.open.drop(node) end
|
||||
|
||||
---
|
||||
---- file: open as per [nvim_tree.config.actions.open_file]
|
||||
---- directory: expand or collapse
|
||||
@@ -74,7 +80,7 @@ function nvim_tree.api.node.open.replace_tree_buffer(node) end
|
||||
function nvim_tree.api.node.open.tab(node, opts) end
|
||||
|
||||
---
|
||||
---Switch to tab containing window with selected file if it exists. Open file in new tab otherwise.
|
||||
---Switch to tab containing window with selected file if it exists, otherwise open in new tab, see [:drop]
|
||||
---
|
||||
---@param node? nvim_tree.api.Node directory or file
|
||||
function nvim_tree.api.node.open.tab_drop(node) end
|
||||
@@ -83,8 +89,7 @@ function nvim_tree.api.node.open.tab_drop(node) end
|
||||
---Toggle [nvim_tree.config.renderer] {group_empty} for a directory. Needs {group_empty} set.
|
||||
---
|
||||
---@param node? nvim_tree.api.Node directory
|
||||
---@param opts? nvim_tree.api.node.open.Opts optional
|
||||
function nvim_tree.api.node.open.toggle_group_empty(node, opts) end
|
||||
function nvim_tree.api.node.open.toggle_group_empty(node) end
|
||||
|
||||
---
|
||||
---Open file in a new vertical split.
|
||||
@@ -280,7 +285,7 @@ nvim_tree.api.node.run = {}
|
||||
function nvim_tree.api.node.run.cmd(node) end
|
||||
|
||||
---
|
||||
---Execute [nvim_tree.config.system_open].
|
||||
---Open with the system default handler: [vim.ui.open()].
|
||||
---
|
||||
---@param node? nvim_tree.api.Node directory or file
|
||||
function nvim_tree.api.node.run.system(node) end
|
||||
|
||||
@@ -87,9 +87,6 @@ error("Cannot require a meta file")
|
||||
---[nvim_tree.config.update_focused_file]
|
||||
---@field update_focused_file? nvim_tree.config.update_focused_file
|
||||
---
|
||||
---[nvim_tree.config.system_open]
|
||||
---@field system_open? nvim_tree.config.system_open
|
||||
---
|
||||
---[nvim_tree.config.git]
|
||||
---@field git? nvim_tree.config.git
|
||||
---
|
||||
|
||||
@@ -7,16 +7,23 @@ error("Cannot require a meta file")
|
||||
---
|
||||
---With this feature, the tree will be partially updated on specific directory changes, resulting in better performance.
|
||||
---
|
||||
---Watchers may be disabled for absolute directory paths via {ignore_dirs}.
|
||||
--- - A list of [regular-expression] to match a path, backslash escaped e.g. `"my-proj/\\.build$"` OR
|
||||
--- - A function that is passed an absolute path and returns `true` to disable
|
||||
---This may be useful when a path is not in `.gitignore` or git integration is disabled.
|
||||
---Blacklist watching absolute directory paths via {ignore_dirs} and optionally whitelist via {whitelist_dirs}:
|
||||
---- A table of |regular-expression| that will be passed to `vim.fn.match`
|
||||
--- - Backslashes must be escaped e.g. `"my-proj/\\.build$"`
|
||||
--- - Literal backslashes must be double escaped to avoid |/magic| e.g. `"C:\\\\src\\\\my-proj"`
|
||||
---- OR a `fun(path: string): boolean` that is passed an absolute path:
|
||||
--- - {ignore_dirs}: return `true` to disable
|
||||
--- - {whitelist_dirs}: return `true` to enable
|
||||
---
|
||||
---{whitelist_dirs} is STRONGLY recommended for windows: [nvim-tree-os-specific].
|
||||
---
|
||||
---After {max_events} consecutive filesystem events on a single directory with an interval < {debounce_delay}:
|
||||
---- The filesystem watcher will be disabled for that directory.
|
||||
---- A warning notification will be shown.
|
||||
---- Consider adding this directory to {ignore_dirs}
|
||||
---
|
||||
---By default, {max_events} is only enabled for windows.
|
||||
---
|
||||
---@class nvim_tree.config.filesystem_watchers
|
||||
---
|
||||
---(default: `true`)
|
||||
@@ -30,6 +37,10 @@ error("Cannot require a meta file")
|
||||
---(default: `{ "/.ccls-cache", "/build", "/node_modules", "/target", "/.zig-cache"}`)
|
||||
---@field ignore_dirs? string[]|(fun(path: string): boolean)
|
||||
---
|
||||
---Optionally enable only for specific directories.
|
||||
---(default: `{}`)
|
||||
---@field whitelist_dirs? string[]|(fun(path: string): boolean)
|
||||
---
|
||||
---Disable for a single directory after {max_events} consecutive events with an interval < {debounce_delay}.
|
||||
---Set to 0 to allow unlimited consecutive events.
|
||||
---(default: `0` or `1000` on windows)
|
||||
|
||||
@@ -3,7 +3,7 @@ error("Cannot require a meta file")
|
||||
|
||||
|
||||
|
||||
---Filters may be applied to the tree to exlude the display of file/directories.
|
||||
---Filters may be applied to the tree to exclude the display of file/directories.
|
||||
---
|
||||
---Multiple filters may be applied at once.
|
||||
---
|
||||
|
||||
@@ -3,9 +3,14 @@ error("Cannot require a meta file")
|
||||
|
||||
|
||||
|
||||
---{sort_by} [nvim_tree.config.help.sort_by]()
|
||||
---
|
||||
---Sort help entries alphabetically by:
|
||||
---- `"key"`: map lhs
|
||||
---- `"desc"`: description
|
||||
---@alias nvim_tree.config.help.sort_by "key"|"desc"
|
||||
---
|
||||
---@class nvim_tree.config.help
|
||||
---
|
||||
---Alphabetically.
|
||||
---(default: `"key"`)
|
||||
---@field sort_by? "key"|"desc"
|
||||
---@field sort_by? nvim_tree.config.help.sort_by
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
---@meta
|
||||
error("Cannot require a meta file")
|
||||
|
||||
|
||||
|
||||
---Open files or directories via the OS.
|
||||
---
|
||||
---Nvim:
|
||||
---- `>=` 0.10 uses [vim.ui.open()] unless {cmd} is specified
|
||||
---- `<` 0.10 calls external {cmd}:
|
||||
--- - UNIX: `xdg-open`
|
||||
--- - macOS: `open`
|
||||
--- - Windows: `cmd`
|
||||
---
|
||||
---Once nvim-tree minimum Nvim version is updated to 0.10, this configuration will no longer be necessary and will be removed.
|
||||
---
|
||||
---@class nvim_tree.config.system_open
|
||||
---
|
||||
---The open command itself
|
||||
---@field cmd? string
|
||||
---
|
||||
---Optional argument list. Leave empty for OS specific default.
|
||||
---(default: `{}` or `{ "/c", "start", '""' }` on windows)
|
||||
---@field args? string[]
|
||||
@@ -19,7 +19,7 @@ function M.fn(path)
|
||||
end
|
||||
|
||||
-- always match against the real path
|
||||
local path_real = vim.loop.fs_realpath(path)
|
||||
local path_real = vim.uv.fs_realpath(path)
|
||||
if not path_real then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
M.find_file = require("nvim-tree.actions.finders.find-file")
|
||||
M.search_node = require("nvim-tree.actions.finders.search-node")
|
||||
|
||||
return M
|
||||
@@ -25,23 +25,23 @@ local function search(search_dir, input_path)
|
||||
|
||||
local filter_status = explorer.filters:prepare()
|
||||
|
||||
handle, _ = vim.loop.fs_scandir(dir)
|
||||
handle, _ = vim.uv.fs_scandir(dir)
|
||||
if not handle then
|
||||
return
|
||||
end
|
||||
|
||||
realpath, _ = vim.loop.fs_realpath(dir)
|
||||
realpath, _ = vim.uv.fs_realpath(dir)
|
||||
if not realpath or vim.tbl_contains(realpaths_searched, realpath) then
|
||||
return
|
||||
end
|
||||
table.insert(realpaths_searched, realpath)
|
||||
|
||||
name, _ = vim.loop.fs_scandir_next(handle)
|
||||
name, _ = vim.uv.fs_scandir_next(handle)
|
||||
while name do
|
||||
path = dir .. "/" .. name
|
||||
|
||||
---@type uv.fs_stat.result|nil
|
||||
stat, _ = vim.loop.fs_stat(path)
|
||||
stat, _ = vim.uv.fs_stat(path)
|
||||
if not stat then
|
||||
break
|
||||
end
|
||||
@@ -59,7 +59,7 @@ local function search(search_dir, input_path)
|
||||
end
|
||||
end
|
||||
|
||||
name, _ = vim.loop.fs_scandir_next(handle)
|
||||
name, _ = vim.uv.fs_scandir_next(handle)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -74,14 +74,8 @@ function M.fn()
|
||||
-- temporarily set &path
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
|
||||
local path_existed, path_opt
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
path_existed, path_opt = pcall(vim.api.nvim_get_option_value, "path", { buf = bufnr })
|
||||
vim.api.nvim_set_option_value("path", core.get_cwd() .. "/**", { buf = bufnr })
|
||||
else
|
||||
path_existed, path_opt = pcall(vim.api.nvim_buf_get_option, bufnr, "path") ---@diagnostic disable-line: deprecated
|
||||
vim.api.nvim_buf_set_option(bufnr, "path", core.get_cwd() .. "/**") ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
local path_existed, path_opt = pcall(vim.api.nvim_get_option_value, "path", { buf = bufnr })
|
||||
vim.api.nvim_set_option_value("path", core.get_cwd() .. "/**", { buf = bufnr })
|
||||
|
||||
vim.ui.input({ prompt = "Search: ", completion = "file_in_path" }, function(input_path)
|
||||
if not input_path or input_path == "" then
|
||||
@@ -89,17 +83,9 @@ function M.fn()
|
||||
end
|
||||
-- reset &path
|
||||
if path_existed then
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
vim.api.nvim_set_option_value("path", path_opt, { buf = bufnr })
|
||||
else
|
||||
vim.api.nvim_buf_set_option(bufnr, "path", path_opt) ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
vim.api.nvim_set_option_value("path", path_opt, { buf = bufnr })
|
||||
else
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
vim.api.nvim_set_option_value("path", nil, { buf = bufnr })
|
||||
else
|
||||
vim.api.nvim_buf_set_option(bufnr, "path", nil) ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
vim.api.nvim_set_option_value("path", nil, { buf = bufnr })
|
||||
end
|
||||
|
||||
-- strip trailing slash
|
||||
|
||||
@@ -9,6 +9,7 @@ local find_file = require("nvim-tree.actions.finders.find-file").fn
|
||||
|
||||
local Class = require("nvim-tree.classic")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
local FileNode = require("nvim-tree.node.file")
|
||||
local Node = require("nvim-tree.node")
|
||||
|
||||
---@alias ClipboardAction "copy" | "cut"
|
||||
@@ -48,7 +49,7 @@ end
|
||||
---@return boolean
|
||||
---@return string|nil
|
||||
local function do_copy(source, destination)
|
||||
local source_stats, err = vim.loop.fs_stat(source)
|
||||
local source_stats, err = vim.uv.fs_stat(source)
|
||||
|
||||
if not source_stats then
|
||||
log.line("copy_paste", "do_copy fs_stat '%s' failed '%s'", source, err)
|
||||
@@ -64,7 +65,7 @@ local function do_copy(source, destination)
|
||||
|
||||
if source_stats.type == "file" then
|
||||
local success
|
||||
success, err = vim.loop.fs_copyfile(source, destination)
|
||||
success, err = vim.uv.fs_copyfile(source, destination)
|
||||
if not success then
|
||||
log.line("copy_paste", "do_copy fs_copyfile failed '%s'", err)
|
||||
return false, err
|
||||
@@ -72,7 +73,7 @@ local function do_copy(source, destination)
|
||||
return true
|
||||
elseif source_stats.type == "directory" then
|
||||
local handle
|
||||
handle, err = vim.loop.fs_scandir(source)
|
||||
handle, err = vim.uv.fs_scandir(source)
|
||||
if type(handle) == "string" then
|
||||
return false, handle
|
||||
elseif not handle then
|
||||
@@ -81,14 +82,14 @@ local function do_copy(source, destination)
|
||||
end
|
||||
|
||||
local success
|
||||
success, err = vim.loop.fs_mkdir(destination, source_stats.mode)
|
||||
success, err = vim.uv.fs_mkdir(destination, source_stats.mode)
|
||||
if not success then
|
||||
log.line("copy_paste", "do_copy fs_mkdir '%s' failed '%s'", destination, err)
|
||||
return false, err
|
||||
end
|
||||
|
||||
while true do
|
||||
local name, _ = vim.loop.fs_scandir_next(handle)
|
||||
local name, _ = vim.uv.fs_scandir_next(handle)
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
@@ -176,28 +177,40 @@ function Clipboard:bulk_clipboard(nodes, from, to, verb)
|
||||
self.explorer.renderer:draw()
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param node_or_nodes Node|Node[]
|
||||
---@return boolean
|
||||
function Clipboard:is_nodes_array(node_or_nodes)
|
||||
if type(node_or_nodes) == "table" and node_or_nodes.is and node_or_nodes:is(Node) then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
---Copy one or more nodes
|
||||
---@param node_or_nodes Node|Node[]
|
||||
function Clipboard:copy(node_or_nodes)
|
||||
if type(node_or_nodes) == "table" and node_or_nodes.is and node_or_nodes:is(Node) then
|
||||
if self:is_nodes_array(node_or_nodes) == false then
|
||||
utils.array_remove(self.data.cut, node_or_nodes)
|
||||
toggle(node_or_nodes, self.data.copy)
|
||||
self.explorer.renderer:draw()
|
||||
else
|
||||
self:bulk_clipboard(utils.filter_descendant_nodes(node_or_nodes), self.data.cut, self.data.copy, "added to")
|
||||
end
|
||||
self:copy_absolute_path(self.data.copy, { notify = false })
|
||||
end
|
||||
|
||||
---Cut one or more nodes
|
||||
---@param node_or_nodes Node|Node[]
|
||||
function Clipboard:cut(node_or_nodes)
|
||||
if type(node_or_nodes) == "table" and node_or_nodes.is and node_or_nodes:is(Node) then
|
||||
if self:is_nodes_array(node_or_nodes) == false then
|
||||
utils.array_remove(self.data.copy, node_or_nodes)
|
||||
toggle(node_or_nodes, self.data.cut)
|
||||
self.explorer.renderer:draw()
|
||||
else
|
||||
self:bulk_clipboard(utils.filter_descendant_nodes(node_or_nodes), self.data.copy, self.data.cut, "cut to")
|
||||
end
|
||||
self:copy_absolute_path(self.data.cut, { notify = false })
|
||||
end
|
||||
|
||||
---Clear clipboard for action and reload to reflect filesystem changes from paste.
|
||||
@@ -228,7 +241,7 @@ function Clipboard:resolve_conflicts(conflict, destination, action, action_fn)
|
||||
self:finish_paste(action)
|
||||
return
|
||||
end
|
||||
if vim.loop.fs_stat(new_dest) then
|
||||
if vim.uv.fs_stat(new_dest) then
|
||||
self:resolve_conflicts({ { node = conflict[1].node, dest = new_dest } }, destination, action, action_fn)
|
||||
else
|
||||
do_paste_one(source, new_dest, action, action_fn)
|
||||
@@ -285,7 +298,7 @@ function Clipboard:resolve_conflicts(conflict, destination, action, action_fn)
|
||||
local extension = vim.fn.fnamemodify(item.node.name, ":e")
|
||||
local new_name = extension ~= "" and (basename .. suffix .. "." .. extension) or (item.node.name .. suffix)
|
||||
local new_dest = utils.path_join({ destination, new_name })
|
||||
local stats = vim.loop.fs_stat(new_dest)
|
||||
local stats = vim.uv.fs_stat(new_dest)
|
||||
if stats then
|
||||
table.insert(still_conflict, { node = item.node, dest = new_dest })
|
||||
else
|
||||
@@ -304,6 +317,40 @@ function Clipboard:resolve_conflicts(conflict, destination, action, action_fn)
|
||||
end)
|
||||
end
|
||||
|
||||
--- Transforms the copied absolute paths on register to node
|
||||
---@private
|
||||
function Clipboard:get_nodes_from_reg()
|
||||
local content = vim.fn.getreg(self.reg)
|
||||
|
||||
if #content == 0 then
|
||||
return {}
|
||||
end
|
||||
|
||||
local nodes = {}
|
||||
local absolute_paths = vim.split(content:sub(1, #content), "\n")
|
||||
|
||||
for _, absolute_path in ipairs(absolute_paths) do
|
||||
if absolute_path:match("^%s*(.-)%s*s") then
|
||||
local node_args = { absolute_path = absolute_path, name = vim.fn.fnamemodify(absolute_path, ":t"), explorer = self.explorer }
|
||||
if absolute_path:sub(-1) == "/" then
|
||||
node_args.name = vim.fn.fnamemodify(absolute_path:sub(1, -2), ":t")
|
||||
table.insert(nodes, DirectoryNode(node_args))
|
||||
else
|
||||
table.insert(nodes, FileNode(node_args))
|
||||
end
|
||||
end
|
||||
end
|
||||
return nodes
|
||||
end
|
||||
|
||||
---@param nodes Node[]
|
||||
---@private
|
||||
function Clipboard:destroy_nodes(nodes)
|
||||
for _, n in ipairs(nodes) do
|
||||
n:destroy()
|
||||
end
|
||||
end
|
||||
|
||||
---Paste cut or copy with batch conflict resolution.
|
||||
---@private
|
||||
---@param node Node
|
||||
@@ -318,16 +365,21 @@ function Clipboard:do_paste(node, action, action_fn)
|
||||
node = dir:last_group_node()
|
||||
end
|
||||
end
|
||||
local clip = self.data[action]
|
||||
local is_local = #self.data[action] > 0
|
||||
local clip = is_local and self.data[action] or self:get_nodes_from_reg()
|
||||
|
||||
if #clip == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local destination = node.absolute_path
|
||||
local stats, err, err_name = vim.loop.fs_stat(destination)
|
||||
local stats, err, err_name = vim.uv.fs_stat(destination)
|
||||
if not stats and err_name ~= "ENOENT" then
|
||||
log.line("copy_paste", "do_paste fs_stat '%s' failed '%s'", destination, err)
|
||||
notify.error("Could not " .. action .. " " .. notify.render_path(destination) .. " - " .. (err or "???"))
|
||||
if is_local == false then
|
||||
self:destroy_nodes(clip)
|
||||
end
|
||||
return
|
||||
end
|
||||
local is_dir = stats and stats.type == "directory"
|
||||
@@ -340,7 +392,7 @@ function Clipboard:do_paste(node, action, action_fn)
|
||||
local conflict = {}
|
||||
for _, _node in ipairs(clip) do
|
||||
local dest = utils.path_join({ destination, _node.name })
|
||||
local dest_stats = vim.loop.fs_stat(dest)
|
||||
local dest_stats = vim.uv.fs_stat(dest)
|
||||
if dest_stats then
|
||||
table.insert(conflict, { node = _node, dest = dest })
|
||||
else
|
||||
@@ -359,6 +411,10 @@ function Clipboard:do_paste(node, action, action_fn)
|
||||
else
|
||||
self:finish_paste(action)
|
||||
end
|
||||
|
||||
if is_local == false then
|
||||
self:destroy_nodes(clip)
|
||||
end
|
||||
end
|
||||
|
||||
---@param source string
|
||||
@@ -374,7 +430,7 @@ local function do_cut(source, destination)
|
||||
end
|
||||
|
||||
events._dispatch_will_rename_node(source, destination)
|
||||
local success, errmsg = vim.loop.fs_rename(source, destination)
|
||||
local success, errmsg = vim.uv.fs_rename(source, destination)
|
||||
if not success then
|
||||
log.line("copy_paste", "do_cut fs_rename failed '%s'", errmsg)
|
||||
return false, errmsg
|
||||
@@ -386,10 +442,12 @@ end
|
||||
|
||||
---Paste cut (if present) or copy (if present)
|
||||
---@param node Node
|
||||
function Clipboard:paste(node)
|
||||
if self.data.cut[1] ~= nil then
|
||||
---@param opts? { cut?: boolean }
|
||||
function Clipboard:paste(node, opts)
|
||||
opts = opts and opts or {}
|
||||
if self.data.cut[1] ~= nil or opts.cut == true then
|
||||
self:do_paste(node, "cut", do_cut)
|
||||
elseif self.data.copy[1] ~= nil then
|
||||
else
|
||||
self:do_paste(node, "copy", do_copy)
|
||||
end
|
||||
end
|
||||
@@ -413,17 +471,15 @@ function Clipboard:print_clipboard()
|
||||
end
|
||||
|
||||
---@param content string
|
||||
function Clipboard:copy_to_reg(content)
|
||||
-- manually firing TextYankPost does not set vim.v.event
|
||||
-- workaround: create a scratch buffer with the clipboard contents and send a yank command
|
||||
local temp_buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_text(temp_buf, 0, 0, 0, 0, { content })
|
||||
vim.api.nvim_buf_call(temp_buf, function()
|
||||
vim.cmd(string.format('normal! "%sy$', self.reg))
|
||||
end)
|
||||
vim.api.nvim_buf_delete(temp_buf, {})
|
||||
---@param message? string
|
||||
---@param opts? { notify?: boolean }
|
||||
function Clipboard:copy_to_reg(content, message, opts)
|
||||
opts = opts and opts or {}
|
||||
vim.fn.setreg(self.reg, type(content) == "table" and content or { content }, "v")
|
||||
|
||||
notify.info(string.format("Copied %s to %s clipboard!", content, self.clipboard_name))
|
||||
if opts.notify ~= false then
|
||||
notify.info(message or string.format("Copied %s to %s clipboard!", content, self.clipboard_name))
|
||||
end
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
@@ -437,18 +493,20 @@ function Clipboard:copy_filename(node)
|
||||
end
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param node Node
|
||||
function Clipboard:copy_basename(node)
|
||||
---@return string
|
||||
function Clipboard:get_absolute_path(node)
|
||||
if node.name == ".." then
|
||||
-- root
|
||||
self:copy_to_reg(vim.fn.fnamemodify(self.explorer.absolute_path, ":t:r"))
|
||||
else
|
||||
-- node
|
||||
self:copy_to_reg(vim.fn.fnamemodify(node.name, ":r"))
|
||||
node = self.explorer
|
||||
end
|
||||
|
||||
local absolute_path = node.absolute_path
|
||||
return node.nodes ~= nil and utils.path_add_trailing(absolute_path) or absolute_path
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
---@return string|nil
|
||||
function Clipboard:copy_path(node)
|
||||
if node.name == ".." then
|
||||
-- root
|
||||
@@ -470,15 +528,44 @@ function Clipboard:copy_path(node)
|
||||
end
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function Clipboard:copy_absolute_path(node)
|
||||
if node.name == ".." then
|
||||
node = self.explorer
|
||||
---@param node_or_nodes Node|Node[]
|
||||
---@param opts? { notify?: boolean }
|
||||
function Clipboard:copy_absolute_path(node_or_nodes, opts)
|
||||
opts = opts and opts or {}
|
||||
local content
|
||||
|
||||
local is_single = self:is_nodes_array(node_or_nodes) == false
|
||||
if is_single then
|
||||
local node = #node_or_nodes == 1 and node_or_nodes[0] or node_or_nodes
|
||||
content = self:get_absolute_path(node)
|
||||
else
|
||||
node_or_nodes = utils.filter_descendant_nodes(node_or_nodes)
|
||||
content = {}
|
||||
for _, node in ipairs(node_or_nodes) do
|
||||
table.insert(content, self:get_absolute_path(node))
|
||||
end
|
||||
end
|
||||
|
||||
local absolute_path = node.absolute_path
|
||||
local content = node.nodes ~= nil and utils.path_add_trailing(absolute_path) or absolute_path
|
||||
self:copy_to_reg(content)
|
||||
|
||||
if content ~= nil then
|
||||
local message = nil
|
||||
|
||||
if not is_single then
|
||||
message = string.format("%s %s copied to register", #content, #content > 1 and "absolute paths" or "absolute path")
|
||||
end
|
||||
self:copy_to_reg(content, message, opts)
|
||||
end
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function Clipboard:copy_basename(node)
|
||||
if node.name == ".." then
|
||||
-- root
|
||||
self:copy_to_reg(vim.fn.fnamemodify(node.explorer.absolute_path, ":t:r"))
|
||||
else
|
||||
-- node
|
||||
self:copy_to_reg(vim.fn.fnamemodify(node.name, ":r"))
|
||||
end
|
||||
end
|
||||
|
||||
---Node is cut. Will not be copied.
|
||||
|
||||
@@ -13,12 +13,12 @@ local M = {}
|
||||
---@param file string
|
||||
local function create_and_notify(file)
|
||||
events._dispatch_will_create_file(file)
|
||||
local ok, fd = pcall(vim.loop.fs_open, file, "w", 420)
|
||||
local ok, fd = pcall(vim.uv.fs_open, file, "w", 420)
|
||||
if not ok or type(fd) ~= "number" then
|
||||
notify.error("Couldn't create file " .. notify.render_path(file))
|
||||
return
|
||||
end
|
||||
vim.loop.fs_close(fd)
|
||||
vim.uv.fs_close(fd)
|
||||
events._dispatch_file_created(file)
|
||||
end
|
||||
|
||||
@@ -84,7 +84,7 @@ function M.fn(node)
|
||||
if is_last_path_file and idx == num_nodes then
|
||||
create_and_notify(path_to_create)
|
||||
elseif not utils.file_exists(path_to_create) then
|
||||
local success = vim.loop.fs_mkdir(path_to_create, 493)
|
||||
local success = vim.uv.fs_mkdir(path_to_create, 493)
|
||||
if not success then
|
||||
notify.error("Could not create folder " .. notify.render_path(path_to_create))
|
||||
is_error = true
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
M.create_file = require("nvim-tree.actions.fs.create-file")
|
||||
M.remove_file = require("nvim-tree.actions.fs.remove-file")
|
||||
M.rename_file = require("nvim-tree.actions.fs.rename-file")
|
||||
M.trash = require("nvim-tree.actions.fs.trash")
|
||||
|
||||
function M.setup(opts)
|
||||
M.remove_file.setup(opts)
|
||||
M.rename_file.setup(opts)
|
||||
M.trash.setup(opts)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,9 +1,9 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local events = require("nvim-tree.events")
|
||||
local view = require("nvim-tree.view")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local notify = require("nvim-tree.notify")
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local DirectoryLinkNode = require("nvim-tree.node.directory-link")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
@@ -18,7 +18,7 @@ local M = {
|
||||
local function close_windows(windows)
|
||||
-- When floating, prevent closing the last non-floating window.
|
||||
-- For details see #2503, #3187.
|
||||
if view.View.float.enable then
|
||||
if config.g.view.float.enable then
|
||||
local non_float_count = 0
|
||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
||||
if vim.api.nvim_win_get_config(win).relative == "" then
|
||||
@@ -43,15 +43,15 @@ local function clear_buffer(absolute_path)
|
||||
for _, buf in pairs(bufs) do
|
||||
if buf.name == absolute_path then
|
||||
local tree_winnr = vim.api.nvim_get_current_win()
|
||||
if buf.hidden == 0 and (#bufs > 1 or view.View.float.enable) then
|
||||
if buf.hidden == 0 and (#bufs > 1 or config.g.view.float.enable) then
|
||||
vim.api.nvim_set_current_win(buf.windows[1])
|
||||
vim.cmd(":bn")
|
||||
end
|
||||
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
|
||||
if not view.View.float.quit_on_focus_loss then
|
||||
if not config.g.view.float.quit_on_focus_loss then
|
||||
vim.api.nvim_set_current_win(tree_winnr)
|
||||
end
|
||||
if M.config.actions.remove_file.close_window then
|
||||
if config.g.actions.remove_file.close_window then
|
||||
close_windows(buf.windows)
|
||||
end
|
||||
return
|
||||
@@ -62,14 +62,14 @@ end
|
||||
---@param cwd string
|
||||
---@return boolean|nil
|
||||
local function remove_dir(cwd)
|
||||
local handle, err = vim.loop.fs_scandir(cwd)
|
||||
local handle, err = vim.uv.fs_scandir(cwd)
|
||||
if not handle then
|
||||
notify.error(err)
|
||||
return
|
||||
end
|
||||
|
||||
while true do
|
||||
local name, _ = vim.loop.fs_scandir_next(handle)
|
||||
local name, _ = vim.uv.fs_scandir_next(handle)
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
@@ -77,11 +77,11 @@ local function remove_dir(cwd)
|
||||
local new_cwd = utils.path_join({ cwd, name })
|
||||
|
||||
-- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility
|
||||
local stat = vim.loop.fs_stat(new_cwd)
|
||||
local stat = vim.uv.fs_stat(new_cwd)
|
||||
-- TODO remove once 0.12 is the minimum neovim version
|
||||
-- path incorrectly specified as an integer, fixed upstream for neovim 0.12 https://github.com/neovim/neovim/pull/33872
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
local lstat = vim.loop.fs_lstat(new_cwd)
|
||||
local lstat = vim.uv.fs_lstat(new_cwd)
|
||||
|
||||
local type = stat and stat.type or nil
|
||||
-- Checks if file is a link file to ensure deletion of the symlink instead of the file it points to
|
||||
@@ -93,7 +93,7 @@ local function remove_dir(cwd)
|
||||
return false
|
||||
end
|
||||
else
|
||||
local success = vim.loop.fs_unlink(new_cwd)
|
||||
local success = vim.uv.fs_unlink(new_cwd)
|
||||
if not success then
|
||||
return false
|
||||
end
|
||||
@@ -101,7 +101,7 @@ local function remove_dir(cwd)
|
||||
end
|
||||
end
|
||||
|
||||
return vim.loop.fs_rmdir(cwd)
|
||||
return vim.uv.fs_rmdir(cwd)
|
||||
end
|
||||
|
||||
--- Remove a node, notify errors, dispatch events
|
||||
@@ -118,7 +118,7 @@ function M.remove(node)
|
||||
events._dispatch_folder_removed(node.absolute_path)
|
||||
else
|
||||
events._dispatch_will_remove_file(node.absolute_path)
|
||||
local success = vim.loop.fs_unlink(node.absolute_path)
|
||||
local success = vim.uv.fs_unlink(node.absolute_path)
|
||||
if not success then
|
||||
notify.error("Could not remove " .. notify_node)
|
||||
return false
|
||||
@@ -141,18 +141,18 @@ local function remove_one(node)
|
||||
notify.info(notify.render_path(node.absolute_path) .. " was properly removed.")
|
||||
end
|
||||
local explorer = core.get_explorer()
|
||||
if not M.config.filesystem_watchers.enable and explorer then
|
||||
if not config.g.filesystem_watchers.enable and explorer then
|
||||
explorer:reload_explorer()
|
||||
end
|
||||
end
|
||||
|
||||
if M.config.ui.confirm.remove then
|
||||
if config.g.ui.confirm.remove then
|
||||
local prompt_select = "Remove " .. node.name .. "?"
|
||||
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, M.config.ui.confirm.default_yes)
|
||||
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, config.g.ui.confirm.default_yes)
|
||||
|
||||
lib.prompt(prompt_input, prompt_select, items_short, items_long, "nvimtree_remove", function(item_short)
|
||||
utils.clear_prompt()
|
||||
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
|
||||
if item_short == "y" or item_short == (config.g.ui.confirm.default_yes and "") then
|
||||
do_remove()
|
||||
end
|
||||
end)
|
||||
@@ -181,18 +181,18 @@ local function remove_many(nodes)
|
||||
notify.info(string.format("%d nodes properly removed.", removed))
|
||||
end
|
||||
local explorer = core.get_explorer()
|
||||
if not M.config.filesystem_watchers.enable and explorer then
|
||||
if not config.g.filesystem_watchers.enable and explorer then
|
||||
explorer:reload_explorer()
|
||||
end
|
||||
end
|
||||
|
||||
if M.config.ui.confirm.remove then
|
||||
if config.g.ui.confirm.remove then
|
||||
local prompt_select = string.format("Remove %d selected?", #nodes)
|
||||
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, M.config.ui.confirm.default_yes)
|
||||
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, config.g.ui.confirm.default_yes)
|
||||
|
||||
lib.prompt(prompt_input, prompt_select, items_short, items_long, "nvimtree_remove", function(item_short)
|
||||
utils.clear_prompt()
|
||||
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
|
||||
if item_short == "y" or item_short == (config.g.ui.confirm.default_yes and "") then
|
||||
execute()
|
||||
end
|
||||
end)
|
||||
@@ -210,10 +210,4 @@ function M.fn(node_or_nodes)
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config.ui = opts.ui
|
||||
M.config.actions = opts.actions
|
||||
M.config.filesystem_watchers = opts.filesystem_watchers
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -2,6 +2,7 @@ local core = require("nvim-tree.core")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local events = require("nvim-tree.events")
|
||||
local notify = require("nvim-tree.notify")
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local find_file = require("nvim-tree.actions.finders.find-file").fn
|
||||
|
||||
@@ -33,7 +34,7 @@ local function err_fmt(from, to, reason)
|
||||
end
|
||||
|
||||
local function rename_file_exists(node, to)
|
||||
if not utils.is_macos then
|
||||
if not config.os.macos then
|
||||
return utils.file_exists(to)
|
||||
end
|
||||
|
||||
@@ -73,14 +74,14 @@ function M.rename(node, to)
|
||||
|
||||
if idx == num_nodes then
|
||||
events._dispatch_will_rename_node(node.absolute_path, to)
|
||||
local success, err = vim.loop.fs_rename(node.absolute_path, to)
|
||||
local success, err = vim.uv.fs_rename(node.absolute_path, to)
|
||||
|
||||
if not success then
|
||||
notify.warn(err_fmt(notify_from, notify_to, err))
|
||||
return
|
||||
end
|
||||
elseif not rename_file_exists(notify_from, path_to_create) then
|
||||
local success = vim.loop.fs_mkdir(path_to_create, 493)
|
||||
local success = vim.uv.fs_mkdir(path_to_create, 493)
|
||||
if not success then
|
||||
notify.error("Could not create folder " .. notify.render_path(path_to_create))
|
||||
is_error = true
|
||||
@@ -97,85 +98,98 @@ function M.rename(node, to)
|
||||
end
|
||||
end
|
||||
|
||||
---@param default_modifier string|nil
|
||||
---@return fun(node: Node, modifier: string)
|
||||
function M.fn(default_modifier)
|
||||
default_modifier = default_modifier or ":t"
|
||||
|
||||
return function(node, modifier)
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer then
|
||||
return
|
||||
end
|
||||
|
||||
if type(node) ~= "table" then
|
||||
node = explorer:get_node_at_cursor()
|
||||
end
|
||||
if not node then
|
||||
return
|
||||
end
|
||||
|
||||
if type(modifier) ~= "string" then
|
||||
modifier = default_modifier
|
||||
end
|
||||
|
||||
-- support for only specific modifiers have been implemented
|
||||
if not ALLOWED_MODIFIERS[modifier] then
|
||||
notify.warn("Modifier " .. vim.inspect(modifier) .. " is not in allowed list : " .. table.concat(ALLOWED_MODIFIERS, ","))
|
||||
return
|
||||
end
|
||||
|
||||
local dir = node:as(DirectoryNode)
|
||||
if dir then
|
||||
node = dir:last_group_node()
|
||||
end
|
||||
if node.name == ".." then
|
||||
return
|
||||
end
|
||||
|
||||
local namelen = node.name:len()
|
||||
local directory = node.absolute_path:sub(0, namelen * -1 - 1)
|
||||
local default_path
|
||||
local prepend = ""
|
||||
local append = ""
|
||||
default_path = vim.fn.fnamemodify(node.absolute_path, modifier)
|
||||
if modifier:sub(0, 2) == ":t" then
|
||||
prepend = directory
|
||||
end
|
||||
if modifier == ":t:r" then
|
||||
local extension = vim.fn.fnamemodify(node.name, ":e")
|
||||
append = extension:len() == 0 and "" or "." .. extension
|
||||
end
|
||||
if modifier == ":p:h" then
|
||||
default_path = default_path .. "/"
|
||||
end
|
||||
|
||||
local input_opts = {
|
||||
prompt = "Rename to ",
|
||||
default = default_path,
|
||||
completion = "file",
|
||||
}
|
||||
|
||||
vim.ui.input(input_opts, function(new_file_path)
|
||||
utils.clear_prompt()
|
||||
if not new_file_path then
|
||||
return
|
||||
end
|
||||
|
||||
local full_new_path = prepend .. new_file_path .. append
|
||||
|
||||
M.rename(node, full_new_path)
|
||||
if not M.config.filesystem_watchers.enable then
|
||||
explorer:reload_explorer()
|
||||
end
|
||||
|
||||
find_file(utils.path_remove_trailing(full_new_path))
|
||||
end)
|
||||
---@param node Node
|
||||
---@param modifier? string
|
||||
local function prompt_to_rename(node, modifier)
|
||||
if not modifier or type(modifier) ~= "string" then
|
||||
modifier = ":t"
|
||||
end
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer then
|
||||
return
|
||||
end
|
||||
|
||||
if type(node) ~= "table" then
|
||||
local node_at_cursor = explorer:get_node_at_cursor()
|
||||
if not node_at_cursor then
|
||||
return
|
||||
end
|
||||
node = node_at_cursor
|
||||
end
|
||||
|
||||
-- support for only specific modifiers have been implemented
|
||||
if not ALLOWED_MODIFIERS[modifier] then
|
||||
notify.warn("Modifier " .. vim.inspect(modifier) .. " is not in allowed list : " .. table.concat(ALLOWED_MODIFIERS, ","))
|
||||
return
|
||||
end
|
||||
|
||||
local dir = node:as(DirectoryNode)
|
||||
if dir then
|
||||
node = dir:last_group_node()
|
||||
end
|
||||
if node.name == ".." then
|
||||
return
|
||||
end
|
||||
|
||||
local namelen = node.name:len()
|
||||
local directory = node.absolute_path:sub(0, namelen * -1 - 1)
|
||||
local default_path
|
||||
local prepend = ""
|
||||
local append = ""
|
||||
default_path = vim.fn.fnamemodify(node.absolute_path, modifier)
|
||||
if modifier:sub(0, 2) == ":t" then
|
||||
prepend = directory
|
||||
end
|
||||
if modifier == ":t:r" then
|
||||
local extension = vim.fn.fnamemodify(node.name, ":e")
|
||||
append = extension:len() == 0 and "" or "." .. extension
|
||||
end
|
||||
if modifier == ":p:h" then
|
||||
default_path = default_path .. "/"
|
||||
end
|
||||
|
||||
local input_opts = {
|
||||
prompt = "Rename to ",
|
||||
default = default_path,
|
||||
completion = "file",
|
||||
}
|
||||
|
||||
vim.ui.input(input_opts, function(new_file_path)
|
||||
utils.clear_prompt()
|
||||
if not new_file_path then
|
||||
return
|
||||
end
|
||||
|
||||
local full_new_path = prepend .. new_file_path .. append
|
||||
|
||||
M.rename(node, full_new_path)
|
||||
if not config.g.filesystem_watchers.enable then
|
||||
explorer:reload_explorer()
|
||||
end
|
||||
|
||||
find_file(utils.path_remove_trailing(full_new_path))
|
||||
end)
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config.filesystem_watchers = opts.filesystem_watchers
|
||||
---@param node Node
|
||||
function M.rename_node(node)
|
||||
prompt_to_rename(node, ":t")
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.rename_sub(node)
|
||||
prompt_to_rename(node, ":p:h")
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.rename_basename(node)
|
||||
prompt_to_rename(node, ":t:r")
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.rename_full(node)
|
||||
prompt_to_rename(node, ":p")
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -3,6 +3,7 @@ local lib = require("nvim-tree.lib")
|
||||
local notify = require("nvim-tree.notify")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local events = require("nvim-tree.events")
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local DirectoryLinkNode = require("nvim-tree.node.directory-link")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
@@ -32,9 +33,9 @@ end
|
||||
|
||||
---@param node Node
|
||||
function M.remove(node)
|
||||
local binary = M.config.trash.cmd:gsub(" .*$", "")
|
||||
local binary = config.g.trash.cmd:gsub(" .*$", "")
|
||||
if vim.fn.executable(binary) == 0 then
|
||||
notify.warn(string.format("trash.cmd '%s' is not an executable.", M.config.trash.cmd))
|
||||
notify.warn(string.format("trash.cmd '%s' is not an executable.", config.g.trash.cmd))
|
||||
return
|
||||
end
|
||||
|
||||
@@ -45,8 +46,8 @@ function M.remove(node)
|
||||
|
||||
-- trashes a path (file or folder)
|
||||
local function trash_path(on_exit)
|
||||
local need_sync_wait = utils.is_windows
|
||||
local job = vim.fn.jobstart(M.config.trash.cmd .. " " .. vim.fn.shellescape(node.absolute_path), {
|
||||
local need_sync_wait = config.os.windows
|
||||
local job = vim.fn.jobstart(config.g.trash.cmd .. " " .. vim.fn.shellescape(node.absolute_path), {
|
||||
detach = not need_sync_wait,
|
||||
on_exit = on_exit,
|
||||
on_stderr = on_stderr,
|
||||
@@ -65,7 +66,7 @@ function M.remove(node)
|
||||
return
|
||||
end
|
||||
events._dispatch_folder_removed(node.absolute_path)
|
||||
if not M.config.filesystem_watchers.enable and explorer then
|
||||
if not config.g.filesystem_watchers.enable and explorer then
|
||||
explorer:reload_explorer()
|
||||
end
|
||||
end)
|
||||
@@ -78,7 +79,7 @@ function M.remove(node)
|
||||
end
|
||||
events._dispatch_file_removed(node.absolute_path)
|
||||
clear_buffer(node.absolute_path)
|
||||
if not M.config.filesystem_watchers.enable and explorer then
|
||||
if not config.g.filesystem_watchers.enable and explorer then
|
||||
explorer:reload_explorer()
|
||||
end
|
||||
end)
|
||||
@@ -96,13 +97,13 @@ local function trash_one(node)
|
||||
M.remove(node)
|
||||
end
|
||||
|
||||
if M.config.ui.confirm.trash then
|
||||
if config.g.ui.confirm.trash then
|
||||
local prompt_select = "Trash " .. node.name .. "?"
|
||||
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, M.config.ui.confirm.default_yes)
|
||||
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, config.g.ui.confirm.default_yes)
|
||||
|
||||
lib.prompt(prompt_input, prompt_select, items_short, items_long, "nvimtree_trash", function(item_short)
|
||||
utils.clear_prompt()
|
||||
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
|
||||
if item_short == "y" or item_short == (config.g.ui.confirm.default_yes and "") then
|
||||
do_trash()
|
||||
end
|
||||
end)
|
||||
@@ -128,13 +129,13 @@ local function trash_many(nodes)
|
||||
end
|
||||
end
|
||||
|
||||
if M.config.ui.confirm.trash then
|
||||
if config.g.ui.confirm.trash then
|
||||
local prompt_select = string.format("Trash %d selected?", #nodes)
|
||||
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, M.config.ui.confirm.default_yes)
|
||||
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, config.g.ui.confirm.default_yes)
|
||||
|
||||
lib.prompt(prompt_input, prompt_select, items_short, items_long, "nvimtree_trash", function(item_short)
|
||||
utils.clear_prompt()
|
||||
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
|
||||
if item_short == "y" or item_short == (config.g.ui.confirm.default_yes and "") then
|
||||
execute()
|
||||
end
|
||||
end)
|
||||
@@ -152,10 +153,4 @@ function M.fn(node_or_nodes)
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config.ui = opts.ui
|
||||
M.config.trash = opts.trash
|
||||
M.config.filesystem_watchers = opts.filesystem_watchers
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
M.finders = require("nvim-tree.actions.finders")
|
||||
M.fs = require("nvim-tree.actions.fs")
|
||||
M.moves = require("nvim-tree.actions.moves")
|
||||
M.node = require("nvim-tree.actions.node")
|
||||
M.tree = require("nvim-tree.actions.tree")
|
||||
|
||||
function M.setup(opts)
|
||||
M.fs.setup(opts)
|
||||
M.node.setup(opts)
|
||||
M.tree.setup(opts)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,7 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
M.item = require("nvim-tree.actions.moves.item")
|
||||
M.parent = require("nvim-tree.actions.moves.parent")
|
||||
M.sibling = require("nvim-tree.actions.moves.sibling")
|
||||
|
||||
return M
|
||||
@@ -215,32 +215,77 @@ end
|
||||
---@field recurse boolean?
|
||||
|
||||
---@param opts NavigationItemOpts
|
||||
---@return fun()
|
||||
function M.fn(opts)
|
||||
return function()
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer then
|
||||
return
|
||||
end
|
||||
local function item(opts)
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer then
|
||||
return
|
||||
end
|
||||
|
||||
local recurse = false
|
||||
local recurse = false
|
||||
|
||||
-- recurse only valid for git and diag moves.
|
||||
if (opts.what == "git" or opts.what == "diag") and opts.recurse ~= nil then
|
||||
recurse = opts.recurse
|
||||
end
|
||||
-- recurse only valid for git and diag moves.
|
||||
if (opts.what == "git" or opts.what == "diag") and opts.recurse ~= nil then
|
||||
recurse = opts.recurse
|
||||
end
|
||||
|
||||
if not recurse then
|
||||
move(explorer, opts.where, opts.what, opts.skip_gitignored)
|
||||
return
|
||||
end
|
||||
if not recurse then
|
||||
move(explorer, opts.where, opts.what, opts.skip_gitignored)
|
||||
return
|
||||
end
|
||||
|
||||
if opts.where == "next" then
|
||||
move_next_recursive(explorer, opts.what, opts.skip_gitignored)
|
||||
elseif opts.where == "prev" then
|
||||
move_prev_recursive(explorer, opts.what, opts.skip_gitignored)
|
||||
end
|
||||
if opts.where == "next" then
|
||||
move_next_recursive(explorer, opts.what, opts.skip_gitignored)
|
||||
elseif opts.where == "prev" then
|
||||
move_prev_recursive(explorer, opts.what, opts.skip_gitignored)
|
||||
end
|
||||
end
|
||||
|
||||
function M.git_next()
|
||||
item({ where = "next", what = "git" })
|
||||
end
|
||||
|
||||
function M.git_next_skip_gitignored()
|
||||
item({ where = "next", what = "git", skip_gitignored = true })
|
||||
end
|
||||
|
||||
function M.git_next_recursive()
|
||||
item({ where = "next", what = "git", recurse = true })
|
||||
end
|
||||
|
||||
function M.git_prev()
|
||||
item({ where = "prev", what = "git" })
|
||||
end
|
||||
|
||||
function M.git_prev_skip_gitignored()
|
||||
item({ where = "prev", what = "git", skip_gitignored = true })
|
||||
end
|
||||
|
||||
function M.git_prev_recursive()
|
||||
item({ where = "prev", what = "git", recurse = true })
|
||||
end
|
||||
|
||||
function M.diagnostics_next()
|
||||
item({ where = "next", what = "diag" })
|
||||
end
|
||||
|
||||
function M.diagnostics_next_recursive()
|
||||
item({ where = "next", what = "diag", recurse = true })
|
||||
end
|
||||
|
||||
function M.diagnostics_prev()
|
||||
item({ where = "prev", what = "diag" })
|
||||
end
|
||||
|
||||
function M.diagnostics_prev_recursive()
|
||||
item({ where = "prev", what = "diag", recurse = true })
|
||||
end
|
||||
|
||||
function M.opened_next()
|
||||
item({ where = "next", what = "opened" })
|
||||
end
|
||||
|
||||
function M.opened_prev()
|
||||
item({ where = "prev", what = "opened" })
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -3,40 +3,45 @@ local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
local M = {}
|
||||
|
||||
---@param should_close boolean|nil
|
||||
---@return fun(node: Node): boolean|nil
|
||||
function M.fn(should_close)
|
||||
should_close = should_close or false
|
||||
|
||||
---@param node Node
|
||||
return function(node)
|
||||
local dir = node:as(DirectoryNode)
|
||||
if dir then
|
||||
dir = dir:last_group_node()
|
||||
if should_close and dir.open then
|
||||
dir.open = false
|
||||
dir.explorer.renderer:draw()
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local parent = (node:get_parent_of_group() or node).parent
|
||||
|
||||
if not parent or not parent.parent then
|
||||
view.set_cursor({ 1, 0 })
|
||||
---@param node Node
|
||||
---@param should_close boolean
|
||||
local function move(node, should_close)
|
||||
local dir = node:as(DirectoryNode)
|
||||
if dir then
|
||||
dir = dir:last_group_node()
|
||||
if should_close and dir.open then
|
||||
dir.open = false
|
||||
dir.explorer.renderer:draw()
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local _, line = parent.explorer:find_node(function(n)
|
||||
return n.absolute_path == parent.absolute_path
|
||||
end)
|
||||
local parent = (node:get_parent_of_group() or node).parent
|
||||
|
||||
view.set_cursor({ line + 1, 0 })
|
||||
if should_close then
|
||||
parent.open = false
|
||||
parent.explorer.renderer:draw()
|
||||
end
|
||||
if not parent or not parent.parent then
|
||||
view.set_cursor({ 1, 0 })
|
||||
return
|
||||
end
|
||||
|
||||
local _, line = parent.explorer:find_node(function(n)
|
||||
return n.absolute_path == parent.absolute_path
|
||||
end)
|
||||
|
||||
view.set_cursor({ line + 1, 0 })
|
||||
if should_close then
|
||||
parent.open = false
|
||||
parent.explorer.renderer:draw()
|
||||
end
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.move(node)
|
||||
move(node, false)
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.move_close(node)
|
||||
move(node, true)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -3,55 +3,73 @@ local Iterator = require("nvim-tree.iterators.node-iterator")
|
||||
|
||||
local M = {}
|
||||
|
||||
---@param direction string
|
||||
---@return fun(node: Node): nil
|
||||
function M.fn(direction)
|
||||
return function(node)
|
||||
if node.name == ".." or not direction then
|
||||
return
|
||||
end
|
||||
---@param node Node
|
||||
---@param direction "next"|"prev"|"first"|"last"
|
||||
local function move(node, direction)
|
||||
if node.name == ".." or not direction then
|
||||
return
|
||||
end
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer then
|
||||
return
|
||||
end
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer then
|
||||
return
|
||||
end
|
||||
|
||||
local first, last, next, prev = nil, nil, nil, nil
|
||||
local found = false
|
||||
local parent = node.parent or explorer
|
||||
Iterator.builder(parent and parent.nodes or {})
|
||||
:recursor(function()
|
||||
return nil
|
||||
end)
|
||||
:applier(function(n)
|
||||
first = first or n
|
||||
last = n
|
||||
if n.absolute_path == node.absolute_path then
|
||||
found = true
|
||||
return
|
||||
end
|
||||
prev = not found and n or prev
|
||||
if found and not next then
|
||||
next = n
|
||||
end
|
||||
end)
|
||||
:iterate()
|
||||
local first, last, next, prev = nil, nil, nil, nil
|
||||
local found = false
|
||||
local parent = node.parent or explorer
|
||||
Iterator.builder(parent and parent.nodes or {})
|
||||
:recursor(function()
|
||||
return nil
|
||||
end)
|
||||
:applier(function(n)
|
||||
first = first or n
|
||||
last = n
|
||||
if n.absolute_path == node.absolute_path then
|
||||
found = true
|
||||
return
|
||||
end
|
||||
prev = not found and n or prev
|
||||
if found and not next then
|
||||
next = n
|
||||
end
|
||||
end)
|
||||
:iterate()
|
||||
|
||||
local target_node
|
||||
if direction == "first" then
|
||||
target_node = first
|
||||
elseif direction == "last" then
|
||||
target_node = last
|
||||
elseif direction == "next" then
|
||||
target_node = next or first
|
||||
else
|
||||
target_node = prev or last
|
||||
end
|
||||
local target_node
|
||||
if direction == "first" then
|
||||
target_node = first
|
||||
elseif direction == "last" then
|
||||
target_node = last
|
||||
elseif direction == "next" then
|
||||
target_node = next or first
|
||||
else
|
||||
target_node = prev or last
|
||||
end
|
||||
|
||||
if target_node then
|
||||
explorer:focus_node_or_parent(target_node)
|
||||
end
|
||||
if target_node then
|
||||
explorer:focus_node_or_parent(target_node)
|
||||
end
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.next(node)
|
||||
move(node, "next")
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.prev(node)
|
||||
move(node, "prev")
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.first(node)
|
||||
move(node, "first")
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.last(node)
|
||||
move(node, "last")
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local utils = require("nvim-tree.utils")
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -38,7 +39,7 @@ local function setup_window(node)
|
||||
local max_width = vim.fn.max(vim.tbl_map(function(n)
|
||||
return #n
|
||||
end, lines))
|
||||
local open_win_config = vim.tbl_extend("force", M.open_win_config, {
|
||||
local open_win_config = vim.tbl_extend("force", config.g.actions.file_popup.open_win_config, {
|
||||
width = max_width + 1,
|
||||
height = #lines,
|
||||
noautocmd = true,
|
||||
@@ -89,8 +90,4 @@ function M.toggle_file_info(node)
|
||||
})
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.open_win_config = opts.actions.file_popup.open_win_config
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
M.file_popup = require("nvim-tree.actions.node.file-popup")
|
||||
M.open_file = require("nvim-tree.actions.node.open-file")
|
||||
M.run_command = require("nvim-tree.actions.node.run-command")
|
||||
M.system_open = require("nvim-tree.actions.node.system-open")
|
||||
M.buffer = require("nvim-tree.actions.node.buffer")
|
||||
|
||||
function M.setup(opts)
|
||||
require("nvim-tree.actions.node.system-open").setup(opts)
|
||||
require("nvim-tree.actions.node.file-popup").setup(opts)
|
||||
require("nvim-tree.actions.node.open-file").setup(opts)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -4,6 +4,13 @@ local notify = require("nvim-tree.notify")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local full_name = require("nvim-tree.renderer.components.full-name")
|
||||
local view = require("nvim-tree.view")
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
local FileLinkNode = require("nvim-tree.node.file-link")
|
||||
local RootNode = require("nvim-tree.node.root")
|
||||
|
||||
---@alias NodeOpenFileMode ""|"change_dir"|"drop"|"edit"|"edit_in_place"|"edit_no_picker"|"preview"|"preview_no_picker"|"split"|"split_no_picker"|"tab_drop"|"tabnew"|"toggle_group_empty"|"vsplit"|"vsplit_no_picker"
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -26,13 +33,8 @@ local function usable_win_ids()
|
||||
|
||||
return vim.tbl_filter(function(id)
|
||||
local bufid = vim.api.nvim_win_get_buf(id)
|
||||
for option, v in pairs(M.window_picker.exclude) do
|
||||
local ok, option_value
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
ok, option_value = pcall(vim.api.nvim_get_option_value, option, { buf = bufid })
|
||||
else
|
||||
ok, option_value = pcall(vim.api.nvim_buf_get_option, bufid, option) ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
for option, v in pairs(config.g.actions.open_file.window_picker.exclude) do
|
||||
local ok, option_value = pcall(vim.api.nvim_get_option_value, option, { buf = bufid })
|
||||
|
||||
if ok and vim.tbl_contains(v, option_value) then
|
||||
return false
|
||||
@@ -64,8 +66,9 @@ local function pick_win_id()
|
||||
return selectable[1]
|
||||
end
|
||||
|
||||
if #M.window_picker.chars < #selectable then
|
||||
notify.error(string.format("More windows (%d) than actions.open_file.window_picker.chars (%d).", #selectable, #M.window_picker.chars))
|
||||
if #config.g.actions.open_file.window_picker.chars < #selectable then
|
||||
notify.error(string.format("More windows (%d) than actions.open_file.window_picker.chars (%d).", #selectable,
|
||||
#config.g.actions.open_file.window_picker.chars))
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -93,39 +96,23 @@ local function pick_win_id()
|
||||
|
||||
if laststatus == 3 then
|
||||
for _, win_id in ipairs(not_selectable) do
|
||||
local ok_status, statusline
|
||||
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
ok_status, statusline = pcall(vim.api.nvim_get_option_value, "statusline", { win = win_id })
|
||||
else
|
||||
ok_status, statusline = pcall(vim.api.nvim_win_get_option, win_id, "statusline") ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
local ok_status, statusline = pcall(vim.api.nvim_get_option_value, "statusline", { win = win_id })
|
||||
|
||||
win_opts_unselectable[win_id] = {
|
||||
statusline = ok_status and statusline or "",
|
||||
}
|
||||
|
||||
-- Clear statusline for windows not selectable
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
vim.api.nvim_set_option_value("statusline", " ", { win = win_id })
|
||||
else
|
||||
vim.api.nvim_win_set_option(win_id, "statusline", " ") ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
vim.api.nvim_set_option_value("statusline", " ", { win = win_id })
|
||||
end
|
||||
end
|
||||
|
||||
-- Setup UI
|
||||
for _, id in ipairs(selectable) do
|
||||
local char = M.window_picker.chars:sub(i, i)
|
||||
local char = config.g.actions.open_file.window_picker.chars:sub(i, i)
|
||||
|
||||
local ok_status, statusline, ok_hl, winhl
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
ok_status, statusline = pcall(vim.api.nvim_get_option_value, "statusline", { win = id })
|
||||
ok_hl, winhl = pcall(vim.api.nvim_get_option_value, "winhl", { win = id })
|
||||
else
|
||||
ok_status, statusline = pcall(vim.api.nvim_win_get_option, id, "statusline") ---@diagnostic disable-line: deprecated
|
||||
ok_hl, winhl = pcall(vim.api.nvim_win_get_option, id, "winhl") ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
local ok_status, statusline = pcall(vim.api.nvim_get_option_value, "statusline", { win = id })
|
||||
local ok_hl, winhl = pcall(vim.api.nvim_get_option_value, "winhl", { win = id })
|
||||
|
||||
win_opts_selectable[id] = {
|
||||
statusline = ok_status and statusline or "",
|
||||
@@ -133,16 +120,11 @@ local function pick_win_id()
|
||||
}
|
||||
win_map[char] = id
|
||||
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
vim.api.nvim_set_option_value("statusline", "%=" .. char .. "%=", { win = id })
|
||||
vim.api.nvim_set_option_value("winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker", { win = id })
|
||||
else
|
||||
vim.api.nvim_win_set_option(id, "statusline", "%=" .. char .. "%=") ---@diagnostic disable-line: deprecated
|
||||
vim.api.nvim_win_set_option(id, "winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker") ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
vim.api.nvim_set_option_value("statusline", "%=" .. char .. "%=", { win = id })
|
||||
vim.api.nvim_set_option_value("winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker", { win = id })
|
||||
|
||||
i = i + 1
|
||||
if i > #M.window_picker.chars then
|
||||
if i > #config.g.actions.open_file.window_picker.chars then
|
||||
break
|
||||
end
|
||||
end
|
||||
@@ -158,11 +140,7 @@ local function pick_win_id()
|
||||
-- Restore window options
|
||||
for _, id in ipairs(selectable) do
|
||||
for opt, value in pairs(win_opts_selectable[id]) do
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
vim.api.nvim_set_option_value(opt, value, { win = id })
|
||||
else
|
||||
vim.api.nvim_win_set_option(id, opt, value) ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
vim.api.nvim_set_option_value(opt, value, { win = id })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -171,11 +149,7 @@ local function pick_win_id()
|
||||
-- Ensure window still exists at this point
|
||||
if vim.api.nvim_win_is_valid(id) then
|
||||
for opt, value in pairs(win_opts_unselectable[id]) do
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
vim.api.nvim_set_option_value(opt, value, { win = id })
|
||||
else
|
||||
vim.api.nvim_win_set_option(id, opt, value) ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
vim.api.nvim_set_option_value(opt, value, { win = id })
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -184,7 +158,7 @@ local function pick_win_id()
|
||||
vim.o.laststatus = laststatus
|
||||
vim.opt.fillchars = fillchars
|
||||
|
||||
if not vim.tbl_contains(vim.split(M.window_picker.chars, ""), resp) then
|
||||
if not vim.tbl_contains(vim.split(config.g.actions.open_file.window_picker.chars, ""), resp) then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -192,10 +166,10 @@ local function pick_win_id()
|
||||
end
|
||||
|
||||
local function open_file_in_tab(filename)
|
||||
if M.quit_on_open then
|
||||
if config.g.actions.open_file.quit_on_open then
|
||||
view.close()
|
||||
end
|
||||
if M.relative_path then
|
||||
if config.g.actions.open_file.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
end
|
||||
vim.cmd.tabnew()
|
||||
@@ -210,20 +184,20 @@ local function open_file_in_tab(filename)
|
||||
end
|
||||
|
||||
local function drop(filename)
|
||||
if M.quit_on_open then
|
||||
if config.g.actions.open_file.quit_on_open then
|
||||
view.close()
|
||||
end
|
||||
if M.relative_path then
|
||||
if config.g.actions.open_file.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
end
|
||||
vim.cmd("drop " .. vim.fn.fnameescape(filename))
|
||||
end
|
||||
|
||||
local function tab_drop(filename)
|
||||
if M.quit_on_open then
|
||||
if config.g.actions.open_file.quit_on_open then
|
||||
view.close()
|
||||
end
|
||||
if M.relative_path then
|
||||
if config.g.actions.open_file.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
end
|
||||
vim.cmd("tab :drop " .. vim.fn.fnameescape(filename))
|
||||
@@ -247,7 +221,7 @@ end
|
||||
|
||||
local function get_target_winid(mode)
|
||||
local target_winid
|
||||
if not M.window_picker.enable or string.find(mode, "no_picker") then
|
||||
if not config.g.actions.open_file.window_picker.enable or string.find(mode, "no_picker") then
|
||||
target_winid = lib.target_winid
|
||||
local usable_wins = usable_win_ids()
|
||||
-- first available usable window
|
||||
@@ -260,8 +234,8 @@ local function get_target_winid(mode)
|
||||
end
|
||||
else
|
||||
-- pick a window
|
||||
if type(M.window_picker.picker) == "function" then
|
||||
target_winid = M.window_picker.picker()
|
||||
if type(config.g.actions.open_file.window_picker.picker) == "function" then
|
||||
target_winid = config.g.actions.open_file.window_picker.picker()
|
||||
else
|
||||
target_winid = pick_win_id()
|
||||
end
|
||||
@@ -286,6 +260,8 @@ local function set_current_win_no_autocmd(winid, autocmd)
|
||||
vim.opt.eventignore = eventignore
|
||||
end
|
||||
|
||||
---@param filename string
|
||||
---@param mode NodeOpenFileMode
|
||||
local function open_in_new_window(filename, mode)
|
||||
if type(mode) ~= "string" then
|
||||
mode = ""
|
||||
@@ -303,13 +279,13 @@ local function open_in_new_window(filename, mode)
|
||||
|
||||
-- non-floating, non-nvim-tree windows
|
||||
local win_ids = vim.tbl_filter(function(id)
|
||||
local config = vim.api.nvim_win_get_config(id)
|
||||
local win_config = vim.api.nvim_win_get_config(id)
|
||||
local bufnr = vim.api.nvim_win_get_buf(id)
|
||||
return config and config.relative == "" or utils.is_nvim_tree_buf(bufnr)
|
||||
return win_config and win_config.relative == "" or utils.is_nvim_tree_buf(bufnr)
|
||||
end, vim.api.nvim_list_wins())
|
||||
|
||||
local create_new_window = #win_ids == 1 -- This implies that the nvim-tree window is the only one
|
||||
local new_window_side = (view.View.side == "right") and "aboveleft" or "belowright"
|
||||
local new_window_side = (config.g.view.side == "right") and "aboveleft" or "belowright"
|
||||
|
||||
-- Target is invalid: create new window
|
||||
if not vim.tbl_contains(win_ids, target_winid) then
|
||||
@@ -327,12 +303,7 @@ local function open_in_new_window(filename, mode)
|
||||
-- modified, and create new split if it is.
|
||||
local target_bufid = vim.api.nvim_win_get_buf(target_winid)
|
||||
|
||||
local modified
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
modified = vim.api.nvim_get_option_value("modified", { buf = target_bufid })
|
||||
else
|
||||
modified = vim.api.nvim_buf_get_option(target_bufid, "modified") ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
local modified = vim.api.nvim_get_option_value("modified", { buf = target_bufid })
|
||||
|
||||
if modified then
|
||||
if not mode:match("split$") then
|
||||
@@ -341,7 +312,7 @@ local function open_in_new_window(filename, mode)
|
||||
end
|
||||
end
|
||||
|
||||
if (mode == "preview" or mode == "preview_no_picker") and view.View.float.enable then
|
||||
if (mode == "preview" or mode == "preview_no_picker") and config.g.view.float.enable then
|
||||
-- ignore "WinLeave" autocmd on preview
|
||||
-- because the registered "WinLeave"
|
||||
-- will kill the floating window immediately
|
||||
@@ -351,7 +322,7 @@ local function open_in_new_window(filename, mode)
|
||||
end
|
||||
|
||||
local fname
|
||||
if M.relative_path then
|
||||
if config.g.actions.open_file.relative_path then
|
||||
fname = utils.escape_special_chars(vim.fn.fnameescape(utils.path_relative(filename, vim.fn.getcwd())))
|
||||
else
|
||||
fname = utils.escape_special_chars(vim.fn.fnameescape(filename))
|
||||
@@ -382,13 +353,13 @@ end
|
||||
|
||||
local function edit_in_current_buf(filename)
|
||||
require("nvim-tree.view").abandon_current_window()
|
||||
if M.relative_path then
|
||||
if config.g.actions.open_file.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
end
|
||||
vim.cmd("keepalt keepjumps edit " .. vim.fn.fnameescape(filename))
|
||||
end
|
||||
|
||||
---@param mode string
|
||||
---@param mode NodeOpenFileMode
|
||||
---@param filename string
|
||||
---@return nil
|
||||
function M.fn(mode, filename)
|
||||
@@ -426,7 +397,7 @@ function M.fn(mode, filename)
|
||||
vim.bo.bufhidden = ""
|
||||
end
|
||||
|
||||
if M.resize_window then
|
||||
if config.g.actions.open_file.resize_window then
|
||||
view.resize()
|
||||
end
|
||||
|
||||
@@ -434,19 +405,131 @@ function M.fn(mode, filename)
|
||||
return on_preview(buf_loaded)
|
||||
end
|
||||
|
||||
if M.quit_on_open then
|
||||
if config.g.actions.open_file.quit_on_open then
|
||||
view.close()
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.quit_on_open = opts.actions.open_file.quit_on_open
|
||||
M.resize_window = opts.actions.open_file.resize_window
|
||||
M.relative_path = opts.actions.open_file.relative_path
|
||||
if opts.actions.open_file.window_picker.chars then
|
||||
opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper()
|
||||
---@param mode string
|
||||
---@param node Node
|
||||
---@param edit_opts nvim_tree.api.node.open.Opts?
|
||||
local function edit(mode, node, edit_opts)
|
||||
local file_link = node:as(FileLinkNode)
|
||||
local path = file_link and file_link.link_to or node.absolute_path
|
||||
local cur_tabpage = vim.api.nvim_get_current_tabpage()
|
||||
|
||||
M.fn(mode, path)
|
||||
|
||||
edit_opts = edit_opts or {}
|
||||
|
||||
local mode_unsupported_quit_on_open = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
|
||||
if not mode_unsupported_quit_on_open and edit_opts.quit_on_open then
|
||||
view.close(cur_tabpage)
|
||||
end
|
||||
M.window_picker = opts.actions.open_file.window_picker
|
||||
|
||||
local mode_unsupported_focus = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
|
||||
local focus = edit_opts.focus == nil or edit_opts.focus == false
|
||||
if not mode_unsupported_focus and not focus then
|
||||
-- if mode == "tabnew" a new tab will be opened and we need to focus back to the previous tab
|
||||
if mode == "tabnew" then
|
||||
vim.cmd(":tabprev")
|
||||
end
|
||||
view.focus()
|
||||
end
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
---@param mode NodeOpenFileMode
|
||||
---@param toggle_group boolean?
|
||||
---@param edit_opts nvim_tree.api.node.open.Opts?
|
||||
local function open_or_expand_or_dir_up(node, mode, toggle_group, edit_opts)
|
||||
local root = node:as(RootNode)
|
||||
local dir = node:as(DirectoryNode)
|
||||
|
||||
if root or node.name == ".." then
|
||||
local explorer = require("nvim-tree.core").get_explorer()
|
||||
if explorer then
|
||||
explorer:change_dir("..")
|
||||
end
|
||||
elseif dir then
|
||||
dir:expand_or_collapse(toggle_group)
|
||||
elseif not toggle_group then
|
||||
edit(mode, node, edit_opts)
|
||||
end
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.toggle_group_empty(node)
|
||||
open_or_expand_or_dir_up(node, "toggle_group_empty", true)
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
---@param opts nvim_tree.api.node.open.Opts?
|
||||
function M.preview(node, opts)
|
||||
open_or_expand_or_dir_up(node, "preview", false, opts)
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
---@param opts nvim_tree.api.node.open.Opts?
|
||||
function M.preview_no_picker(node, opts)
|
||||
open_or_expand_or_dir_up(node, "preview_no_picker", false, opts)
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
---@param opts nvim_tree.api.node.open.Opts?
|
||||
function M.edit(node, opts)
|
||||
open_or_expand_or_dir_up(node, "edit", false, opts)
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.drop(node)
|
||||
open_or_expand_or_dir_up(node, "drop")
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.tab_drop(node)
|
||||
open_or_expand_or_dir_up(node, "tab_drop")
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.replace_tree_buffer(node)
|
||||
open_or_expand_or_dir_up(node, "edit_in_place")
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
---@param opts nvim_tree.api.node.open.Opts?
|
||||
function M.no_window_picker(node, opts)
|
||||
open_or_expand_or_dir_up(node, "edit_no_picker", false, opts)
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
---@param opts nvim_tree.api.node.open.Opts?
|
||||
function M.vertical(node, opts)
|
||||
open_or_expand_or_dir_up(node, "vsplit", false, opts)
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
---@param opts nvim_tree.api.node.open.Opts?
|
||||
function M.vertical_no_picker(node, opts)
|
||||
open_or_expand_or_dir_up(node, "vsplit_no_picker", false, opts)
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
---@param opts nvim_tree.api.node.open.Opts?
|
||||
function M.horizontal(node, opts)
|
||||
open_or_expand_or_dir_up(node, "split", false, opts)
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
---@param opts nvim_tree.api.node.open.Opts?
|
||||
function M.horizontal_no_picker(node, opts)
|
||||
open_or_expand_or_dir_up(node, "split_no_picker", false, opts)
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
---@param opts nvim_tree.api.node.open.Opts?
|
||||
function M.tab(node, opts)
|
||||
open_or_expand_or_dir_up(node, "tabnew", false, opts)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,56 +1,9 @@
|
||||
local notify = require("nvim-tree.notify")
|
||||
local utils = require("nvim-tree.utils")
|
||||
|
||||
local M = {}
|
||||
|
||||
---@param node Node
|
||||
local function user(node)
|
||||
if #M.config.system_open.cmd == 0 then
|
||||
require("nvim-tree.utils").notify.warn("Cannot open file with system application. Unrecognized platform.")
|
||||
return
|
||||
end
|
||||
|
||||
local process = {
|
||||
cmd = M.config.system_open.cmd,
|
||||
args = M.config.system_open.args,
|
||||
errors = "\n",
|
||||
stderr = vim.loop.new_pipe(false),
|
||||
}
|
||||
table.insert(process.args, node.link_to or node.absolute_path)
|
||||
|
||||
local opts = {
|
||||
args = process.args,
|
||||
stdio = { nil, nil, process.stderr },
|
||||
detached = true,
|
||||
}
|
||||
|
||||
process.handle, process.pid = vim.loop.spawn(process.cmd, opts, function(code)
|
||||
process.stderr:read_stop()
|
||||
process.stderr:close()
|
||||
process.handle:close()
|
||||
if code ~= 0 then
|
||||
notify.warn(string.format("system_open failed with return code %d: %s", code, process.errors))
|
||||
end
|
||||
end)
|
||||
|
||||
table.remove(process.args)
|
||||
if not process.handle then
|
||||
notify.warn(string.format("system_open failed to spawn command '%s': %s", process.cmd, process.pid))
|
||||
return
|
||||
end
|
||||
vim.loop.read_start(process.stderr, function(err, data)
|
||||
if err then
|
||||
return
|
||||
end
|
||||
if data then
|
||||
process.errors = process.errors .. data
|
||||
end
|
||||
end)
|
||||
vim.loop.unref(process.handle)
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
local function native(node)
|
||||
function M.fn(node)
|
||||
local _, err = vim.ui.open(node.link_to or node.absolute_path)
|
||||
|
||||
-- err only provided on opener executable not found hence logging path is not useful
|
||||
@@ -59,33 +12,4 @@ local function native(node)
|
||||
end
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.fn(node)
|
||||
M.open(node)
|
||||
end
|
||||
|
||||
-- TODO #2430 always use native once 0.10 is the minimum neovim version
|
||||
function M.setup(opts)
|
||||
M.config = {}
|
||||
M.config.system_open = opts.system_open or {}
|
||||
|
||||
if vim.fn.has("nvim-0.10") == 1 and #M.config.system_open.cmd == 0 then
|
||||
M.open = native
|
||||
else
|
||||
M.open = user
|
||||
if #M.config.system_open.cmd == 0 then
|
||||
if utils.is_windows then
|
||||
M.config.system_open = {
|
||||
cmd = "cmd",
|
||||
args = { "/c", "start", '""' },
|
||||
}
|
||||
elseif utils.is_macos then
|
||||
M.config.system_open.cmd = "open"
|
||||
elseif utils.is_unix then
|
||||
M.config.system_open.cmd = "xdg-open"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
19
lua/nvim-tree/actions/tree/change-dir.lua
Normal file
19
lua/nvim-tree/actions/tree/change-dir.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local config = require("nvim-tree.config")
|
||||
local find_file = require("nvim-tree.actions.tree.find-file")
|
||||
|
||||
local M = {}
|
||||
|
||||
---@param name? string
|
||||
function M.fn(name)
|
||||
local explorer = core.get_explorer()
|
||||
if name and explorer then
|
||||
explorer:change_dir(name)
|
||||
end
|
||||
|
||||
if config.g.update_focused_file.update_root.enable then
|
||||
find_file.fn()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
68
lua/nvim-tree/actions/tree/change-root.lua
Normal file
68
lua/nvim-tree/actions/tree/change-root.lua
Normal file
@@ -0,0 +1,68 @@
|
||||
local utils = require("nvim-tree.utils")
|
||||
local core = require("nvim-tree.core")
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local M = {}
|
||||
|
||||
--- Update the tree root to a directory or the directory containing
|
||||
---@param path string relative or absolute
|
||||
---@param bufnr number|nil
|
||||
function M.fn(path, bufnr)
|
||||
-- skip if current file is in ignore_list
|
||||
if type(bufnr) == "number" then
|
||||
local ft = vim.api.nvim_get_option_value("filetype", { buf = bufnr }) or ""
|
||||
|
||||
for _, value in pairs(config.g.update_focused_file.update_root.ignore_list) do
|
||||
if utils.str_find(path, value) or utils.str_find(ft, value) then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- don't find inexistent
|
||||
if vim.fn.filereadable(path) == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local cwd = core.get_cwd()
|
||||
if cwd == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local vim_cwd = vim.fn.getcwd()
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer then
|
||||
return
|
||||
end
|
||||
|
||||
-- test if in vim_cwd
|
||||
if utils.path_relative(path, vim_cwd) ~= path then
|
||||
if vim_cwd ~= cwd then
|
||||
explorer:change_dir(vim_cwd)
|
||||
end
|
||||
return
|
||||
end
|
||||
-- test if in cwd
|
||||
if utils.path_relative(path, cwd) ~= path then
|
||||
return
|
||||
end
|
||||
|
||||
-- otherwise test init_root
|
||||
if config.g.prefer_startup_root and utils.path_relative(path, config.init_root) ~= path then
|
||||
explorer:change_dir(config.init_root)
|
||||
return
|
||||
end
|
||||
-- otherwise root_dirs
|
||||
for _, dir in pairs(config.g.root_dirs) do
|
||||
dir = vim.fn.fnamemodify(dir, ":p")
|
||||
if utils.path_relative(path, dir) ~= path then
|
||||
explorer:change_dir(dir)
|
||||
return
|
||||
end
|
||||
end
|
||||
-- finally fall back to the folder containing the file
|
||||
explorer:change_dir(vim.fn.fnamemodify(path, ":p:h"))
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,7 +1,9 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local config = require("nvim-tree.config")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
local change_root = require("nvim-tree.actions.tree.change-root")
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -56,16 +58,12 @@ function M.fn(opts)
|
||||
end
|
||||
|
||||
-- update root
|
||||
if opts.update_root or M.config.update_focused_file.update_root.enable then
|
||||
require("nvim-tree").change_root(path, bufnr)
|
||||
if opts.update_root or config.g.update_focused_file.update_root.enable then
|
||||
change_root.fn(path, bufnr)
|
||||
end
|
||||
|
||||
-- find
|
||||
finders_find_file.fn(path)
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config = opts or {}
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
M.find_file = require("nvim-tree.actions.tree.find-file")
|
||||
M.collapse = require("nvim-tree.actions.tree.collapse")
|
||||
M.open = require("nvim-tree.actions.tree.open")
|
||||
M.toggle = require("nvim-tree.actions.tree.toggle")
|
||||
M.resize = require("nvim-tree.actions.tree.resize")
|
||||
|
||||
function M.setup(opts)
|
||||
M.find_file.setup(opts)
|
||||
M.open.setup(opts)
|
||||
M.toggle.setup(opts)
|
||||
M.resize.setup(opts)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,6 +1,9 @@
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local core = require("nvim-tree.core")
|
||||
local config = require("nvim-tree.config")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
local change_root = require("nvim-tree.actions.tree.change-root")
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -37,10 +40,10 @@ function M.fn(opts)
|
||||
end
|
||||
|
||||
-- find file
|
||||
if M.config.update_focused_file.enable or opts.find_file then
|
||||
if config.g.update_focused_file.enable or opts.find_file then
|
||||
-- update root
|
||||
if opts.update_root then
|
||||
require("nvim-tree").change_root(previous_path, previous_buf)
|
||||
change_root.fn(previous_path, previous_buf)
|
||||
end
|
||||
|
||||
-- find
|
||||
@@ -48,8 +51,42 @@ function M.fn(opts)
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config = opts or {}
|
||||
---@param dirname string absolute directory path
|
||||
function M.open_on_directory(dirname)
|
||||
local should_proceed = config.g.hijack_directories.auto_open or view.is_visible()
|
||||
if not should_proceed then
|
||||
return
|
||||
end
|
||||
|
||||
-- instantiate an explorer if there is not one
|
||||
if not core.get_explorer() then
|
||||
core.init(dirname)
|
||||
end
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer:force_dirchange(dirname, true, false)
|
||||
end
|
||||
end
|
||||
|
||||
function M.tab_enter()
|
||||
if view.is_visible({ any_tabpage = true }) then
|
||||
local bufname = vim.api.nvim_buf_get_name(0)
|
||||
|
||||
local ft = vim.api.nvim_get_option_value("filetype", { buf = 0 }) or ""
|
||||
|
||||
for _, filter in ipairs(config.g.tab.sync.ignore) do
|
||||
if bufname:match(filter) ~= nil or ft:match(filter) ~= nil then
|
||||
return
|
||||
end
|
||||
end
|
||||
view.open({ focus_tree = false })
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -44,8 +44,4 @@ function M.fn(opts)
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config = opts or {}
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local config = require("nvim-tree.config")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
local change_root = require("nvim-tree.actions.tree.change-root")
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -52,10 +54,10 @@ function M.fn(opts, no_focus, cwd, bang)
|
||||
})
|
||||
|
||||
-- find file
|
||||
if M.config.update_focused_file.enable or opts.find_file then
|
||||
if config.g.update_focused_file.enable or opts.find_file then
|
||||
-- update root
|
||||
if opts.update_root then
|
||||
require("nvim-tree").change_root(previous_path, previous_buf)
|
||||
change_root.fn(previous_path, previous_buf)
|
||||
end
|
||||
|
||||
-- find
|
||||
@@ -69,8 +71,4 @@ function M.fn(opts, no_focus, cwd, bang)
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config = opts or {}
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -96,6 +96,6 @@ local api = {
|
||||
live_filter = require("nvim-tree._meta.api.deprecated").live_filter, ---@deprecated
|
||||
}
|
||||
|
||||
require("nvim-tree.api.impl.pre").hydrate(api)
|
||||
require("nvim-tree.api.impl").hydrate_pre_setup(api)
|
||||
|
||||
return api
|
||||
|
||||
260
lua/nvim-tree/api/impl.lua
Normal file
260
lua/nvim-tree/api/impl.lua
Normal file
@@ -0,0 +1,260 @@
|
||||
---Hydrates API meta functions with their implementations.
|
||||
---For startup performance reasons, all API implementation's requires must be
|
||||
---done at call time, not when this module is required.
|
||||
|
||||
local M = {}
|
||||
|
||||
---Walk the entire API, hydrating all functions with the error notification.
|
||||
---Do not hydrate classes i.e. anything with a metatable.
|
||||
---@param api table not properly typed to prevent LSP from referencing implementations
|
||||
local function hydrate_not_setup(api)
|
||||
for k, v in pairs(api) do
|
||||
if type(v) == "function" then
|
||||
api[k] = function()
|
||||
require("nvim-tree.notify").error("nvim-tree setup not called")
|
||||
end
|
||||
elseif type(v) == "table" and not getmetatable(v) then
|
||||
hydrate_not_setup(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Returns the node under the cursor.
|
||||
---@return Node?
|
||||
local function node_at_cursor()
|
||||
local e = require("nvim-tree.core").get_explorer()
|
||||
return e and e:get_node_at_cursor() or nil
|
||||
end
|
||||
|
||||
---Returns the visually selected nodes, if we are in visual mode.
|
||||
---@return Node[]?
|
||||
local function visual_nodes()
|
||||
local utils = require("nvim-tree.utils")
|
||||
return utils.is_visual_mode() and utils.get_visual_nodes() or nil
|
||||
end
|
||||
|
||||
---Injects:
|
||||
---- n: n or node at cursor
|
||||
---@param fn fun(n?: Node, ...): any
|
||||
---@return fun(n?: Node, ...): any
|
||||
local function _n(fn)
|
||||
return function(n, ...)
|
||||
return fn(n or node_at_cursor(), ...)
|
||||
end
|
||||
end
|
||||
|
||||
---Injects:
|
||||
---- n: visual nodes or n or node at cursor
|
||||
---@param fn fun(n?: Node|Node[], ...): any
|
||||
---@return fun(n?: Node|Node[], ...): any
|
||||
local function _v(fn)
|
||||
return function(n, ...)
|
||||
return fn(visual_nodes() or n or node_at_cursor(), ...)
|
||||
end
|
||||
end
|
||||
|
||||
---Injects:
|
||||
---- e: Explorer instance
|
||||
---Does nothing when no explorer instance.
|
||||
---@param fn fun(e: Explorer, ...): any
|
||||
---@return fun(e: Explorer, ...): any
|
||||
local function e_(fn)
|
||||
return function(...)
|
||||
local e = require("nvim-tree.core").get_explorer()
|
||||
if e then
|
||||
return fn(e, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Injects:
|
||||
---- e: Explorer instance
|
||||
---- n: n or node at cursor
|
||||
---Does nothing when no explorer instance.
|
||||
---@param fn fun(e: Explorer, n?: Node, ...): any
|
||||
---@return fun(e: Explorer, n?: Node, ...): any
|
||||
local function en(fn)
|
||||
return function(n, ...)
|
||||
local e = require("nvim-tree.core").get_explorer()
|
||||
if e then
|
||||
return fn(e, n or node_at_cursor(), ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Injects:
|
||||
---- e: Explorer instance
|
||||
---- n: visual nodes or n or node at cursor
|
||||
---Does nothing when no explorer instance.
|
||||
---@param fn fun(e: Explorer, n?: Node|Node[], ...): any
|
||||
---@return fun(e: Explorer, n?: Node|Node[], ...): any
|
||||
local function ev(fn)
|
||||
return function(n, ...)
|
||||
local e = require("nvim-tree.core").get_explorer()
|
||||
if e then
|
||||
return fn(e, visual_nodes() or n or node_at_cursor(), ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---NOP function wrapper, exists for formatting purposes only.
|
||||
---@param fn fun(...): any
|
||||
---@return fun(...): any
|
||||
local function __(fn)
|
||||
return function(...)
|
||||
return fn(...)
|
||||
end
|
||||
end
|
||||
|
||||
---Hydrates API meta functions pre-setup:
|
||||
--- Pre-setup functions will be hydrated with their implementation.
|
||||
--- Post-setup functions will notify error: "nvim-tree setup not called"
|
||||
--- All classes will be hydrated with their implementations.
|
||||
---Called once when api is first required
|
||||
---@param api table not properly typed to prevent LSP from referencing implementations
|
||||
function M.hydrate_pre_setup(api)
|
||||
hydrate_not_setup(api)
|
||||
|
||||
api.appearance.hi_test = __(function() require("nvim-tree.appearance.hi-test")() end)
|
||||
|
||||
api.commands.get = __(function() return require("nvim-tree.commands").get() end)
|
||||
|
||||
api.config.default = __(function() return require("nvim-tree.config").d_clone() end)
|
||||
|
||||
api.events.subscribe = __(function(event_name, handler) require("nvim-tree.events").subscribe(event_name, handler) end)
|
||||
|
||||
api.map.keymap.default = __(function() return require("nvim-tree.keymap").get_keymap_default() end)
|
||||
api.map.on_attach.default = __(function(bufnr) require("nvim-tree.keymap").on_attach_default(bufnr) end)
|
||||
|
||||
api.Decorator = require("nvim-tree.renderer.decorator")
|
||||
|
||||
-- Map any legacy functions to implementations above or to meta
|
||||
require("nvim-tree.legacy").map_api(api)
|
||||
end
|
||||
|
||||
---Re-hydrates all API functions with implementations, replacing any "nvim-tree setup not called" error functions.
|
||||
---Called explicitly after nvim-tree setup
|
||||
---@param api table not properly typed to prevent LSP from referencing implementations
|
||||
function M.hydrate_post_setup(api)
|
||||
-- Parameter naming conventions:
|
||||
-- `e` explorer
|
||||
-- `n` node
|
||||
-- `o` opts
|
||||
|
||||
api.config.global = __(function() return require("nvim-tree.config").g_clone() end)
|
||||
api.config.user = __(function() return require("nvim-tree.config").u_clone() end)
|
||||
|
||||
api.filter.custom.toggle = e_(function(e) e.filters:toggle("custom") end)
|
||||
api.filter.dotfiles.toggle = e_(function(e) e.filters:toggle("dotfiles") end)
|
||||
api.filter.git.clean.toggle = e_(function(e) e.filters:toggle("git_clean") end)
|
||||
api.filter.git.ignored.toggle = e_(function(e) e.filters:toggle("git_ignored") end)
|
||||
api.filter.live.clear = e_(function(e) e.live_filter:clear_filter() end)
|
||||
api.filter.live.start = e_(function(e) e.live_filter:start_filtering() end)
|
||||
api.filter.no_bookmark.toggle = e_(function(e) e.filters:toggle("no_bookmark") end)
|
||||
api.filter.no_buffer.toggle = e_(function(e) e.filters:toggle("no_buffer") end)
|
||||
api.filter.toggle = e_(function(e) e.filters:toggle() end)
|
||||
|
||||
api.fs.clear_clipboard = e_(function(e) e.clipboard:clear_clipboard() end)
|
||||
api.fs.copy.absolute_path = ev(function(e, n) e.clipboard:copy_absolute_path(n) end)
|
||||
api.fs.copy.basename = en(function(e, n) e.clipboard:copy_basename(n) end)
|
||||
api.fs.copy.filename = en(function(e, n) e.clipboard:copy_filename(n) end)
|
||||
api.fs.copy.relative_path = en(function(e, n) e.clipboard:copy_path(n) end)
|
||||
api.fs.copy.node = ev(function(e, n) e.clipboard:copy(n) end)
|
||||
api.fs.create = _n(function(n) require("nvim-tree.actions.fs.create-file").fn(n) end)
|
||||
api.fs.cut = ev(function(e, n) e.clipboard:cut(n) end)
|
||||
api.fs.paste = en(function(e, n) e.clipboard:paste(n) end)
|
||||
api.fs.move = en(function(e, n) e.clipboard:paste(n, { cut = true }) end)
|
||||
api.fs.print_clipboard = e_(function(e) e.clipboard:print_clipboard() end)
|
||||
api.fs.remove = _v(function(n) require("nvim-tree.actions.fs.remove-file").fn(n) end)
|
||||
api.fs.rename = _n(function(n) require("nvim-tree.actions.fs.rename-file").rename_node(n) end)
|
||||
api.fs.rename_basename = _n(function(n) require("nvim-tree.actions.fs.rename-file").rename_basename(n) end)
|
||||
api.fs.rename_full = _n(function(n) require("nvim-tree.actions.fs.rename-file").rename_full(n) end)
|
||||
api.fs.rename_node = _n(function(n) require("nvim-tree.actions.fs.rename-file").rename_node(n) end)
|
||||
api.fs.rename_sub = _n(function(n) require("nvim-tree.actions.fs.rename-file").rename_sub(n) end)
|
||||
api.fs.trash = _v(function(n) require("nvim-tree.actions.fs.trash").fn(n) end)
|
||||
|
||||
api.git.reload = e_(function(e) e:reload_git() end)
|
||||
|
||||
api.map.keymap.current = __(function() return require("nvim-tree.keymap").get_keymap() end)
|
||||
|
||||
api.marks.bulk.delete = e_(function(e) e.marks:bulk_delete() end)
|
||||
api.marks.bulk.move = e_(function(e) e.marks:bulk_move() end)
|
||||
api.marks.bulk.trash = e_(function(e) e.marks:bulk_trash() end)
|
||||
api.marks.clear = e_(function(e) e.marks:clear() end)
|
||||
api.marks.get = en(function(e, n) return e.marks:get(n) end)
|
||||
api.marks.list = e_(function(e) return e.marks:list() end)
|
||||
api.marks.navigate.next = e_(function(e) e.marks:navigate_next() end)
|
||||
api.marks.navigate.prev = e_(function(e) e.marks:navigate_prev() end)
|
||||
api.marks.navigate.select = e_(function(e) e.marks:navigate_select() end)
|
||||
api.marks.toggle = ev(function(e, n) e.marks:toggle(n) end)
|
||||
|
||||
api.node.buffer.delete = _n(function(n, o) require("nvim-tree.actions.node.buffer").delete(n, o) end)
|
||||
api.node.buffer.wipe = _n(function(n, o) require("nvim-tree.actions.node.buffer").wipe(n, o) end)
|
||||
api.node.collapse = _n(function(n, o) require("nvim-tree.actions.tree.collapse").node(n, o) end)
|
||||
api.node.expand = en(function(e, n, o) e:expand_node(n, o) end)
|
||||
api.node.navigate.diagnostics.next = __(function() require("nvim-tree.actions.moves.item").diagnostics_next() end)
|
||||
api.node.navigate.diagnostics.next_recursive = __(function() require("nvim-tree.actions.moves.item").diagnostics_next_recursive() end)
|
||||
api.node.navigate.diagnostics.prev = __(function() require("nvim-tree.actions.moves.item").diagnostics_prev() end)
|
||||
api.node.navigate.diagnostics.prev_recursive = __(function() require("nvim-tree.actions.moves.item").diagnostics_prev_recursive() end)
|
||||
api.node.navigate.git.next = __(function() require("nvim-tree.actions.moves.item").git_next() end)
|
||||
api.node.navigate.git.next_recursive = __(function() require("nvim-tree.actions.moves.item").git_next_recursive() end)
|
||||
api.node.navigate.git.next_skip_gitignored = __(function() require("nvim-tree.actions.moves.item").git_next_skip_gitignored() end)
|
||||
api.node.navigate.git.prev = __(function() require("nvim-tree.actions.moves.item").git_prev() end)
|
||||
api.node.navigate.git.prev_recursive = __(function() require("nvim-tree.actions.moves.item").git_prev_recursive() end)
|
||||
api.node.navigate.git.prev_skip_gitignored = __(function() require("nvim-tree.actions.moves.item").git_prev_skip_gitignored() end)
|
||||
api.node.navigate.opened.next = __(function() require("nvim-tree.actions.moves.item").opened_next() end)
|
||||
api.node.navigate.opened.prev = __(function() require("nvim-tree.actions.moves.item").opened_prev() end)
|
||||
api.node.navigate.parent = _n(function(n) require("nvim-tree.actions.moves.parent").move(n) end)
|
||||
api.node.navigate.parent_close = _n(function(n) require("nvim-tree.actions.moves.parent").move_close(n) end)
|
||||
api.node.navigate.sibling.first = _n(function(n) require("nvim-tree.actions.moves.sibling").first(n) end)
|
||||
api.node.navigate.sibling.last = _n(function(n) require("nvim-tree.actions.moves.sibling").last(n) end)
|
||||
api.node.navigate.sibling.next = _n(function(n) require("nvim-tree.actions.moves.sibling").next(n) end)
|
||||
api.node.navigate.sibling.prev = _n(function(n) require("nvim-tree.actions.moves.sibling").prev(n) end)
|
||||
api.node.open.drop = _n(function(n) require("nvim-tree.actions.node.open-file").drop(n) end)
|
||||
api.node.open.edit = _n(function(n, o) require("nvim-tree.actions.node.open-file").edit(n, o) end)
|
||||
api.node.open.horizontal = _n(function(n, o) require("nvim-tree.actions.node.open-file").horizontal(n, o) end)
|
||||
api.node.open.horizontal_no_picker = _n(function(n, o)
|
||||
require("nvim-tree.actions.node.open-file").horizontal_no_picker(n,
|
||||
o)
|
||||
end)
|
||||
api.node.open.no_window_picker = _n(function(n, o) require("nvim-tree.actions.node.open-file").no_window_picker(n, o) end)
|
||||
api.node.open.preview = _n(function(n, o) require("nvim-tree.actions.node.open-file").preview(n, o) end)
|
||||
api.node.open.preview_no_picker = _n(function(n, o) require("nvim-tree.actions.node.open-file").preview_no_picker(n, o) end)
|
||||
api.node.open.replace_tree_buffer = _n(function(n) require("nvim-tree.actions.node.open-file").replace_tree_buffer(n) end)
|
||||
api.node.open.tab = _n(function(n, o) require("nvim-tree.actions.node.open-file").tab(n, o) end)
|
||||
api.node.open.tab_drop = _n(function(n) require("nvim-tree.actions.node.open-file").tab_drop(n) end)
|
||||
api.node.open.toggle_group_empty = _n(function(n) require("nvim-tree.actions.node.open-file").toggle_group_empty(n) end)
|
||||
api.node.open.vertical = _n(function(n, o) require("nvim-tree.actions.node.open-file").vertical(n, o) end)
|
||||
api.node.open.vertical_no_picker = _n(function(n, o) require("nvim-tree.actions.node.open-file").vertical_no_picker(n, o) end)
|
||||
api.node.run.cmd = _n(function(n) require("nvim-tree.actions.node.run-command").run_file_command(n) end)
|
||||
api.node.run.system = _n(function(n) require("nvim-tree.actions.node.system-open").fn(n) end)
|
||||
api.node.show_info_popup = _n(function(n) require("nvim-tree.actions.node.file-popup").toggle_file_info(n) end)
|
||||
|
||||
api.tree.change_root = __(function(path) require("nvim-tree.actions.tree.change-dir").fn(path) end)
|
||||
api.tree.change_root_to_node = en(function(e, n) e:change_dir_to_node(n) end)
|
||||
api.tree.change_root_to_parent = en(function(e, n) e:dir_up(n) end)
|
||||
api.tree.close = __(function() require("nvim-tree.view").close() end)
|
||||
api.tree.close_in_all_tabs = __(function() require("nvim-tree.view").close_all_tabs() end)
|
||||
api.tree.close_in_this_tab = __(function() require("nvim-tree.view").close_this_tab_only() end)
|
||||
api.tree.collapse_all = __(function(o) require("nvim-tree.actions.tree.collapse").all(o) end)
|
||||
api.tree.expand_all = en(function(e, n, o) e:expand_all(n, o) end)
|
||||
api.tree.find_file = __(function(o) require("nvim-tree.actions.tree.find-file").fn(o) end)
|
||||
api.tree.focus = __(function(o) require("nvim-tree.actions.tree.open").fn(o) end)
|
||||
api.tree.get_node_under_cursor = en(function(e) return e:get_node_at_cursor() end)
|
||||
api.tree.get_nodes = en(function(e) return e:get_nodes() end)
|
||||
api.tree.is_tree_buf = __(function(bufnr) return require("nvim-tree.utils").is_nvim_tree_buf(bufnr) end)
|
||||
api.tree.is_visible = __(function(o) return require("nvim-tree.view").is_visible(o) end)
|
||||
api.tree.open = __(function(o) require("nvim-tree.actions.tree.open").fn(o) end)
|
||||
api.tree.reload = e_(function(e) e:reload_explorer() end)
|
||||
api.tree.reload_git = e_(function(e) e:reload_git() end)
|
||||
api.tree.resize = __(function(o) require("nvim-tree.actions.tree.resize").fn(o) end)
|
||||
api.tree.search_node = __(function() require("nvim-tree.actions.finders.search-node").fn() end)
|
||||
api.tree.toggle = __(function(o) require("nvim-tree.actions.tree.toggle").fn(o) end)
|
||||
api.tree.toggle_help = __(function() require("nvim-tree.help").toggle() end)
|
||||
api.tree.winid = __(function(o) return require("nvim-tree.view").winid(o) end)
|
||||
|
||||
-- Map all legacy functions to implementations
|
||||
require("nvim-tree.legacy").map_api(api)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,287 +0,0 @@
|
||||
---Hydrates all API functions with concrete implementations.
|
||||
---All "nvim-tree setup not called" error functions from pre.lua will be replaced.
|
||||
---
|
||||
---Call this after nvim-tree setup
|
||||
---
|
||||
---This is expensive as there are many cascading requires and is avoided
|
||||
---until after setup has been called, so that the user may require API cheaply.
|
||||
|
||||
local legacy = require("nvim-tree.legacy")
|
||||
|
||||
local actions = require("nvim-tree.actions")
|
||||
local config = require("nvim-tree.config")
|
||||
local help = require("nvim-tree.help")
|
||||
local keymap = require("nvim-tree.keymap")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local view = require("nvim-tree.view")
|
||||
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
local FileLinkNode = require("nvim-tree.node.file-link")
|
||||
local RootNode = require("nvim-tree.node.root")
|
||||
|
||||
local M = {}
|
||||
|
||||
---Invoke a method on the singleton explorer.
|
||||
---Print error when setup not called.
|
||||
---@param explorer_method string explorer method name
|
||||
---@return fun(...): any
|
||||
local function wrap_explorer(explorer_method)
|
||||
return function(...)
|
||||
local explorer = require("nvim-tree.core").get_explorer()
|
||||
if explorer then
|
||||
return explorer[explorer_method](explorer, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Inject the node as the first argument if present otherwise do nothing.
|
||||
---@param fn fun(node: Node, ...): any
|
||||
---@return fun(node: Node?, ...): any
|
||||
local function wrap_node(fn)
|
||||
return function(node, ...)
|
||||
node = node or wrap_explorer("get_node_at_cursor")()
|
||||
if node then
|
||||
return fn(node, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Inject the node or nil as the first argument if absent.
|
||||
---@param fn fun(node: Node?, ...): any
|
||||
---@return fun(node: Node?, ...): any
|
||||
local function wrap_node_or_nil(fn)
|
||||
return function(node, ...)
|
||||
node = node or wrap_explorer("get_node_at_cursor")()
|
||||
return fn(node, ...)
|
||||
end
|
||||
end
|
||||
|
||||
---Invoke a member's method on the singleton explorer.
|
||||
---Print error when setup not called.
|
||||
---@param explorer_member string explorer member name
|
||||
---@param member_method string method name to invoke on member
|
||||
---@param ... any passed to method
|
||||
---@return fun(...): any
|
||||
local function wrap_explorer_member_args(explorer_member, member_method, ...)
|
||||
local method_args = ...
|
||||
return function(...)
|
||||
local explorer = require("nvim-tree.core").get_explorer()
|
||||
if explorer then
|
||||
return explorer[explorer_member][member_method](explorer[explorer_member], method_args, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Invoke a member's method on the singleton explorer.
|
||||
---Print error when setup not called.
|
||||
---@param explorer_member string explorer member name
|
||||
---@param member_method string method name to invoke on member
|
||||
---@return fun(...): any
|
||||
local function wrap_explorer_member(explorer_member, member_method)
|
||||
return function(...)
|
||||
local explorer = require("nvim-tree.core").get_explorer()
|
||||
if explorer then
|
||||
return explorer[explorer_member][member_method](explorer[explorer_member], ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Wrap a function to be mode-dependent: in visual mode, pass all nodes in the
|
||||
---visual range; in normal mode, pass a single node. The implementation decides
|
||||
---how to handle each case.
|
||||
---@param fn fun(node_or_nodes: Node|Node[], ...): any
|
||||
---@return fun(node: Node?, ...): any
|
||||
local function wrap_node_or_visual(fn)
|
||||
local wrapped = wrap_node(fn)
|
||||
return function(node, ...)
|
||||
if utils.is_visual_mode() then
|
||||
local nodes = utils.get_visual_nodes()
|
||||
if nodes then
|
||||
fn(nodes, ...)
|
||||
end
|
||||
else
|
||||
return wrapped(node, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@class NodeEditOpts
|
||||
---@field quit_on_open boolean|nil default false
|
||||
---@field focus boolean|nil default true
|
||||
|
||||
---@param mode string
|
||||
---@param node Node
|
||||
---@param edit_opts NodeEditOpts?
|
||||
local function edit(mode, node, edit_opts)
|
||||
local file_link = node:as(FileLinkNode)
|
||||
local path = file_link and file_link.link_to or node.absolute_path
|
||||
local cur_tabpage = vim.api.nvim_get_current_tabpage()
|
||||
|
||||
actions.node.open_file.fn(mode, path)
|
||||
|
||||
edit_opts = edit_opts or {}
|
||||
|
||||
local mode_unsupported_quit_on_open = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
|
||||
if not mode_unsupported_quit_on_open and edit_opts.quit_on_open then
|
||||
view.close(cur_tabpage)
|
||||
end
|
||||
|
||||
local mode_unsupported_focus = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
|
||||
local focus = edit_opts.focus == nil or edit_opts.focus == true
|
||||
if not mode_unsupported_focus and not focus then
|
||||
-- if mode == "tabnew" a new tab will be opened and we need to focus back to the previous tab
|
||||
if mode == "tabnew" then
|
||||
vim.cmd(":tabprev")
|
||||
end
|
||||
view.focus()
|
||||
end
|
||||
end
|
||||
|
||||
---@param mode string
|
||||
---@param toggle_group boolean?
|
||||
---@return fun(node: Node, edit_opts: NodeEditOpts?)
|
||||
local function open_or_expand_or_dir_up(mode, toggle_group)
|
||||
---@param node Node
|
||||
---@param edit_opts NodeEditOpts?
|
||||
return function(node, edit_opts)
|
||||
local root = node:as(RootNode)
|
||||
local dir = node:as(DirectoryNode)
|
||||
|
||||
if root or node.name == ".." then
|
||||
wrap_explorer("change_dir")("..")
|
||||
elseif dir then
|
||||
dir:expand_or_collapse(toggle_group)
|
||||
elseif not toggle_group then
|
||||
edit(mode, node, edit_opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Re-Hydrate api functions and classes post-setup
|
||||
---@param api table not properly typed to prevent LSP from referencing implementations
|
||||
function M.hydrate(api)
|
||||
api.tree.open = actions.tree.open.fn
|
||||
api.tree.focus = api.tree.open
|
||||
|
||||
api.tree.toggle = actions.tree.toggle.fn
|
||||
api.tree.close = view.close
|
||||
api.tree.close_in_this_tab = view.close_this_tab_only
|
||||
api.tree.close_in_all_tabs = view.close_all_tabs
|
||||
api.tree.reload = wrap_explorer("reload_explorer")
|
||||
|
||||
api.tree.resize = actions.tree.resize.fn
|
||||
|
||||
api.tree.change_root = require("nvim-tree").change_dir
|
||||
|
||||
api.tree.change_root_to_node = wrap_node(wrap_explorer("change_dir_to_node"))
|
||||
api.tree.change_root_to_parent = wrap_node(wrap_explorer("dir_up"))
|
||||
api.tree.get_node_under_cursor = wrap_explorer("get_node_at_cursor")
|
||||
api.tree.get_nodes = wrap_explorer("get_nodes")
|
||||
|
||||
api.tree.find_file = actions.tree.find_file.fn
|
||||
api.tree.search_node = actions.finders.search_node.fn
|
||||
|
||||
api.tree.collapse_all = actions.tree.collapse.all
|
||||
|
||||
api.tree.expand_all = wrap_node(wrap_explorer("expand_all"))
|
||||
api.tree.toggle_help = help.toggle
|
||||
api.tree.is_tree_buf = utils.is_nvim_tree_buf
|
||||
|
||||
api.tree.is_visible = view.is_visible
|
||||
|
||||
api.tree.winid = view.winid
|
||||
|
||||
api.fs.create = wrap_node_or_nil(actions.fs.create_file.fn)
|
||||
api.fs.remove = wrap_node_or_visual(actions.fs.remove_file.fn)
|
||||
api.fs.trash = wrap_node_or_visual(actions.fs.trash.fn)
|
||||
api.fs.rename_node = wrap_node(actions.fs.rename_file.fn(":t"))
|
||||
api.fs.rename = wrap_node(actions.fs.rename_file.fn(":t"))
|
||||
api.fs.rename_sub = wrap_node(actions.fs.rename_file.fn(":p:h"))
|
||||
api.fs.rename_basename = wrap_node(actions.fs.rename_file.fn(":t:r"))
|
||||
api.fs.rename_full = wrap_node(actions.fs.rename_file.fn(":p"))
|
||||
api.fs.cut = wrap_node_or_visual(wrap_explorer_member("clipboard", "cut"))
|
||||
api.fs.paste = wrap_node(wrap_explorer_member("clipboard", "paste"))
|
||||
api.fs.clear_clipboard = wrap_explorer_member("clipboard", "clear_clipboard")
|
||||
api.fs.print_clipboard = wrap_explorer_member("clipboard", "print_clipboard")
|
||||
api.fs.copy.node = wrap_node_or_visual(wrap_explorer_member("clipboard", "copy"))
|
||||
api.fs.copy.absolute_path = wrap_node(wrap_explorer_member("clipboard", "copy_absolute_path"))
|
||||
api.fs.copy.filename = wrap_node(wrap_explorer_member("clipboard", "copy_filename"))
|
||||
api.fs.copy.basename = wrap_node(wrap_explorer_member("clipboard", "copy_basename"))
|
||||
api.fs.copy.relative_path = wrap_node(wrap_explorer_member("clipboard", "copy_path"))
|
||||
|
||||
api.node.open.edit = wrap_node(open_or_expand_or_dir_up("edit"))
|
||||
api.node.open.drop = wrap_node(open_or_expand_or_dir_up("drop"))
|
||||
api.node.open.tab_drop = wrap_node(open_or_expand_or_dir_up("tab_drop"))
|
||||
api.node.open.replace_tree_buffer = wrap_node(open_or_expand_or_dir_up("edit_in_place"))
|
||||
api.node.open.no_window_picker = wrap_node(open_or_expand_or_dir_up("edit_no_picker"))
|
||||
api.node.open.vertical = wrap_node(open_or_expand_or_dir_up("vsplit"))
|
||||
api.node.open.vertical_no_picker = wrap_node(open_or_expand_or_dir_up("vsplit_no_picker"))
|
||||
api.node.open.horizontal = wrap_node(open_or_expand_or_dir_up("split"))
|
||||
api.node.open.horizontal_no_picker = wrap_node(open_or_expand_or_dir_up("split_no_picker"))
|
||||
api.node.open.tab = wrap_node(open_or_expand_or_dir_up("tabnew"))
|
||||
api.node.open.toggle_group_empty = wrap_node(open_or_expand_or_dir_up("toggle_group_empty", true))
|
||||
api.node.open.preview = wrap_node(open_or_expand_or_dir_up("preview"))
|
||||
api.node.open.preview_no_picker = wrap_node(open_or_expand_or_dir_up("preview_no_picker"))
|
||||
|
||||
api.node.show_info_popup = wrap_node(actions.node.file_popup.toggle_file_info)
|
||||
api.node.run.cmd = wrap_node(actions.node.run_command.run_file_command)
|
||||
api.node.run.system = wrap_node(actions.node.system_open.fn)
|
||||
|
||||
api.node.navigate.sibling.next = wrap_node(actions.moves.sibling.fn("next"))
|
||||
api.node.navigate.sibling.prev = wrap_node(actions.moves.sibling.fn("prev"))
|
||||
api.node.navigate.sibling.first = wrap_node(actions.moves.sibling.fn("first"))
|
||||
api.node.navigate.sibling.last = wrap_node(actions.moves.sibling.fn("last"))
|
||||
api.node.navigate.parent = wrap_node(actions.moves.parent.fn(false))
|
||||
api.node.navigate.parent_close = wrap_node(actions.moves.parent.fn(true))
|
||||
api.node.navigate.git.next = wrap_node(actions.moves.item.fn({ where = "next", what = "git" }))
|
||||
api.node.navigate.git.next_skip_gitignored = wrap_node(actions.moves.item.fn({ where = "next", what = "git", skip_gitignored = true }))
|
||||
api.node.navigate.git.next_recursive = wrap_node(actions.moves.item.fn({ where = "next", what = "git", recurse = true }))
|
||||
api.node.navigate.git.prev = wrap_node(actions.moves.item.fn({ where = "prev", what = "git" }))
|
||||
api.node.navigate.git.prev_skip_gitignored = wrap_node(actions.moves.item.fn({ where = "prev", what = "git", skip_gitignored = true }))
|
||||
api.node.navigate.git.prev_recursive = wrap_node(actions.moves.item.fn({ where = "prev", what = "git", recurse = true }))
|
||||
api.node.navigate.diagnostics.next = wrap_node(actions.moves.item.fn({ where = "next", what = "diag" }))
|
||||
api.node.navigate.diagnostics.next_recursive = wrap_node(actions.moves.item.fn({ where = "next", what = "diag", recurse = true }))
|
||||
api.node.navigate.diagnostics.prev = wrap_node(actions.moves.item.fn({ where = "prev", what = "diag" }))
|
||||
api.node.navigate.diagnostics.prev_recursive = wrap_node(actions.moves.item.fn({ where = "prev", what = "diag", recurse = true }))
|
||||
api.node.navigate.opened.next = wrap_node(actions.moves.item.fn({ where = "next", what = "opened" }))
|
||||
api.node.navigate.opened.prev = wrap_node(actions.moves.item.fn({ where = "prev", what = "opened" }))
|
||||
|
||||
api.node.expand = wrap_node(wrap_explorer("expand_node"))
|
||||
api.node.collapse = wrap_node(actions.tree.collapse.node)
|
||||
|
||||
api.node.buffer.delete = wrap_node(function(node, opts) actions.node.buffer.delete(node, opts) end)
|
||||
api.node.buffer.wipe = wrap_node(function(node, opts) actions.node.buffer.wipe(node, opts) end)
|
||||
|
||||
api.tree.reload_git = wrap_explorer("reload_git")
|
||||
|
||||
api.filter.live.start = wrap_explorer_member("live_filter", "start_filtering")
|
||||
api.filter.live.clear = wrap_explorer_member("live_filter", "clear_filter")
|
||||
api.filter.toggle = wrap_explorer_member("filters", "toggle")
|
||||
api.filter.git.ignored.toggle = wrap_explorer_member_args("filters", "toggle", "git_ignored")
|
||||
api.filter.git.clean.toggle = wrap_explorer_member_args("filters", "toggle", "git_clean")
|
||||
api.filter.no_buffer.toggle = wrap_explorer_member_args("filters", "toggle", "no_buffer")
|
||||
api.filter.custom.toggle = wrap_explorer_member_args("filters", "toggle", "custom")
|
||||
api.filter.dotfiles.toggle = wrap_explorer_member_args("filters", "toggle", "dotfiles")
|
||||
api.filter.no_bookmark.toggle = wrap_explorer_member_args("filters", "toggle", "no_bookmark")
|
||||
|
||||
api.marks.get = wrap_node(wrap_explorer_member("marks", "get"))
|
||||
api.marks.list = wrap_explorer_member("marks", "list")
|
||||
api.marks.toggle = wrap_node_or_visual(wrap_explorer_member("marks", "toggle"))
|
||||
api.marks.clear = wrap_explorer_member("marks", "clear")
|
||||
api.marks.bulk.delete = wrap_explorer_member("marks", "bulk_delete")
|
||||
api.marks.bulk.trash = wrap_explorer_member("marks", "bulk_trash")
|
||||
api.marks.bulk.move = wrap_explorer_member("marks", "bulk_move")
|
||||
api.marks.navigate.next = wrap_explorer_member("marks", "navigate_next")
|
||||
api.marks.navigate.prev = wrap_explorer_member("marks", "navigate_prev")
|
||||
api.marks.navigate.select = wrap_explorer_member("marks", "navigate_select")
|
||||
|
||||
api.map.keymap.current = keymap.get_keymap
|
||||
|
||||
api.config.global = config.g_clone
|
||||
api.config.user = config.u_clone
|
||||
|
||||
-- (Re)hydrate any legacy by mapping to concrete set above
|
||||
legacy.map_api(api)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,62 +0,0 @@
|
||||
--Hydrates meta api empty definitions pre-setup:
|
||||
-- - Pre-setup functions will be hydrated with their concrete implementation.
|
||||
-- - Post-setup functions will notify error: "nvim-tree setup not called"
|
||||
-- - All classes will be hydrated with their implementations.
|
||||
--
|
||||
--Call it once when api is first required
|
||||
--
|
||||
--This file should have minimal requires that are cheap and have no dependencies or are already required.
|
||||
--
|
||||
--Everything must be as lazily loaded as possible: the user must be able to require api cheaply.
|
||||
|
||||
local legacy = require("nvim-tree.legacy")
|
||||
|
||||
local commands = require("nvim-tree.commands") -- already required by plugin.lua
|
||||
local events = require("nvim-tree.events") -- needed for event registration pre-setup
|
||||
local keymap = require("nvim-tree.keymap") -- needed for default on attach
|
||||
local notify = require("nvim-tree.notify") -- already required by events and others
|
||||
|
||||
local Decorator = require("nvim-tree.renderer.decorator")
|
||||
|
||||
local M = {}
|
||||
|
||||
---Walk the api, hydrating all functions with the error notification.
|
||||
---Do not hydrate classes: anything with a metatable.
|
||||
---@param t table
|
||||
local function hydrate_error(t)
|
||||
for k, v in pairs(t) do
|
||||
if type(v) == "function" then
|
||||
t[k] = function()
|
||||
notify.error("nvim-tree setup not called")
|
||||
end
|
||||
elseif type(v) == "table" and not getmetatable(v) then
|
||||
hydrate_error(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Hydrate api functions and classes pre-setup
|
||||
---@param api table not properly typed to prevent LSP from referencing implementations
|
||||
function M.hydrate(api)
|
||||
-- default to the error message
|
||||
hydrate_error(api)
|
||||
|
||||
-- eager functions
|
||||
api.events.subscribe = events.subscribe
|
||||
api.map.on_attach.default = keymap.on_attach_default
|
||||
api.commands.get = commands.get
|
||||
api.map.keymap.default = keymap.get_keymap_default
|
||||
|
||||
-- lazy functions
|
||||
api.appearance.hi_test = function() require("nvim-tree.appearance.hi-test")() end
|
||||
api.config.default = function() return require("nvim-tree.config").d_clone() end
|
||||
|
||||
-- classes
|
||||
api.Decorator = Decorator:extend()
|
||||
api.events.Event = events.Event
|
||||
|
||||
-- Hydrate any legacy by mapping to concrete set above
|
||||
legacy.map_api(api)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -138,11 +138,7 @@ return function()
|
||||
render_displays("other, long", displays_long, bufnr, l)
|
||||
|
||||
-- finalise and focus the buffer
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
|
||||
else
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", false) ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
|
||||
|
||||
vim.cmd.buffer(bufnr)
|
||||
end
|
||||
|
||||
@@ -182,7 +182,8 @@ M.LEGACY_LINKS = {
|
||||
NvimTreeDiagnosticHintFolderHL = "NvimTreeLspDiagnosticsHintFolderText",
|
||||
}
|
||||
|
||||
function M.setup()
|
||||
---Create all highlight groups and links. Idempotent.
|
||||
function M.highlight()
|
||||
-- non-linked
|
||||
for _, g in ipairs(M.HIGHLIGHT_GROUPS) do
|
||||
if g.def then
|
||||
|
||||
145
lua/nvim-tree/autocmd.lua
Normal file
145
lua/nvim-tree/autocmd.lua
Normal file
@@ -0,0 +1,145 @@
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local M = {}
|
||||
|
||||
---Create all global autocommands after setup.
|
||||
---Idempotent: removes existing autocommands first.
|
||||
---For startup performance reasons, all requires must be done inline during the callback.
|
||||
---Some short circuiting logic is done directly inside the callback to prevent unnecessary requires.
|
||||
function M.global()
|
||||
local augroup_id = vim.api.nvim_create_augroup("NvimTree", { clear = true })
|
||||
|
||||
vim.api.nvim_create_autocmd("BufWipeout", {
|
||||
group = augroup_id,
|
||||
pattern = "NvimTree_*",
|
||||
callback = function()
|
||||
require("nvim-tree.view").wipeout()
|
||||
end,
|
||||
})
|
||||
|
||||
if config.g.tab.sync.open then
|
||||
vim.api.nvim_create_autocmd("TabEnter", {
|
||||
group = augroup_id,
|
||||
callback = vim.schedule_wrap(function()
|
||||
require("nvim-tree.actions.tree.open").tab_enter()
|
||||
end)
|
||||
})
|
||||
end
|
||||
|
||||
if config.g.sync_root_with_cwd then
|
||||
vim.api.nvim_create_autocmd("DirChanged", {
|
||||
group = augroup_id,
|
||||
callback = function()
|
||||
require("nvim-tree.actions.tree.change-dir").fn(vim.uv.cwd())
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if config.g.update_focused_file.enable then
|
||||
vim.api.nvim_create_autocmd("BufEnter", {
|
||||
group = augroup_id,
|
||||
callback = function(event)
|
||||
if type(config.g.update_focused_file.exclude) == "function" and config.g.update_focused_file.exclude(event) then
|
||||
return
|
||||
end
|
||||
require("nvim-tree.utils").debounce("BufEnter:find_file", config.g.view.debounce_delay, function()
|
||||
require("nvim-tree.actions.tree.find-file").fn()
|
||||
end)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if config.g.hijack_directories.enable and (config.g.disable_netrw or config.g.hijack_netrw) then
|
||||
vim.api.nvim_create_autocmd({ "BufEnter", "BufNewFile" }, {
|
||||
group = augroup_id,
|
||||
nested = true,
|
||||
callback = function(data)
|
||||
local bufname = vim.api.nvim_buf_get_name(data.buf)
|
||||
if vim.fn.isdirectory(bufname) == 1 then
|
||||
require("nvim-tree.actions.tree.open").open_on_directory(bufname)
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if config.g.view.centralize_selection then
|
||||
vim.api.nvim_create_autocmd("BufEnter", {
|
||||
group = augroup_id,
|
||||
pattern = "NvimTree_*",
|
||||
callback = vim.schedule_wrap(function()
|
||||
vim.api.nvim_buf_call(0, function()
|
||||
local is_term_mode = vim.api.nvim_get_mode().mode == "t"
|
||||
if is_term_mode then
|
||||
return
|
||||
end
|
||||
vim.cmd([[norm! zz]])
|
||||
end)
|
||||
end)
|
||||
})
|
||||
end
|
||||
|
||||
if config.g.diagnostics.enable then
|
||||
vim.api.nvim_create_autocmd("DiagnosticChanged", {
|
||||
group = augroup_id,
|
||||
callback = function(ev)
|
||||
require("nvim-tree.diagnostics").update_lsp(ev)
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
group = augroup_id,
|
||||
pattern = "CocDiagnosticChange",
|
||||
callback = function()
|
||||
require("nvim-tree.diagnostics").update_coc()
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if config.g.view.float.enable and config.g.view.float.quit_on_focus_loss then
|
||||
vim.api.nvim_create_autocmd("WinLeave", {
|
||||
group = augroup_id,
|
||||
pattern = "NvimTree_*",
|
||||
callback = function()
|
||||
if require("nvim-tree.utils").is_nvim_tree_buf(0) then
|
||||
require("nvim-tree.view").close()
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
-- Handles event dispatch when tree is closed by `:q`
|
||||
vim.api.nvim_create_autocmd("WinClosed", {
|
||||
group = augroup_id,
|
||||
pattern = "*",
|
||||
---@param ev vim.api.keyset.create_autocmd.callback_args
|
||||
callback = function(ev)
|
||||
if not vim.api.nvim_buf_is_valid(ev.buf) then
|
||||
return
|
||||
end
|
||||
if vim.api.nvim_get_option_value("filetype", { buf = ev.buf }) == "NvimTree" then
|
||||
require("nvim-tree.events")._dispatch_on_tree_close()
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
if config.g.renderer.full_name then
|
||||
local group = vim.api.nvim_create_augroup("nvim_tree_floating_node", { clear = true })
|
||||
vim.api.nvim_create_autocmd({ "BufLeave", "CursorMoved" }, {
|
||||
group = group,
|
||||
pattern = { "NvimTree_*" },
|
||||
callback = function()
|
||||
require("nvim-tree.renderer.components.full-name").hide()
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd({ "CursorMoved" }, {
|
||||
group = group,
|
||||
pattern = { "NvimTree_*" },
|
||||
callback = function()
|
||||
require("nvim-tree.renderer.components.full-name").show()
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,3 +1,5 @@
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
local M = {}
|
||||
@@ -26,7 +28,7 @@ end
|
||||
---@param node Node
|
||||
---@return boolean
|
||||
function M.is_modified(node)
|
||||
if not M.config.modified.enable then
|
||||
if not config.g.modified.enable then
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -36,11 +38,11 @@ function M.is_modified(node)
|
||||
|
||||
local dir = node:as(DirectoryNode)
|
||||
if dir then
|
||||
if not M.config.modified.show_on_dirs then
|
||||
if not config.g.modified.show_on_dirs then
|
||||
return false
|
||||
end
|
||||
|
||||
if dir.open and not M.config.modified.show_on_open_dirs then
|
||||
if dir.open and not config.g.modified.show_on_open_dirs then
|
||||
return false
|
||||
end
|
||||
end
|
||||
@@ -55,11 +57,4 @@ function M.is_opened(node)
|
||||
return node and vim.fn.bufloaded(node.absolute_path) > 0
|
||||
end
|
||||
|
||||
---@param opts nvim_tree.config
|
||||
function M.setup(opts)
|
||||
M.config = {
|
||||
modified = opts.modified,
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,21 +1,35 @@
|
||||
--This will be required after api, before setup.
|
||||
--This file should have minimal requires that are cheap and have no dependencies or are already required.
|
||||
|
||||
local notify = require("nvim-tree.notify")
|
||||
local legacy = require("nvim-tree.legacy")
|
||||
local utils = require("nvim-tree.utils")
|
||||
|
||||
-- short names like g are used rather than getters to keep code brief
|
||||
|
||||
--Short names like g are used rather than getters to keep code brief
|
||||
local M = {
|
||||
---@type nvim_tree.config immutable default config
|
||||
---Immutable default config
|
||||
---@type nvim_tree.config
|
||||
d = {},
|
||||
|
||||
---@type nvim_tree.config? global current config, nil until setup called
|
||||
---Global current config, nil until setup called, mutable
|
||||
---@type nvim_tree.config?
|
||||
g = nil,
|
||||
|
||||
---@type nvim_tree.config? raw user config, nil when no user config passed to setup
|
||||
---Immutable raw user config, nil when no user config passed to setup
|
||||
---@type nvim_tree.config?
|
||||
u = nil,
|
||||
|
||||
---Immutable OS, detected once on first require
|
||||
---@type table<"unix"|"macos"|"wsl"|"windows", boolean>
|
||||
os = nil,
|
||||
|
||||
---Nvim cwd at setup time
|
||||
---@type string
|
||||
init_root = "",
|
||||
}
|
||||
|
||||
M.os = {
|
||||
unix = vim.fn.has("unix") == 1,
|
||||
macos = vim.fn.has("mac") == 1 or vim.fn.has("macunix") == 1,
|
||||
wsl = vim.fn.has("wsl") == 1,
|
||||
-- false for WSL
|
||||
windows = vim.fn.has("win32") == 1 or vim.fn.has("win32unix") == 1,
|
||||
}
|
||||
|
||||
M.d = { -- config-default-start
|
||||
@@ -159,10 +173,6 @@ M.d = { -- config-default-start
|
||||
},
|
||||
exclude = false,
|
||||
},
|
||||
system_open = {
|
||||
cmd = "",
|
||||
args = {},
|
||||
},
|
||||
git = {
|
||||
enable = true,
|
||||
show_on_dirs = true,
|
||||
@@ -218,6 +228,7 @@ M.d = { -- config-default-start
|
||||
"/target",
|
||||
"/.zig-cache",
|
||||
},
|
||||
whitelist_dirs = {},
|
||||
},
|
||||
actions = {
|
||||
use_system_clipboard = true,
|
||||
@@ -303,14 +314,6 @@ M.d = { -- config-default-start
|
||||
},
|
||||
} -- config-default-end
|
||||
|
||||
-- Immediately apply OS specific localisations to defaults
|
||||
if utils.is_macos or utils.is_windows then
|
||||
M.d.trash.cmd = "trash"
|
||||
end
|
||||
if utils.is_windows then
|
||||
M.d.filesystem_watchers.max_events = 1000
|
||||
end
|
||||
|
||||
local FIELD_SKIP_VALIDATE = {
|
||||
open_win_config = true,
|
||||
}
|
||||
@@ -348,6 +351,7 @@ local ACCEPTED_TYPES = {
|
||||
},
|
||||
filesystem_watchers = {
|
||||
ignore_dirs = { "function" },
|
||||
whitelist_dirs = { "function" },
|
||||
},
|
||||
actions = {
|
||||
open_file = {
|
||||
@@ -482,7 +486,58 @@ local function validate_config(u)
|
||||
validate(u, M.d, ACCEPTED_STRINGS, ACCEPTED_TYPES, ACCEPTED_ENUMS, "")
|
||||
|
||||
if msg then
|
||||
notify.warn(msg .. "\n\nsee :help nvim-tree-config for available configuration options")
|
||||
require("nvim-tree.notify").warn(msg .. "\n\nsee :help nvim-tree-config for available configuration options")
|
||||
end
|
||||
end
|
||||
|
||||
---Localise the (default) config with OS specifics
|
||||
---@param d nvim_tree.config
|
||||
local function localise_config(d)
|
||||
-- Trash
|
||||
if M.os.macos or M.os.windows then
|
||||
d.trash.cmd = "trash"
|
||||
end
|
||||
|
||||
-- Watchers
|
||||
if M.os.windows then
|
||||
d.filesystem_watchers.max_events = 1000
|
||||
end
|
||||
end
|
||||
|
||||
---Normalise the (global) config: defaults and user
|
||||
---@param g nvim_tree.config
|
||||
local function process_config(g)
|
||||
--
|
||||
-- Open
|
||||
--
|
||||
g.actions.open_file.window_picker.chars = tostring(g.actions.open_file.window_picker.chars):upper()
|
||||
|
||||
--
|
||||
-- Padding
|
||||
--
|
||||
if g.renderer.indent_width < 1 then
|
||||
g.renderer.indent_width = 1
|
||||
end
|
||||
for k, v in pairs(g.renderer.indent_markers.icons) do
|
||||
if #v == 0 then
|
||||
g.renderer.indent_markers.icons[k] = " "
|
||||
else
|
||||
-- return the first character from the UTF-8 encoded string; we may use utf8.codes from Lua 5.3 when available
|
||||
g.renderer.indent_markers.icons[k] = v:match("[%z\1-\127\194-\244][\128-\191]*")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Hijack and disable netrw if (globally) configured
|
||||
---@param g nvim_tree.config
|
||||
local function manage_netrw(g)
|
||||
if g.hijack_netrw then
|
||||
vim.cmd("silent! autocmd! FileExplorer *")
|
||||
vim.cmd("autocmd VimEnter * ++once silent! autocmd! FileExplorer *")
|
||||
end
|
||||
if g.disable_netrw then
|
||||
vim.g.loaded_netrw = 1
|
||||
vim.g.loaded_netrwPlugin = 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -493,7 +548,7 @@ end
|
||||
function M.setup(u)
|
||||
if not u or type(u) ~= "table" then
|
||||
if u then
|
||||
notify.warn(string.format("invalid config type \"%s\" passed to setup, using defaults", type(u)))
|
||||
require("nvim-tree.notify").warn(string.format("invalid config type \"%s\" passed to setup, using defaults", type(u)))
|
||||
end
|
||||
M.g = vim.deepcopy(M.d)
|
||||
M.u = nil
|
||||
@@ -503,12 +558,21 @@ function M.setup(u)
|
||||
-- retain user for reference
|
||||
M.u = vim.deepcopy(u)
|
||||
|
||||
legacy.migrate_config(u)
|
||||
require("nvim-tree.legacy").migrate_config(u)
|
||||
|
||||
validate_config(u)
|
||||
|
||||
-- set global to the validated and populated user config
|
||||
M.g = vim.tbl_deep_extend("force", M.d, u)
|
||||
|
||||
-- process merged config
|
||||
process_config(M.g)
|
||||
|
||||
-- deal with netrw
|
||||
manage_netrw(M.g)
|
||||
|
||||
-- store cwd
|
||||
M.init_root = vim.fn.getcwd()
|
||||
end
|
||||
|
||||
---Deep clone defaults
|
||||
@@ -529,4 +593,7 @@ function M.g_clone()
|
||||
return vim.deepcopy(M.g)
|
||||
end
|
||||
|
||||
---Immediately localise the defaults once and once only
|
||||
localise_config(M.d)
|
||||
|
||||
return M
|
||||
|
||||
@@ -2,6 +2,8 @@ local events = require("nvim-tree.events")
|
||||
local notify = require("nvim-tree.notify")
|
||||
local view = require("nvim-tree.view")
|
||||
local log = require("nvim-tree.log")
|
||||
local git = require("nvim-tree.git")
|
||||
local watcher = require("nvim-tree.watcher")
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -20,9 +22,9 @@ function M.init(foldername)
|
||||
local err, path
|
||||
|
||||
if foldername then
|
||||
path, err = vim.loop.fs_realpath(foldername)
|
||||
path, err = vim.uv.fs_realpath(foldername)
|
||||
else
|
||||
path, err = vim.loop.cwd()
|
||||
path, err = vim.uv.cwd()
|
||||
end
|
||||
if path then
|
||||
TreeExplorer = require("nvim-tree.explorer")({ path = path })
|
||||
@@ -64,4 +66,16 @@ function M.get_nodes_starting_line()
|
||||
return offset
|
||||
end
|
||||
|
||||
function M.purge_all_state()
|
||||
view.close_all_tabs()
|
||||
view.abandon_all_windows()
|
||||
if TreeExplorer then
|
||||
git.purge_state()
|
||||
TreeExplorer:destroy()
|
||||
M.reset_explorer()
|
||||
end
|
||||
-- purge orphaned that were not destroyed by their nodes
|
||||
watcher.purge_watchers()
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
local config = require("nvim-tree.config")
|
||||
local core = require("nvim-tree.core")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local view = require("nvim-tree.view")
|
||||
@@ -38,11 +39,16 @@ local function uniformize_path(path)
|
||||
end
|
||||
|
||||
---Severity is within diagnostics.severity.min, diagnostics.severity.max
|
||||
---@param severity lsp.DiagnosticSeverity
|
||||
---@param config table
|
||||
---Alway in range when using vim.diagnostic.Opts:
|
||||
---@see nvim_tree.config.diagnostics.diagnostic_opts
|
||||
---@param severity vim.diagnostic.Severity
|
||||
---@return boolean
|
||||
local function is_severity_in_range(severity, config)
|
||||
return config.max <= severity and severity <= config.min
|
||||
local function is_severity_in_range(severity)
|
||||
if config.g.diagnostics.diagnostic_opts then
|
||||
return true
|
||||
else
|
||||
return severity >= config.g.diagnostics.severity.max and severity <= config.g.diagnostics.severity.min
|
||||
end
|
||||
end
|
||||
|
||||
---Handle any COC exceptions, preventing any propagation
|
||||
@@ -86,7 +92,7 @@ local function from_coc()
|
||||
local bufname = uniformize_path(diagnostic.file)
|
||||
local coc_severity = COC_SEVERITY_LEVELS[diagnostic.severity]
|
||||
local highest_severity = buffer_severity[bufname] or coc_severity
|
||||
if is_severity_in_range(highest_severity, M.severity) then
|
||||
if is_severity_in_range(highest_severity) then
|
||||
buffer_severity[bufname] = math.min(highest_severity, coc_severity)
|
||||
end
|
||||
end
|
||||
@@ -122,7 +128,8 @@ end
|
||||
---On disabling LSP, a reset event will be sent for all buffers.
|
||||
---@param ev table standard event with data.diagnostics populated
|
||||
function M.update_lsp(ev)
|
||||
if not M.enable or not ev or not ev.data or not ev.data.diagnostics then
|
||||
log.line("diagnostics", "DiagnosticChanged")
|
||||
if not config.g.diagnostics.enable or not ev or not ev.data or not ev.data.diagnostics then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -138,7 +145,7 @@ function M.update_lsp(ev)
|
||||
|
||||
-- most severe (lowest) severity in user range
|
||||
for _, diagnostic in ipairs(diagnostics) do
|
||||
if diagnostic.severity >= M.severity.max and diagnostic.severity <= M.severity.min then
|
||||
if is_severity_in_range(diagnostic.severity) then
|
||||
if not new_severity or diagnostic.severity < new_severity then
|
||||
new_severity = diagnostic.severity
|
||||
end
|
||||
@@ -150,7 +157,7 @@ function M.update_lsp(ev)
|
||||
NODE_SEVERITIES[bufname] = new_severity
|
||||
NODE_SEVERITIES_VERSION = NODE_SEVERITIES_VERSION + 1
|
||||
|
||||
utils.debounce("DiagnosticChanged redraw", M.debounce_delay, function()
|
||||
utils.debounce("DiagnosticChanged redraw", config.g.diagnostics.debounce_delay, function()
|
||||
local profile_redraw = log.profile_start("DiagnosticChanged redraw")
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
@@ -168,10 +175,11 @@ end
|
||||
---Fired on CocDiagnosticChanged events:
|
||||
---debounced retrieval, cache update, version increment and draw
|
||||
function M.update_coc()
|
||||
if not M.enable then
|
||||
log.line("diagnostics", "CocDiagnosticChange")
|
||||
if not config.g.diagnostics.enable then
|
||||
return
|
||||
end
|
||||
utils.debounce("CocDiagnosticChanged update", M.debounce_delay, function()
|
||||
utils.debounce("CocDiagnosticChanged update", config.g.diagnostics.debounce_delay, function()
|
||||
local profile = log.profile_start("CocDiagnosticChanged update")
|
||||
NODE_SEVERITIES = from_coc()
|
||||
NODE_SEVERITIES_VERSION = NODE_SEVERITIES_VERSION + 1
|
||||
@@ -198,12 +206,12 @@ end
|
||||
---@param node Node
|
||||
---@return DiagStatus|nil
|
||||
function M.get_diag_status(node)
|
||||
if not M.enable then
|
||||
if not config.g.diagnostics.enable then
|
||||
return nil
|
||||
end
|
||||
|
||||
-- dir but we shouldn't show on dirs at all
|
||||
if node:is(DirectoryNode) and not M.show_on_dirs then
|
||||
if node:is(DirectoryNode) and not config.g.diagnostics.show_on_dirs then
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -222,26 +230,10 @@ function M.get_diag_status(node)
|
||||
end
|
||||
|
||||
-- dir is closed or we should show on open_dirs
|
||||
if not dir.open or M.show_on_open_dirs then
|
||||
if not dir.open or config.g.diagnostics.show_on_open_dirs then
|
||||
return node.diag_status
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.enable = opts.diagnostics.enable
|
||||
M.debounce_delay = opts.diagnostics.debounce_delay
|
||||
M.severity = opts.diagnostics.diagnostic_opts and {
|
||||
min = vim.diagnostic.severity.HINT,
|
||||
max = vim.diagnostic.severity.ERROR
|
||||
} or opts.diagnostics.severity
|
||||
|
||||
if M.enable then
|
||||
log.line("diagnostics", "setup")
|
||||
end
|
||||
|
||||
M.show_on_dirs = opts.diagnostics.show_on_dirs
|
||||
M.show_on_open_dirs = opts.diagnostics.show_on_open_dirs
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,27 +1,9 @@
|
||||
local notify = require("nvim-tree.notify")
|
||||
local Event = require("nvim-tree._meta.api.events").Event
|
||||
|
||||
local M = {}
|
||||
|
||||
local global_handlers = {}
|
||||
|
||||
M.Event = {
|
||||
Ready = "Ready",
|
||||
WillRenameNode = "WillRenameNode",
|
||||
NodeRenamed = "NodeRenamed",
|
||||
TreePreOpen = "TreePreOpen",
|
||||
TreeOpen = "TreeOpen",
|
||||
TreeClose = "TreeClose",
|
||||
WillCreateFile = "WillCreateFile",
|
||||
FileCreated = "FileCreated",
|
||||
WillRemoveFile = "WillRemoveFile",
|
||||
FileRemoved = "FileRemoved",
|
||||
FolderCreated = "FolderCreated",
|
||||
FolderRemoved = "FolderRemoved",
|
||||
Resize = "Resize",
|
||||
TreeAttachedPost = "TreeAttachedPost",
|
||||
TreeRendered = "TreeRendered",
|
||||
}
|
||||
|
||||
---@param event_name string
|
||||
---@return table
|
||||
local function get_handlers(event_name)
|
||||
@@ -42,84 +24,84 @@ local function dispatch(event_name, payload)
|
||||
for _, handler in pairs(get_handlers(event_name)) do
|
||||
local success, error = pcall(handler, payload)
|
||||
if not success then
|
||||
notify.error("Handler for event " .. event_name .. " errored. " .. vim.inspect(error))
|
||||
require("nvim-tree.notify").error("Handler for event " .. event_name .. " errored. " .. vim.inspect(error))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_ready()
|
||||
dispatch(M.Event.Ready)
|
||||
dispatch(Event.Ready)
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_will_rename_node(old_name, new_name)
|
||||
dispatch(M.Event.WillRenameNode, { old_name = old_name, new_name = new_name })
|
||||
dispatch(Event.WillRenameNode, { old_name = old_name, new_name = new_name })
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_node_renamed(old_name, new_name)
|
||||
dispatch(M.Event.NodeRenamed, { old_name = old_name, new_name = new_name })
|
||||
dispatch(Event.NodeRenamed, { old_name = old_name, new_name = new_name })
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_will_remove_file(fname)
|
||||
dispatch(M.Event.WillRemoveFile, { fname = fname })
|
||||
dispatch(Event.WillRemoveFile, { fname = fname })
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_file_removed(fname)
|
||||
dispatch(M.Event.FileRemoved, { fname = fname })
|
||||
dispatch(Event.FileRemoved, { fname = fname })
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_will_create_file(fname)
|
||||
dispatch(M.Event.WillCreateFile, { fname = fname })
|
||||
dispatch(Event.WillCreateFile, { fname = fname })
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_file_created(fname)
|
||||
dispatch(M.Event.FileCreated, { fname = fname })
|
||||
dispatch(Event.FileCreated, { fname = fname })
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_folder_created(folder_name)
|
||||
dispatch(M.Event.FolderCreated, { folder_name = folder_name })
|
||||
dispatch(Event.FolderCreated, { folder_name = folder_name })
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_folder_removed(folder_name)
|
||||
dispatch(M.Event.FolderRemoved, { folder_name = folder_name })
|
||||
dispatch(Event.FolderRemoved, { folder_name = folder_name })
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_on_tree_pre_open()
|
||||
dispatch(M.Event.TreePreOpen, nil)
|
||||
dispatch(Event.TreePreOpen, nil)
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_on_tree_open()
|
||||
dispatch(M.Event.TreeOpen, nil)
|
||||
dispatch(Event.TreeOpen, nil)
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_on_tree_close()
|
||||
dispatch(M.Event.TreeClose, nil)
|
||||
dispatch(Event.TreeClose, nil)
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_on_tree_resize(size)
|
||||
dispatch(M.Event.Resize, size)
|
||||
dispatch(Event.Resize, size)
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_tree_attached_post(buf)
|
||||
dispatch(M.Event.TreeAttachedPost, buf)
|
||||
dispatch(Event.TreeAttachedPost, buf)
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_on_tree_rendered(bufnr, winnr)
|
||||
dispatch(M.Event.TreeRendered, { bufnr = bufnr, winnr = winnr })
|
||||
dispatch(Event.TreeRendered, { bufnr = bufnr, winnr = winnr })
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -177,7 +177,7 @@ function Filters:custom(path)
|
||||
end
|
||||
|
||||
-- filter custom regexes
|
||||
local relpath = utils.path_relative(path, vim.loop.cwd())
|
||||
local relpath = utils.path_relative(path, vim.uv.cwd())
|
||||
for pat, _ in pairs(self.ignore_list) do
|
||||
if vim.fn.match(relpath, pat) ~= -1 or vim.fn.match(basename, pat) ~= -1 then
|
||||
return true
|
||||
@@ -273,7 +273,6 @@ function Filters:should_filter_as_reason(path, fs_stat, status)
|
||||
end
|
||||
|
||||
---Toggle a type and refresh
|
||||
---@private
|
||||
---@param type FilterType? nil to disable all
|
||||
function Filters:toggle(type)
|
||||
if not type or self.state[type] == nil then
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local appearance = require("nvim-tree.appearance")
|
||||
local buffers = require("nvim-tree.buffers")
|
||||
local config = require("nvim-tree.config")
|
||||
local core = require("nvim-tree.core")
|
||||
local git = require("nvim-tree.git")
|
||||
local log = require("nvim-tree.log")
|
||||
@@ -25,10 +26,8 @@ local FileNode = require("nvim-tree.node.file")
|
||||
local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON
|
||||
local find_file = require("nvim-tree.actions.finders.find-file")
|
||||
|
||||
local config
|
||||
|
||||
---@class (exact) Explorer: RootNode
|
||||
---@field uid_explorer number vim.loop.hrtime() at construction time
|
||||
---@field uid_explorer number vim.uv.hrtime() at construction time
|
||||
---@field opts table user options
|
||||
---@field augroup_id integer
|
||||
---@field current_tab integer
|
||||
@@ -55,11 +54,11 @@ function Explorer:new(args)
|
||||
name = "..",
|
||||
})
|
||||
|
||||
self.uid_explorer = vim.loop.hrtime()
|
||||
self.uid_explorer = vim.uv.hrtime()
|
||||
self.augroup_id = vim.api.nvim_create_augroup("NvimTree_Explorer_" .. self.uid_explorer, {})
|
||||
|
||||
self.open = true
|
||||
self.opts = config
|
||||
self.opts = config.g
|
||||
|
||||
|
||||
self.sorters = Sorter({ explorer = self })
|
||||
@@ -89,7 +88,7 @@ function Explorer:create_autocmds()
|
||||
vim.api.nvim_create_autocmd("ColorScheme", {
|
||||
group = self.augroup_id,
|
||||
callback = function()
|
||||
appearance.setup()
|
||||
appearance.highlight()
|
||||
view.reset_winhl()
|
||||
self.renderer:draw()
|
||||
end,
|
||||
@@ -182,15 +181,30 @@ function Explorer:create_autocmds()
|
||||
end
|
||||
|
||||
if self.opts.modified.enable then
|
||||
vim.api.nvim_create_autocmd({ "BufModifiedSet", "BufWritePost" }, {
|
||||
group = self.augroup_id,
|
||||
callback = function()
|
||||
utils.debounce("Buf:modified_" .. self.uid_explorer, self.opts.view.debounce_delay, function()
|
||||
buffers.reload_modified()
|
||||
self.renderer:draw()
|
||||
end)
|
||||
end,
|
||||
})
|
||||
local function on_modified_or_buf_write()
|
||||
utils.debounce("Buf:modified_" .. self.uid_explorer, self.opts.view.debounce_delay, function()
|
||||
buffers.reload_modified()
|
||||
self.renderer:draw()
|
||||
end)
|
||||
end
|
||||
|
||||
if vim.fn.has("nvim-0.13") == 1 then
|
||||
vim.api.nvim_create_autocmd({ "OptionSet", }, {
|
||||
group = self.augroup_id,
|
||||
pattern = "modified",
|
||||
callback = on_modified_or_buf_write,
|
||||
})
|
||||
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
|
||||
group = self.augroup_id,
|
||||
callback = on_modified_or_buf_write,
|
||||
})
|
||||
else
|
||||
-- BufModifiedSet event was removed in 0.13: it was a specific case of OptionSet
|
||||
vim.api.nvim_create_autocmd({ "BufModifiedSet", "BufWritePost" }, { ---@diagnostic disable-line: assign-type-mismatch
|
||||
group = self.augroup_id,
|
||||
callback = on_modified_or_buf_write,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -204,7 +218,7 @@ end
|
||||
---@return Node[]?
|
||||
function Explorer:reload(node, project)
|
||||
local cwd = node.link_to or node.absolute_path
|
||||
local handle = vim.loop.fs_scandir(cwd)
|
||||
local handle = vim.uv.fs_scandir(cwd)
|
||||
if not handle then
|
||||
return
|
||||
end
|
||||
@@ -234,15 +248,17 @@ function Explorer:reload(node, project)
|
||||
})
|
||||
|
||||
while true do
|
||||
local name, _ = vim.loop.fs_scandir_next(handle)
|
||||
local name, _ = vim.uv.fs_scandir_next(handle)
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
|
||||
local abs = utils.path_join({ cwd, name })
|
||||
|
||||
-- path incorrectly specified as an integer
|
||||
local stat = vim.loop.fs_lstat(abs) ---@diagnostic disable-line param-type-mismatch
|
||||
-- TODO remove once 0.12 is the minimum neovim version
|
||||
-- path incorrectly specified as an integer, fixed upstream for neovim 0.12 https://github.com/neovim/neovim/pull/33872
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
local stat = vim.uv.fs_lstat(abs)
|
||||
|
||||
local filter_reason = self.filters:should_filter_as_reason(abs, stat, filter_status)
|
||||
if filter_reason == FILTER_REASON.none then
|
||||
@@ -300,7 +316,7 @@ function Explorer:reload(node, project)
|
||||
)
|
||||
|
||||
local single_child = node:single_child_directory()
|
||||
if config.renderer.group_empty and node.parent and single_child then
|
||||
if self.opts.renderer.group_empty and node.parent and single_child then
|
||||
node.group_next = single_child
|
||||
local ns = self:reload(single_child, project)
|
||||
node.nodes = ns or {}
|
||||
@@ -390,7 +406,7 @@ function Explorer:populate_children(handle, cwd, node, project, parent)
|
||||
})
|
||||
|
||||
while true do
|
||||
local name, _ = vim.loop.fs_scandir_next(handle)
|
||||
local name, _ = vim.uv.fs_scandir_next(handle)
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
@@ -400,8 +416,10 @@ function Explorer:populate_children(handle, cwd, node, project, parent)
|
||||
if Watcher.is_fs_event_capable(abs) then
|
||||
local profile = log.profile_start("populate_children %s", abs)
|
||||
|
||||
-- path incorrectly specified as an integer
|
||||
local stat = vim.loop.fs_lstat(abs) ---@diagnostic disable-line param-type-mismatch
|
||||
-- TODO remove once 0.12 is the minimum neovim version
|
||||
-- path incorrectly specified as an integer, fixed upstream for neovim 0.12 https://github.com/neovim/neovim/pull/33872
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
local stat = vim.uv.fs_lstat(abs)
|
||||
|
||||
local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status)
|
||||
if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] then
|
||||
@@ -437,7 +455,7 @@ end
|
||||
---@return Node[]|nil
|
||||
function Explorer:explore(node, project, parent)
|
||||
local cwd = node.link_to or node.absolute_path
|
||||
local handle = vim.loop.fs_scandir(cwd)
|
||||
local handle = vim.uv.fs_scandir(cwd)
|
||||
if not handle then
|
||||
return
|
||||
end
|
||||
@@ -448,7 +466,7 @@ function Explorer:explore(node, project, parent)
|
||||
|
||||
local is_root = not node.parent
|
||||
local single_child = node:single_child_directory()
|
||||
if config.renderer.group_empty and not is_root and single_child then
|
||||
if self.opts.renderer.group_empty and not is_root and single_child then
|
||||
local child_cwd = single_child.link_to or single_child.absolute_path
|
||||
local child_project = git.load_project(child_cwd)
|
||||
node.group_next = single_child
|
||||
@@ -755,14 +773,14 @@ end
|
||||
---@return boolean
|
||||
function Explorer:prevent_cwd_change(foldername)
|
||||
local is_same_cwd = foldername == self.absolute_path
|
||||
local is_restricted_above = config.actions.change_dir.restrict_above_cwd and foldername < vim.fn.getcwd(-1, -1)
|
||||
local is_restricted_above = self.opts.actions.change_dir.restrict_above_cwd and foldername < vim.fn.getcwd(-1, -1)
|
||||
return is_same_cwd or is_restricted_above
|
||||
end
|
||||
|
||||
---@private
|
||||
---@return boolean
|
||||
function Explorer:should_change_dir()
|
||||
return config.actions.change_dir.enable and vim.tbl_isempty(vim.v.event)
|
||||
return self.opts.actions.change_dir.enable and vim.tbl_isempty(vim.v.event)
|
||||
end
|
||||
|
||||
---@private
|
||||
@@ -772,7 +790,6 @@ function Explorer:cd(global, path)
|
||||
vim.cmd((global and "cd " or "lcd ") .. vim.fn.fnameescape(path))
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param foldername string
|
||||
---@param should_open_view boolean|nil
|
||||
---@param should_init boolean|nil
|
||||
@@ -782,7 +799,7 @@ function Explorer:force_dirchange(foldername, should_open_view, should_init)
|
||||
local valid_dir = vim.fn.isdirectory(foldername) == 1 -- prevent problems on non existing dirs
|
||||
if valid_dir then
|
||||
if self:should_change_dir() then
|
||||
self:cd(config.actions.change_dir.global, foldername)
|
||||
self:cd(self.opts.actions.change_dir.global, foldername)
|
||||
end
|
||||
|
||||
if should_init ~= false then
|
||||
@@ -835,8 +852,4 @@ function Explorer:change_dir_to_node(node)
|
||||
end
|
||||
end
|
||||
|
||||
function Explorer:setup(opts)
|
||||
config = opts
|
||||
end
|
||||
|
||||
return Explorer
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local view = require("nvim-tree.view")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local Class = require("nvim-tree.classic")
|
||||
local Iterator = require("nvim-tree.iterators.node-iterator")
|
||||
@@ -10,6 +11,7 @@ local DirectoryNode = require("nvim-tree.node.directory")
|
||||
---@field prefix string
|
||||
---@field always_show_folders boolean
|
||||
---@field filter string
|
||||
---@field prev_focused_node? Node
|
||||
local LiveFilter = Class:extend()
|
||||
|
||||
---@class LiveFilter
|
||||
@@ -25,6 +27,7 @@ function LiveFilter:new(args)
|
||||
self.prefix = self.explorer.opts.live_filter.prefix
|
||||
self.always_show_folders = self.explorer.opts.live_filter.always_show_folders
|
||||
self.filter = nil
|
||||
self.prev_focused_node = nil
|
||||
end
|
||||
|
||||
---@param node_ Node?
|
||||
@@ -56,7 +59,7 @@ local overlay_bufnr = 0
|
||||
local overlay_winnr = 0
|
||||
|
||||
local function remove_overlay(self)
|
||||
if view.View.float.enable and view.View.float.quit_on_focus_loss then
|
||||
if config.g.view.float.enable and config.g.view.float.quit_on_focus_loss then
|
||||
-- return to normal nvim-tree float behaviour when filter window is closed
|
||||
vim.api.nvim_create_autocmd("WinLeave", {
|
||||
pattern = "NvimTree_*",
|
||||
@@ -166,7 +169,7 @@ local function calculate_overlay_win_width(self)
|
||||
end
|
||||
|
||||
local function create_overlay(self)
|
||||
if view.View.float.enable then
|
||||
if config.g.view.float.enable then
|
||||
-- don't close nvim-tree float when focus is changed to filter window
|
||||
vim.api.nvim_clear_autocmds({
|
||||
event = "WinLeave",
|
||||
@@ -186,13 +189,8 @@ local function create_overlay(self)
|
||||
style = "minimal",
|
||||
})
|
||||
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = overlay_bufnr })
|
||||
vim.api.nvim_set_option_value("filetype", "NvimTreeFilter", { buf = overlay_bufnr })
|
||||
else
|
||||
vim.api.nvim_buf_set_option(overlay_bufnr, "modifiable", true) ---@diagnostic disable-line: deprecated
|
||||
vim.api.nvim_buf_set_option(overlay_bufnr, "filetype", "NvimTreeFilter") ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = overlay_bufnr })
|
||||
vim.api.nvim_set_option_value("filetype", "NvimTreeFilter", { buf = overlay_bufnr })
|
||||
|
||||
vim.api.nvim_buf_set_lines(overlay_bufnr, 0, -1, false, { self.filter })
|
||||
vim.cmd("startinsert")
|
||||
@@ -200,7 +198,7 @@ local function create_overlay(self)
|
||||
end
|
||||
|
||||
function LiveFilter:start_filtering()
|
||||
view.View.live_filter.prev_focused_node = self.explorer:get_node_at_cursor()
|
||||
self.prev_focused_node = self.explorer:get_node_at_cursor()
|
||||
self.filter = self.filter or ""
|
||||
|
||||
self.explorer.renderer:draw()
|
||||
@@ -215,7 +213,6 @@ end
|
||||
|
||||
function LiveFilter:clear_filter()
|
||||
local node = self.explorer:get_node_at_cursor()
|
||||
local last_node = view.View.live_filter.prev_focused_node
|
||||
|
||||
self.filter = nil
|
||||
reset_filter(self)
|
||||
@@ -223,8 +220,8 @@ function LiveFilter:clear_filter()
|
||||
|
||||
if node then
|
||||
self.explorer:focus_node_or_parent(node)
|
||||
elseif last_node then
|
||||
self.explorer:focus_node_or_parent(last_node)
|
||||
elseif self.prev_focused_node then
|
||||
self.explorer:focus_node_or_parent(self.prev_focused_node)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,12 +2,13 @@ local log = require("nvim-tree.log")
|
||||
local git = require("nvim-tree.git")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local notify = require("nvim-tree.notify")
|
||||
local config = require("nvim-tree.config")
|
||||
local Watcher = require("nvim-tree.watcher").Watcher
|
||||
|
||||
local M = {
|
||||
config = {},
|
||||
uid = 0,
|
||||
}
|
||||
local M = {}
|
||||
|
||||
-- monotonically increasing, unique
|
||||
local uid = 0
|
||||
|
||||
---@param path string
|
||||
---@return boolean
|
||||
@@ -33,6 +34,9 @@ local IGNORED_PATHS = {
|
||||
"/dev",
|
||||
}
|
||||
|
||||
---Return true when a path is:
|
||||
---- Blacklisted via {ignore_dirs}
|
||||
---- Not whitelisted via {whitelist_dirs}, when it is not an empty table.
|
||||
---@param path string
|
||||
---@return boolean
|
||||
local function is_folder_ignored(path)
|
||||
@@ -42,18 +46,41 @@ local function is_folder_ignored(path)
|
||||
end
|
||||
end
|
||||
|
||||
if type(M.config.filesystem_watchers.ignore_dirs) == "table" then
|
||||
for _, ignore_dir in ipairs(M.config.filesystem_watchers.ignore_dirs) do
|
||||
if utils.is_windows then
|
||||
ignore_dir = ignore_dir:gsub("/", "\\\\") or ignore_dir
|
||||
---Return true when p matches an entry in dirs, escaping for windows
|
||||
---@param p string absolute path
|
||||
---@param dirs string[] regexes
|
||||
---@return boolean
|
||||
local function matches_dirs(p, dirs)
|
||||
for _, dir in ipairs(dirs) do
|
||||
if config.os.windows then
|
||||
dir = dir:gsub("/", "\\\\") or dir
|
||||
end
|
||||
|
||||
if vim.fn.match(path, ignore_dir) ~= -1 then
|
||||
if vim.fn.match(p, dir) ~= -1 then
|
||||
return true
|
||||
end
|
||||
end
|
||||
elseif type(M.config.filesystem_watchers.ignore_dirs) == "function" then
|
||||
return M.config.filesystem_watchers.ignore_dirs(path)
|
||||
return false
|
||||
end
|
||||
|
||||
if type(config.g.filesystem_watchers.ignore_dirs) == "table" then
|
||||
if matches_dirs(path, config.g.filesystem_watchers.ignore_dirs --[[@as string[] ]]) then
|
||||
return true
|
||||
end
|
||||
elseif type(config.g.filesystem_watchers.ignore_dirs) == "function" then
|
||||
if config.g.filesystem_watchers.ignore_dirs(path) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
if type(config.g.filesystem_watchers.whitelist_dirs) == "table" and #config.g.filesystem_watchers.whitelist_dirs > 0 then
|
||||
if not matches_dirs(path, config.g.filesystem_watchers.whitelist_dirs --[[@as string[] ]]) then
|
||||
return true
|
||||
end
|
||||
elseif type(config.g.filesystem_watchers.whitelist_dirs) == "function" then
|
||||
if not config.g.filesystem_watchers.whitelist_dirs(path) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
@@ -62,7 +89,7 @@ end
|
||||
---@param node DirectoryNode
|
||||
---@return Watcher|nil
|
||||
function M.create_watcher(node)
|
||||
if not M.config.filesystem_watchers.enable or type(node) ~= "table" then
|
||||
if not config.g.filesystem_watchers.enable or type(node) ~= "table" then
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -79,18 +106,18 @@ function M.create_watcher(node)
|
||||
watcher.data.outstanding_events = watcher.data.outstanding_events + 1
|
||||
|
||||
-- disable watcher when outstanding exceeds max
|
||||
if M.config.filesystem_watchers.max_events > 0 and watcher.data.outstanding_events > M.config.filesystem_watchers.max_events then
|
||||
if config.g.filesystem_watchers.max_events > 0 and watcher.data.outstanding_events > config.g.filesystem_watchers.max_events then
|
||||
notify.error(string.format(
|
||||
"Observed %d consecutive file system events with interval < %dms, exceeding filesystem_watchers.max_events=%s. Disabling watcher for directory '%s'. Consider adding this directory to filesystem_watchers.ignore_dirs",
|
||||
watcher.data.outstanding_events,
|
||||
M.config.filesystem_watchers.debounce_delay,
|
||||
M.config.filesystem_watchers.max_events,
|
||||
config.g.filesystem_watchers.debounce_delay,
|
||||
config.g.filesystem_watchers.max_events,
|
||||
node.absolute_path
|
||||
))
|
||||
node:destroy_watcher()
|
||||
end
|
||||
|
||||
utils.debounce(watcher.data.context, M.config.filesystem_watchers.debounce_delay, function()
|
||||
utils.debounce(watcher.data.context, config.g.filesystem_watchers.debounce_delay, function()
|
||||
if watcher.destroyed then
|
||||
return
|
||||
end
|
||||
@@ -107,20 +134,15 @@ function M.create_watcher(node)
|
||||
end)
|
||||
end
|
||||
|
||||
M.uid = M.uid + 1
|
||||
uid = uid + 1
|
||||
return Watcher:create({
|
||||
path = path,
|
||||
callback = callback,
|
||||
data = {
|
||||
context = "explorer:watch:" .. path .. ":" .. M.uid,
|
||||
context = "explorer:watch:" .. path .. ":" .. uid,
|
||||
outstanding_events = 0, -- unprocessed events that have not been debounced
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config.filesystem_watchers = opts.filesystem_watchers
|
||||
M.uid = 0
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local log = require("nvim-tree.log")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local config = require("nvim-tree.config")
|
||||
local git_utils = require("nvim-tree.git.utils")
|
||||
|
||||
local GitRunner = require("nvim-tree.git.runner")
|
||||
@@ -88,7 +89,7 @@ end
|
||||
|
||||
---@return nvim_tree.git.Project[] maybe empty
|
||||
function M.reload_all_projects()
|
||||
if not M.config.git.enable then
|
||||
if not config.g.git.enable then
|
||||
return {}
|
||||
end
|
||||
|
||||
@@ -106,7 +107,7 @@ end
|
||||
function M.reload_project(toplevel, path, callback)
|
||||
local project = M._projects_by_toplevel[toplevel] --[[@as nvim_tree.git.Project]]
|
||||
|
||||
if not toplevel or not project or not M.config.git.enable then
|
||||
if not toplevel or not project or not config.g.git.enable then
|
||||
if callback then
|
||||
callback()
|
||||
end
|
||||
@@ -126,7 +127,7 @@ function M.reload_project(toplevel, path, callback)
|
||||
path = path,
|
||||
list_untracked = git_utils.should_show_untracked(toplevel),
|
||||
list_ignored = true,
|
||||
timeout = M.config.git.timeout,
|
||||
timeout = config.g.git.timeout,
|
||||
}
|
||||
|
||||
if callback then
|
||||
@@ -137,7 +138,6 @@ function M.reload_project(toplevel, path, callback)
|
||||
end
|
||||
GitRunner:run(args)
|
||||
else
|
||||
-- TODO #1974 use callback once async/await is available
|
||||
reload_git_project(toplevel, path, project, GitRunner:run(args))
|
||||
end
|
||||
end
|
||||
@@ -161,7 +161,7 @@ function M.get_toplevel(path)
|
||||
return nil
|
||||
end
|
||||
|
||||
if not M.config.git.enable then
|
||||
if not config.g.git.enable then
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -172,7 +172,7 @@ function M.get_toplevel(path)
|
||||
return nil
|
||||
end
|
||||
|
||||
local stat, _ = vim.loop.fs_stat(path)
|
||||
local stat, _ = vim.uv.fs_stat(path)
|
||||
if not stat or stat.type ~= "directory" then
|
||||
return nil
|
||||
end
|
||||
@@ -194,15 +194,15 @@ function M.get_toplevel(path)
|
||||
local toplevel_norm = vim.fn.fnamemodify(toplevel, ":p")
|
||||
|
||||
-- ignore disabled paths
|
||||
if type(M.config.git.disable_for_dirs) == "table" then
|
||||
for _, disabled_for_dir in ipairs(M.config.git.disable_for_dirs) do
|
||||
if type(config.g.git.disable_for_dirs) == "table" then
|
||||
for _, disabled_for_dir in ipairs(config.g.git.disable_for_dirs --[[@as string[] ]]) do
|
||||
local disabled_norm = vim.fn.fnamemodify(disabled_for_dir, ":p")
|
||||
if toplevel_norm == disabled_norm then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
elseif type(M.config.git.disable_for_dirs) == "function" then
|
||||
if M.config.git.disable_for_dirs(toplevel_norm) then
|
||||
elseif type(config.g.git.disable_for_dirs) == "function" then
|
||||
if config.g.git.disable_for_dirs(toplevel_norm) then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
@@ -220,7 +220,7 @@ function M.get_toplevel(path)
|
||||
end
|
||||
|
||||
local function reload_tree_at(toplevel)
|
||||
if not M.config.git.enable or not toplevel then
|
||||
if not config.g.git.enable or not toplevel then
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -259,7 +259,7 @@ end
|
||||
---@param path string absolute
|
||||
---@return nvim_tree.git.Project maybe empty
|
||||
function M.load_project(path)
|
||||
if not M.config.git.enable then
|
||||
if not config.g.git.enable then
|
||||
return {}
|
||||
end
|
||||
|
||||
@@ -278,17 +278,17 @@ function M.load_project(path)
|
||||
toplevel = toplevel,
|
||||
list_untracked = git_utils.should_show_untracked(toplevel),
|
||||
list_ignored = true,
|
||||
timeout = M.config.git.timeout,
|
||||
timeout = config.g.git.timeout,
|
||||
})
|
||||
|
||||
local watcher = nil
|
||||
if M.config.filesystem_watchers.enable then
|
||||
if config.g.filesystem_watchers.enable then
|
||||
log.line("watcher", "git start")
|
||||
|
||||
---@param w Watcher
|
||||
local callback = function(w)
|
||||
log.line("watcher", "git event scheduled '%s'", w.data.toplevel)
|
||||
utils.debounce("git:watcher:" .. w.data.toplevel, M.config.filesystem_watchers.debounce_delay, function()
|
||||
utils.debounce("git:watcher:" .. w.data.toplevel, config.g.filesystem_watchers.debounce_delay, function()
|
||||
if w.destroyed then
|
||||
return
|
||||
end
|
||||
@@ -403,12 +403,7 @@ end
|
||||
function M.disable_git_integration()
|
||||
log.line("git", "disabling git integration")
|
||||
M.purge_state()
|
||||
M.config.git.enable = false
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config.git = opts.git
|
||||
M.config.filesystem_watchers = opts.filesystem_watchers
|
||||
config.g.git.enable = false
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -125,9 +125,9 @@ end
|
||||
---@param callback function|nil
|
||||
function GitRunner:run_git_job(callback)
|
||||
local handle, pid
|
||||
local stdout = vim.loop.new_pipe(false)
|
||||
local stderr = vim.loop.new_pipe(false)
|
||||
local timer = vim.loop.new_timer()
|
||||
local stdout = vim.uv.new_pipe(false)
|
||||
local stderr = vim.uv.new_pipe(false)
|
||||
local timer = vim.uv.new_timer()
|
||||
|
||||
if stdout == nil or stderr == nil or timer == nil then
|
||||
return
|
||||
@@ -150,7 +150,7 @@ function GitRunner:run_git_job(callback)
|
||||
|
||||
-- don't close the handle when killing as it will leave a zombie
|
||||
if rc == -1 then
|
||||
pcall(vim.loop.kill, pid, "sigkill")
|
||||
pcall(vim.uv.kill, pid, "sigkill")
|
||||
elseif handle then
|
||||
handle:close()
|
||||
end
|
||||
@@ -164,7 +164,7 @@ function GitRunner:run_git_job(callback)
|
||||
log.line("git", "running job with timeout %dms", self.timeout)
|
||||
log.line("git", "git %s", table.concat(utils.array_remove_nils(spawn_options.args), " "))
|
||||
|
||||
handle, pid = vim.loop.spawn(
|
||||
handle, pid = vim.uv.spawn(
|
||||
"git",
|
||||
spawn_options,
|
||||
vim.schedule_wrap(function(rc)
|
||||
@@ -196,8 +196,8 @@ function GitRunner:run_git_job(callback)
|
||||
self:log_raw_output(data)
|
||||
end
|
||||
|
||||
vim.loop.read_start(stdout, vim.schedule_wrap(manage_stdout))
|
||||
vim.loop.read_start(stderr, vim.schedule_wrap(manage_stderr))
|
||||
vim.uv.read_start(stdout, vim.schedule_wrap(manage_stdout))
|
||||
vim.uv.read_start(stderr, vim.schedule_wrap(manage_stderr))
|
||||
end
|
||||
|
||||
---@private
|
||||
|
||||
@@ -1,21 +1,32 @@
|
||||
local log = require("nvim-tree.log")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local M = {
|
||||
use_cygpath = false,
|
||||
}
|
||||
local M = {}
|
||||
|
||||
---@type boolean?
|
||||
local use_cygpath_cached = nil
|
||||
|
||||
---true when cygwin enabled and present
|
||||
---@return boolean
|
||||
local function use_cygpath()
|
||||
if use_cygpath_cached == nil then
|
||||
if config.g.git.cygwin_support then
|
||||
use_cygpath_cached = vim.fn.executable("cygpath") == 1
|
||||
else
|
||||
use_cygpath_cached = false
|
||||
end
|
||||
end
|
||||
return use_cygpath_cached
|
||||
end
|
||||
|
||||
--- Execute system command
|
||||
---@param cmd string[]
|
||||
---@return string stdout
|
||||
---@return integer exit code
|
||||
local function system(cmd)
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
local obj = vim.system(cmd):wait(M.opts.git.timeout)
|
||||
return obj.stdout or "", obj.code
|
||||
else
|
||||
return vim.fn.system(cmd), vim.v.shell_error
|
||||
end
|
||||
local obj = vim.system(cmd):wait(config.g.git.timeout)
|
||||
return obj.stdout or "", obj.code
|
||||
end
|
||||
|
||||
--- Retrieve the git toplevel directory
|
||||
@@ -50,7 +61,7 @@ function M.get_toplevel(cwd)
|
||||
if vim.fn.has("win32") == 1 then
|
||||
-- msys2 git support
|
||||
-- cygpath calls must in array format to avoid shell compatibility issues
|
||||
if M.use_cygpath then
|
||||
if use_cygpath() then
|
||||
toplevel = vim.fn.system({ "cygpath", "-w", toplevel })
|
||||
if vim.v.shell_error ~= 0 then
|
||||
return nil, nil
|
||||
@@ -195,11 +206,4 @@ function M.git_status_dir(parent_ignored, project, path, path_fallback)
|
||||
return ns
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
if opts.git.cygwin_support then
|
||||
M.use_cygpath = vim.fn.executable("cygpath") == 1
|
||||
end
|
||||
M.opts = opts
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local keymap = require("nvim-tree.keymap")
|
||||
local api = {} -- circular dependency
|
||||
local api = require("nvim-tree.api")
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local PAT_MOUSE = "^<.*Mouse"
|
||||
local PAT_CTRL = "^<C%-"
|
||||
@@ -14,8 +15,6 @@ local WIN_HL = table.concat({
|
||||
local namespace_help_id = vim.api.nvim_create_namespace("NvimTreeHelp")
|
||||
|
||||
local M = {
|
||||
config = {},
|
||||
|
||||
-- one and only buf/win
|
||||
bufnr = nil,
|
||||
winnr = nil,
|
||||
@@ -90,7 +89,7 @@ end
|
||||
local function compute(map)
|
||||
local head_lhs = "nvim-tree mappings"
|
||||
local head_rhs1 = "exit: q"
|
||||
local head_rhs2 = string.format("sort by %s: s", M.config.sort_by == "key" and "description" or "keymap")
|
||||
local head_rhs2 = string.format("sort by %s: s", config.g.help.sort_by == "key" and "description" or "keymap")
|
||||
|
||||
-- merge modes for duplicate lhs+desc entries e.g. "n" + "x" -> "nx"
|
||||
local merged = {}
|
||||
@@ -111,7 +110,7 @@ local function compute(map)
|
||||
-- sorter function for mappings
|
||||
local sort_fn
|
||||
|
||||
if M.config.sort_by == "desc" then
|
||||
if config.g.help.sort_by == "desc" then
|
||||
sort_fn = function(a, b)
|
||||
return a.desc:lower() < b.desc:lower()
|
||||
end
|
||||
@@ -204,12 +203,7 @@ local function open()
|
||||
|
||||
-- populate it
|
||||
vim.api.nvim_buf_set_lines(M.bufnr, 0, -1, false, lines)
|
||||
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = M.bufnr })
|
||||
else
|
||||
vim.api.nvim_buf_set_option(M.bufnr, "modifiable", false) ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = M.bufnr })
|
||||
|
||||
-- highlight it
|
||||
for _, args in ipairs(hl_range_args) do
|
||||
@@ -234,10 +228,10 @@ local function open()
|
||||
|
||||
-- style it a bit like the tree
|
||||
vim.wo[M.winnr].winhl = WIN_HL
|
||||
vim.wo[M.winnr].cursorline = M.config.cursorline
|
||||
vim.wo[M.winnr].cursorline = config.g.view.cursorline
|
||||
|
||||
local function toggle_sort()
|
||||
M.config.sort_by = (M.config.sort_by == "desc") and "key" or "desc"
|
||||
config.g.help.sort_by = (config.g.help.sort_by == "desc") and "key" or "desc"
|
||||
open()
|
||||
end
|
||||
|
||||
@@ -281,11 +275,4 @@ function M.toggle()
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config.cursorline = opts.view.cursorline
|
||||
M.config.sort_by = opts.help.sort_by
|
||||
|
||||
api = require("nvim-tree.api")
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
local M = {}
|
||||
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
---Execute the user or default on attach
|
||||
---@see nvim_tree.config.on_attach
|
||||
---@param bufnr integer
|
||||
function M.on_attach(bufnr)
|
||||
if type(config.g.on_attach) == "function" then
|
||||
config.g.on_attach(bufnr)
|
||||
else
|
||||
M.on_attach_default(bufnr)
|
||||
end
|
||||
end
|
||||
|
||||
--- Apply mappings to a scratch buffer and return buffer local mappings
|
||||
---@param fn fun(bufnr: integer) on_attach or on_attach_default
|
||||
---@return table as per vim.api.nvim_buf_get_keymap
|
||||
@@ -77,7 +90,7 @@ function M.on_attach_default(bufnr)
|
||||
vim.keymap.set("n", "F", api.filter.live.clear, opts("Live Filter: Clear"))
|
||||
vim.keymap.set("n", "f", api.filter.live.start, opts("Live Filter: Start"))
|
||||
vim.keymap.set("n", "g?", api.tree.toggle_help, opts("Help"))
|
||||
vim.keymap.set("n", "gy", api.fs.copy.absolute_path, opts("Copy Absolute Path"))
|
||||
vim.keymap.set({ "n", "x" }, "gy", api.fs.copy.absolute_path, opts("Copy Absolute Path"))
|
||||
vim.keymap.set("n", "ge", api.fs.copy.basename, opts("Copy Basename"))
|
||||
vim.keymap.set("n", "H", api.filter.dotfiles.toggle, opts("Toggle Filter: Dotfiles"))
|
||||
vim.keymap.set("n", "I", api.filter.git.ignored.toggle, opts("Toggle Filter: Git Ignored"))
|
||||
@@ -89,6 +102,7 @@ function M.on_attach_default(bufnr)
|
||||
vim.keymap.set("n", "o", api.node.open.edit, opts("Open"))
|
||||
vim.keymap.set("n", "O", api.node.open.no_window_picker, opts("Open: No Window Picker"))
|
||||
vim.keymap.set("n", "p", api.fs.paste, opts("Paste"))
|
||||
vim.keymap.set("n", "gp", api.fs.move, opts("Move"))
|
||||
vim.keymap.set("n", "P", api.node.navigate.parent, opts("Parent Directory"))
|
||||
vim.keymap.set("n", "q", api.tree.close, opts("Close"))
|
||||
vim.keymap.set("n", "r", api.fs.rename, opts("Rename"))
|
||||
@@ -106,12 +120,4 @@ function M.on_attach_default(bufnr)
|
||||
-- END_ON_ATTACH_DEFAULT
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
if type(opts.on_attach) ~= "function" then
|
||||
M.on_attach = M.on_attach_default
|
||||
else
|
||||
M.on_attach = opts.on_attach
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
local notify = require("nvim-tree.notify")
|
||||
|
||||
local M = {}
|
||||
|
||||
--- Create empty sub-tables if not present
|
||||
@@ -120,27 +118,41 @@ end
|
||||
---@param u nvim_tree.config user supplied subset of config
|
||||
local function deprecated_config(u)
|
||||
if type(u.view) == "table" and u.view.hide_root_folder then
|
||||
notify.info("view.hide_root_folder is deprecated, please set renderer.root_folder_label = false")
|
||||
require("nvim-tree.notify").info(
|
||||
"view.hide_root_folder is deprecated, please set renderer.root_folder_label = false"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
---@param u nvim_tree.config user supplied subset of config
|
||||
local function removed_config(u)
|
||||
if u.auto_close then
|
||||
notify.warn("auto close feature has been removed: https://github.com/nvim-tree/nvim-tree.lua/wiki/Auto-Close")
|
||||
require("nvim-tree.notify").warn(
|
||||
"auto close feature has been removed: https://github.com/nvim-tree/nvim-tree.lua/wiki/Auto-Close"
|
||||
)
|
||||
u["auto_close"] = nil
|
||||
end
|
||||
|
||||
if u.focus_empty_on_setup then
|
||||
notify.warn("focus_empty_on_setup has been removed: https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup")
|
||||
require("nvim-tree.notify").warn(
|
||||
"focus_empty_on_setup has been removed: https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup"
|
||||
)
|
||||
u["focus_empty_on_setup"] = nil
|
||||
end
|
||||
|
||||
if u.create_in_closed_folder then
|
||||
notify.warn(
|
||||
"create_in_closed_folder has been removed and is now the default behaviour. You may use api.fs.create to add a file under your desired node.")
|
||||
require("nvim-tree.notify").warn(
|
||||
"create_in_closed_folder has been removed and is now the default behaviour. You may use api.fs.create to add a file under your desired node."
|
||||
)
|
||||
end
|
||||
u["create_in_closed_folder"] = nil
|
||||
|
||||
if u.system_open then
|
||||
require("nvim-tree.notify").warn(
|
||||
"system_open has been removed, now uses the system default handler: vim.ui.open()"
|
||||
)
|
||||
u["system_open"] = nil
|
||||
end
|
||||
end
|
||||
|
||||
---Migrate legacy config in place.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local view = require("nvim-tree.view")
|
||||
local core = require("nvim-tree.core")
|
||||
local notify = require("nvim-tree.notify")
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
---@class LibOpenOpts
|
||||
---@field path string|nil path
|
||||
@@ -25,7 +26,7 @@ end
|
||||
---@param cwd string
|
||||
local function handle_buf_cwd(cwd)
|
||||
local explorer = core.get_explorer()
|
||||
if M.respect_buf_cwd and cwd ~= core.get_cwd() and explorer then
|
||||
if config.g.respect_buf_cwd and cwd ~= core.get_cwd() and explorer then
|
||||
explorer:change_dir(cwd)
|
||||
end
|
||||
end
|
||||
@@ -46,16 +47,11 @@ local function should_hijack_current_buf()
|
||||
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
||||
|
||||
local bufmodified, ft
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
bufmodified = vim.api.nvim_get_option_value("modified", { buf = bufnr })
|
||||
ft = vim.api.nvim_get_option_value("ft", { buf = bufnr })
|
||||
else
|
||||
bufmodified = vim.api.nvim_buf_get_option(bufnr, "modified") ---@diagnostic disable-line: deprecated
|
||||
ft = vim.api.nvim_buf_get_option(bufnr, "ft") ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
bufmodified = vim.api.nvim_get_option_value("modified", { buf = bufnr })
|
||||
ft = vim.api.nvim_get_option_value("ft", { buf = bufnr })
|
||||
|
||||
local should_hijack_unnamed = M.hijack_unnamed_buffer_when_opening and bufname == "" and not bufmodified and ft == ""
|
||||
local should_hijack_dir = bufname ~= "" and vim.fn.isdirectory(bufname) == 1 and M.hijack_directories.enable
|
||||
local should_hijack_unnamed = config.g.hijack_unnamed_buffer_when_opening and bufname == "" and not bufmodified and ft == ""
|
||||
local should_hijack_dir = bufname ~= "" and vim.fn.isdirectory(bufname) == 1 and config.g.hijack_directories.enable
|
||||
|
||||
return should_hijack_dir or should_hijack_unnamed
|
||||
end
|
||||
@@ -76,7 +72,7 @@ function M.prompt(prompt_input, prompt_select, items_short, items_long, kind, ca
|
||||
return ""
|
||||
end
|
||||
|
||||
if M.select_prompts then
|
||||
if config.g.select_prompts then
|
||||
vim.ui.select(items_short, { prompt = prompt_select, kind = kind, format_item = format_item }, function(item_short)
|
||||
callback(item_short)
|
||||
end)
|
||||
@@ -99,7 +95,7 @@ function M.open(opts)
|
||||
if opts.path then
|
||||
core.init(opts.path)
|
||||
else
|
||||
local cwd, err = vim.loop.cwd()
|
||||
local cwd, err = vim.uv.cwd()
|
||||
if not cwd then
|
||||
notify.error(string.format("current working directory unavailable: %s", err))
|
||||
return
|
||||
@@ -132,12 +128,4 @@ function M.open(opts)
|
||||
view.restore_tab_state()
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.hijack_unnamed_buffer_when_opening = opts.hijack_unnamed_buffer_when_opening
|
||||
M.hijack_directories = opts.hijack_directories
|
||||
M.respect_buf_cwd = opts.respect_buf_cwd
|
||||
M.select_prompts = opts.select_prompts
|
||||
M.group_empty = opts.renderer.group_empty
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
---@alias LogTypes "all" | "config" | "copy_paste" | "dev" | "diagnostics" | "git" | "profile" | "watcher"
|
||||
|
||||
---@type table<LogTypes, boolean>
|
||||
@@ -57,7 +59,7 @@ end
|
||||
function M.profile_start(fmt, ...)
|
||||
local profile = {}
|
||||
if M.enabled("profile") then
|
||||
profile.start = vim.loop.hrtime()
|
||||
profile.start = vim.uv.hrtime()
|
||||
profile.tag = string.format((fmt or "???"), ...)
|
||||
M.line("profile", "START %s", profile.tag)
|
||||
end
|
||||
@@ -69,7 +71,7 @@ end
|
||||
---@param profile Profile returned from profile_start
|
||||
function M.profile_end(profile)
|
||||
if M.enabled("profile") and type(profile) == "table" then
|
||||
local millis = profile.start and math.modf((vim.loop.hrtime() - profile.start) / 1000000) or -1
|
||||
local millis = profile.start and math.modf((vim.uv.hrtime() - profile.start) / 1000000) or -1
|
||||
M.line("profile", "END %s %dms", profile.tag or "", millis)
|
||||
end
|
||||
end
|
||||
@@ -110,14 +112,17 @@ function M.enabled(typ)
|
||||
return file_path ~= nil and (types[typ] or types.all)
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
if opts.log and opts.log.enable and opts.log.types then
|
||||
types = opts.log.types
|
||||
--- Create the log file and enable logging, if globally configured
|
||||
function M.start()
|
||||
if config.g.log and config.g.log.enable and config.g.log.types then
|
||||
types = config.g.log.types
|
||||
file_path = string.format("%s/nvim-tree.log", vim.fn.stdpath("log"), os.date("%H:%M:%S"), vim.env.USER)
|
||||
if opts.log.truncate then
|
||||
if config.g.log.truncate then
|
||||
os.remove(file_path)
|
||||
end
|
||||
require("nvim-tree.notify").debug("nvim-tree.lua logging to " .. file_path)
|
||||
if config.g.notify.threshold <= vim.log.levels.DEBUG then
|
||||
require("nvim-tree.notify").debug("nvim-tree.lua logging to " .. file_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ function Marks:bulk_delete()
|
||||
end
|
||||
|
||||
local function execute()
|
||||
for _, node in ipairs(self:list()) do
|
||||
for _, node in ipairs(utils.filter_descendant_nodes(self:list())) do
|
||||
remove_file.remove(node)
|
||||
end
|
||||
self:clear_reload()
|
||||
@@ -221,7 +221,7 @@ function Marks:bulk_trash()
|
||||
end
|
||||
|
||||
local function execute()
|
||||
for _, node in ipairs(self:list()) do
|
||||
for _, node in ipairs(utils.filter_descendant_nodes(self:list())) do
|
||||
trash.remove(node)
|
||||
end
|
||||
self:clear_reload()
|
||||
@@ -274,7 +274,7 @@ function Marks:bulk_move()
|
||||
return
|
||||
end
|
||||
|
||||
for _, node in ipairs(self:list()) do
|
||||
for _, node in ipairs(utils.filter_descendant_nodes(self:list())) do
|
||||
local head = vim.fn.fnamemodify(node.absolute_path, ":t")
|
||||
local to = utils.path_join({ location, head })
|
||||
rename_file.rename(node, to)
|
||||
|
||||
@@ -22,8 +22,8 @@ local DirectoryNode = Node:extend()
|
||||
function DirectoryNode:new(args)
|
||||
DirectoryNode.super.new(self, args)
|
||||
|
||||
local handle = vim.loop.fs_scandir(args.absolute_path)
|
||||
local has_children = handle and vim.loop.fs_scandir_next(handle) ~= nil or false
|
||||
local handle = vim.uv.fs_scandir(args.absolute_path)
|
||||
local has_children = handle and vim.uv.fs_scandir_next(handle) ~= nil or false
|
||||
|
||||
self.type = "directory"
|
||||
|
||||
|
||||
@@ -17,15 +17,15 @@ function M.create(args)
|
||||
|
||||
if args.fs_stat.type == "directory" then
|
||||
-- directory must be readable and enumerable
|
||||
if vim.loop.fs_access(args.absolute_path, "R") and Watcher.is_fs_event_capable(args.absolute_path) then
|
||||
if vim.uv.fs_access(args.absolute_path, "R") and Watcher.is_fs_event_capable(args.absolute_path) then
|
||||
return DirectoryNode(args)
|
||||
end
|
||||
elseif args.fs_stat.type == "file" then
|
||||
return FileNode(args)
|
||||
elseif args.fs_stat.type == "link" then
|
||||
-- link target path and stat must resolve
|
||||
local link_to = vim.loop.fs_realpath(args.absolute_path)
|
||||
local link_to_stat = link_to and vim.loop.fs_stat(link_to)
|
||||
local link_to = vim.uv.fs_realpath(args.absolute_path)
|
||||
local link_to_stat = link_to and vim.uv.fs_stat(link_to)
|
||||
if not link_to or not link_to_stat then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ local Class = require("nvim-tree.classic")
|
||||
|
||||
---Abstract Node class.
|
||||
---@class (exact) Node: nvim_tree.Class
|
||||
---@field uid_node number vim.loop.hrtime() at construction time
|
||||
---@field uid_node number vim.uv.hrtime() at construction time
|
||||
---@field type "file" | "directory" | "link" uv.fs_stat.result.type
|
||||
---@field explorer Explorer
|
||||
---@field absolute_path string
|
||||
@@ -26,7 +26,7 @@ local Node = Class:extend()
|
||||
---@protected
|
||||
---@param args NodeArgs
|
||||
function Node:new(args)
|
||||
self.uid_node = vim.loop.hrtime()
|
||||
self.uid_node = vim.uv.hrtime()
|
||||
self.explorer = args.explorer
|
||||
self.absolute_path = args.absolute_path
|
||||
self.executable = false
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
local M = {}
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local config = {
|
||||
threshold = vim.log.levels.INFO,
|
||||
absolute_path = true,
|
||||
}
|
||||
local M = {}
|
||||
|
||||
local title_support
|
||||
---@return boolean
|
||||
@@ -27,8 +24,11 @@ local modes = {
|
||||
}
|
||||
|
||||
do
|
||||
---@param level vim.log.levels
|
||||
---@param msg string
|
||||
local dispatch = function(level, msg)
|
||||
if level < config.threshold or not msg then
|
||||
local threshold = config.g and config.g.notify.threshold or config.d.notify.threshold
|
||||
if level < threshold or not msg then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -52,17 +52,11 @@ end
|
||||
---@param path string
|
||||
---@return string
|
||||
function M.render_path(path)
|
||||
if config.absolute_path then
|
||||
if config.g and config.g.notify.absolute_path then
|
||||
return path
|
||||
else
|
||||
return vim.fn.fnamemodify(path .. "/", ":h:t")
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
opts = opts or {}
|
||||
config.threshold = opts.notify.threshold or vim.log.levels.INFO
|
||||
config.absolute_path = opts.notify.absolute_path
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
---@alias devicons_get_icon fun(name: string, ext: string?, opts: table?): string?, string?
|
||||
---@alias devicons_setup fun(opts: table?)
|
||||
|
||||
@@ -6,11 +8,18 @@
|
||||
---@field get_icon devicons_get_icon
|
||||
local devicons
|
||||
|
||||
--One shot lazy discovery and setup done
|
||||
local initialized = false
|
||||
|
||||
local M = {}
|
||||
|
||||
---Wrapper around nvim-web-devicons, nils if devicons not available
|
||||
---@type devicons_get_icon
|
||||
function M.get_icon(name, ext, opts)
|
||||
if not initialized then
|
||||
M.initialize()
|
||||
end
|
||||
|
||||
if devicons then
|
||||
return devicons.get_icon(name, ext, opts)
|
||||
else
|
||||
@@ -19,9 +28,8 @@ function M.get_icon(name, ext, opts)
|
||||
end
|
||||
|
||||
---Attempt to use nvim-web-devicons if present and enabled for file or folder
|
||||
---@param opts table
|
||||
function M.setup(opts)
|
||||
if opts.renderer.icons.show.file or opts.renderer.icons.show.folder then
|
||||
function M.initialize()
|
||||
if config.g.renderer.icons.show.file or config.g.renderer.icons.show.folder then
|
||||
local ok, di = pcall(require, "nvim-web-devicons")
|
||||
if ok then
|
||||
devicons = di --[[@as DevIcons]]
|
||||
@@ -30,6 +38,7 @@ function M.setup(opts)
|
||||
devicons.setup()
|
||||
end
|
||||
end
|
||||
initialized = true
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
local config = require("nvim-tree.config")
|
||||
local view_state = require("nvim-tree.view-state")
|
||||
|
||||
local M = {}
|
||||
|
||||
local utils = require("nvim-tree.utils")
|
||||
local view = require("nvim-tree.view")
|
||||
|
||||
local function hide(win)
|
||||
if win then
|
||||
if vim.api.nvim_win_is_valid(win) then
|
||||
vim.api.nvim_win_close(win, true)
|
||||
function M.hide()
|
||||
if M.popup_win and utils.is_nvim_tree_buf(0) then
|
||||
if vim.api.nvim_win_is_valid(M.popup_win) then
|
||||
vim.api.nvim_win_close(M.popup_win, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -33,7 +35,11 @@ local function effective_win_width()
|
||||
return win_width - win_info[1].textoff
|
||||
end
|
||||
|
||||
local function show(opts)
|
||||
function M.show()
|
||||
if not utils.is_nvim_tree_buf(0) then
|
||||
return
|
||||
end
|
||||
|
||||
local line_nr = vim.api.nvim_win_get_cursor(0)[1]
|
||||
if vim.wo.wrap then
|
||||
return
|
||||
@@ -70,9 +76,10 @@ local function show(opts)
|
||||
height = 1,
|
||||
noautocmd = true,
|
||||
style = "minimal",
|
||||
zindex = 40,
|
||||
border = "none"
|
||||
})
|
||||
vim.wo[M.popup_win].winhl = view.View.winopts.winhl
|
||||
vim.wo[M.popup_win].winhl = view_state.Active.winopts.winhl
|
||||
|
||||
local ns_id = vim.api.nvim_get_namespaces()["NvimTreeHighlights"]
|
||||
local extmarks = vim.api.nvim_buf_get_extmarks(0, ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = true })
|
||||
@@ -96,38 +103,10 @@ local function show(opts)
|
||||
end
|
||||
end
|
||||
vim.cmd([[ setlocal nowrap noswapfile nobuflisted buftype=nofile bufhidden=wipe ]])
|
||||
if opts.view.cursorline then
|
||||
if config.g.view.cursorline then
|
||||
vim.cmd([[ setlocal cursorline cursorlineopt=both ]])
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
M.setup = function(opts)
|
||||
M.config = opts.renderer
|
||||
if not M.config.full_name then
|
||||
return
|
||||
end
|
||||
|
||||
local group = vim.api.nvim_create_augroup("nvim_tree_floating_node", { clear = true })
|
||||
vim.api.nvim_create_autocmd({ "BufLeave", "CursorMoved" }, {
|
||||
group = group,
|
||||
pattern = { "NvimTree_*" },
|
||||
callback = function()
|
||||
if utils.is_nvim_tree_buf(0) then
|
||||
hide(M.popup_win)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd({ "CursorMoved" }, {
|
||||
group = group,
|
||||
pattern = { "NvimTree_*" },
|
||||
callback = function()
|
||||
if utils.is_nvim_tree_buf(0) then
|
||||
show(opts)
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
M.full_name = require("nvim-tree.renderer.components.full-name")
|
||||
M.devicons = require("nvim-tree.renderer.components.devicons")
|
||||
M.padding = require("nvim-tree.renderer.components.padding")
|
||||
|
||||
function M.setup(opts)
|
||||
M.full_name.setup(opts)
|
||||
M.devicons.setup(opts)
|
||||
M.padding.setup(opts)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,3 +1,4 @@
|
||||
local config = require("nvim-tree.config")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
local M = {}
|
||||
@@ -27,21 +28,21 @@ local function get_padding_indent_markers(depth, idx, nodes_number, markers, wit
|
||||
|
||||
if depth > 0 then
|
||||
local has_folder_sibling = check_siblings_for_folder(node, with_arrows)
|
||||
local indent = string.rep(" ", M.config.indent_width - 1)
|
||||
local indent = string.rep(" ", config.g.renderer.indent_width - 1)
|
||||
markers[depth] = idx ~= nodes_number
|
||||
for i = 1, depth - early_stop do
|
||||
local glyph
|
||||
if idx == nodes_number and i == depth then
|
||||
local bottom_width = M.config.indent_width - 2 + (with_arrows and not inline_arrows and has_folder_sibling and 2 or 0)
|
||||
glyph = M.config.indent_markers.icons.corner
|
||||
.. string.rep(M.config.indent_markers.icons.bottom, bottom_width)
|
||||
.. (M.config.indent_width > 1 and " " or "")
|
||||
local bottom_width = config.g.renderer.indent_width - 2 + (with_arrows and not inline_arrows and has_folder_sibling and 2 or 0)
|
||||
glyph = config.g.renderer.indent_markers.icons.corner
|
||||
.. string.rep(config.g.renderer.indent_markers.icons.bottom, bottom_width)
|
||||
.. (config.g.renderer.indent_width > 1 and " " or "")
|
||||
elseif markers[i] and i == depth then
|
||||
glyph = M.config.indent_markers.icons.item .. indent
|
||||
glyph = config.g.renderer.indent_markers.icons.item .. indent
|
||||
elseif markers[i] then
|
||||
glyph = M.config.indent_markers.icons.edge .. indent
|
||||
glyph = config.g.renderer.indent_markers.icons.edge .. indent
|
||||
else
|
||||
glyph = M.config.indent_markers.icons.none .. indent
|
||||
glyph = config.g.renderer.indent_markers.icons.none .. indent
|
||||
end
|
||||
|
||||
if not with_arrows or (inline_arrows and (depth ~= i or not node.nodes)) then
|
||||
@@ -68,10 +69,10 @@ end
|
||||
function M.get_indent_markers(depth, idx, nodes_number, node, markers, early_stop)
|
||||
local str = ""
|
||||
|
||||
local show_arrows = M.config.icons.show.folder_arrow
|
||||
local show_markers = M.config.indent_markers.enable
|
||||
local inline_arrows = M.config.indent_markers.inline_arrows
|
||||
local indent_width = M.config.indent_width
|
||||
local show_arrows = config.g.renderer.icons.show.folder_arrow
|
||||
local show_markers = config.g.renderer.indent_markers.enable
|
||||
local inline_arrows = config.g.renderer.indent_markers.inline_arrows
|
||||
local indent_width = config.g.renderer.indent_width
|
||||
|
||||
if show_markers then
|
||||
str = str .. get_padding_indent_markers(depth, idx, nodes_number, markers, show_arrows, inline_arrows, node, early_stop or 0)
|
||||
@@ -85,7 +86,7 @@ end
|
||||
---@param node Node
|
||||
---@return nvim_tree.api.highlighted_string[]?
|
||||
function M.get_arrows(node)
|
||||
if not M.config.icons.show.folder_arrow then
|
||||
if not config.g.renderer.icons.show.folder_arrow then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -95,38 +96,18 @@ function M.get_arrows(node)
|
||||
local dir = node:as(DirectoryNode)
|
||||
if dir then
|
||||
if dir.open then
|
||||
str = M.config.icons.glyphs.folder["arrow_open"] .. M.config.icons.padding.folder_arrow
|
||||
str = config.g.renderer.icons.glyphs.folder["arrow_open"] .. config.g.renderer.icons.padding.folder_arrow
|
||||
hl = "NvimTreeFolderArrowOpen"
|
||||
else
|
||||
str = M.config.icons.glyphs.folder["arrow_closed"] .. M.config.icons.padding.folder_arrow
|
||||
str = config.g.renderer.icons.glyphs.folder["arrow_closed"] .. config.g.renderer.icons.padding.folder_arrow
|
||||
end
|
||||
elseif M.config.indent_markers.enable then
|
||||
elseif config.g.renderer.indent_markers.enable then
|
||||
str = ""
|
||||
else
|
||||
str = " " .. string.rep(" ", #M.config.icons.padding.folder_arrow)
|
||||
str = " " .. string.rep(" ", #config.g.renderer.icons.padding.folder_arrow)
|
||||
end
|
||||
|
||||
return { str = str, hl = { hl } }
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config = opts.renderer
|
||||
|
||||
if M.config.indent_width < 1 then
|
||||
M.config.indent_width = 1
|
||||
end
|
||||
|
||||
local function check_marker(symbol)
|
||||
if #symbol == 0 then
|
||||
return " "
|
||||
end
|
||||
-- return the first character from the UTF-8 encoded string; we may use utf8.codes from Lua 5.3 when available
|
||||
return symbol:match("[%z\1-\127\194-\244][\128-\191]*")
|
||||
end
|
||||
|
||||
for k, v in pairs(M.config.indent_markers.icons) do
|
||||
M.config.indent_markers.icons[k] = check_marker(v)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -37,20 +37,12 @@ end
|
||||
---@param extmarks table[] extra marks for right icon placement
|
||||
---@param virtual_lines table[] virtual lines for hidden count display
|
||||
function Renderer:_draw(bufnr, lines, hl_range_args, signs, extmarks, virtual_lines)
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = bufnr })
|
||||
else
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", true) ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = bufnr })
|
||||
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
self:render_hl(bufnr, hl_range_args)
|
||||
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
|
||||
else
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", false) ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
|
||||
|
||||
vim.fn.sign_unplace(SIGN_GROUP)
|
||||
for i, sign_name in pairs(signs) do
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local M = {
|
||||
debouncers = {},
|
||||
}
|
||||
|
||||
M.is_unix = vim.fn.has("unix") == 1
|
||||
M.is_macos = vim.fn.has("mac") == 1 or vim.fn.has("macunix") == 1
|
||||
M.is_wsl = vim.fn.has("wsl") == 1
|
||||
-- false for WSL
|
||||
M.is_windows = vim.fn.has("win32") == 1 or vim.fn.has("win32unix") == 1
|
||||
|
||||
---@param haystack string
|
||||
---@param needle string
|
||||
---@return boolean
|
||||
@@ -78,7 +74,7 @@ function M.path_relative(path, relative_to)
|
||||
end
|
||||
|
||||
local norm_path = path
|
||||
if M.is_windows then
|
||||
if config.os.windows then
|
||||
norm_path = win_norm_path(norm_path)
|
||||
end
|
||||
|
||||
@@ -168,12 +164,7 @@ function M.rename_loaded_buffers(old_path, new_path)
|
||||
vim.api.nvim_buf_set_name(buf, new_path .. buf_name:sub(#old_path + 1))
|
||||
-- to avoid the 'overwrite existing file' error message on write for
|
||||
-- normal files
|
||||
local buftype
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
buftype = vim.api.nvim_get_option_value("buftype", { buf = buf })
|
||||
else
|
||||
buftype = vim.api.nvim_buf_get_option(buf, "buftype") ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
local buftype = vim.api.nvim_get_option_value("buftype", { buf = buf })
|
||||
|
||||
if buftype == "" then
|
||||
vim.api.nvim_buf_call(buf, function()
|
||||
@@ -187,14 +178,14 @@ function M.rename_loaded_buffers(old_path, new_path)
|
||||
end
|
||||
|
||||
local is_windows_drive = function(path)
|
||||
return (M.is_windows) and (path:match("^%a:\\$") ~= nil)
|
||||
return (config.os.windows) and (path:match("^%a:\\$") ~= nil)
|
||||
end
|
||||
|
||||
---@param path string path to file or directory
|
||||
---@return boolean
|
||||
function M.file_exists(path)
|
||||
if not (M.is_windows or M.is_wsl) then
|
||||
local _, error = vim.loop.fs_stat(path)
|
||||
if not (config.os.windows or config.os.wsl) then
|
||||
local _, error = vim.uv.fs_stat(path)
|
||||
return error == nil
|
||||
end
|
||||
|
||||
@@ -214,14 +205,14 @@ function M.file_exists(path)
|
||||
local parent = vim.fn.fnamemodify(path, ":h")
|
||||
local filename = vim.fn.fnamemodify(path, ":t")
|
||||
|
||||
local handle = vim.loop.fs_scandir(parent)
|
||||
local handle = vim.uv.fs_scandir(parent)
|
||||
if not handle then
|
||||
-- File can not exist if its parent directory does not exist
|
||||
return false
|
||||
end
|
||||
|
||||
while true do
|
||||
local name, _ = vim.loop.fs_scandir_next(handle)
|
||||
local name, _ = vim.uv.fs_scandir_next(handle)
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
@@ -236,7 +227,7 @@ end
|
||||
---@param path string
|
||||
---@return string
|
||||
function M.canonical_path(path)
|
||||
if M.is_windows and path:match("^%a:") then
|
||||
if config.os.windows and path:match("^%a:") then
|
||||
return path:sub(1, 1):upper() .. path:sub(2)
|
||||
end
|
||||
return path
|
||||
@@ -257,7 +248,7 @@ function M.escape_special_chars(path)
|
||||
if path == nil then
|
||||
return path
|
||||
end
|
||||
return M.is_windows and escape_special_char_for_windows(path) or path
|
||||
return config.os.windows and escape_special_char_for_windows(path) or path
|
||||
end
|
||||
|
||||
local function round(value)
|
||||
@@ -340,7 +331,7 @@ function M.debounce(context, timeout, callback)
|
||||
timer_stop_close(debouncer.timer)
|
||||
end
|
||||
|
||||
local timer = vim.loop.new_timer()
|
||||
local timer = vim.uv.new_timer()
|
||||
if not timer then
|
||||
return
|
||||
end
|
||||
@@ -447,11 +438,11 @@ end
|
||||
---@param absolute_path string
|
||||
---@return boolean
|
||||
function M.is_executable(absolute_path)
|
||||
if M.is_windows or M.is_wsl then
|
||||
if config.os.windows or config.os.wsl then
|
||||
--- executable detection on windows is buggy and not performant hence it is disabled
|
||||
return false
|
||||
else
|
||||
return vim.loop.fs_access(absolute_path, "X") or false
|
||||
return vim.uv.fs_access(absolute_path, "X") or false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
109
lua/nvim-tree/view-state.lua
Normal file
109
lua/nvim-tree/view-state.lua
Normal file
@@ -0,0 +1,109 @@
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local M = {}
|
||||
|
||||
local DEFAULT_MIN_WIDTH = 30
|
||||
local DEFAULT_MAX_WIDTH = -1
|
||||
local DEFAULT_LINES_EXCLUDED = {
|
||||
"root",
|
||||
}
|
||||
local DEFAULT_PADDING = 1
|
||||
|
||||
M.Active = {
|
||||
adaptive_size = false,
|
||||
tabpages = {},
|
||||
cursors = {},
|
||||
winopts = {
|
||||
relativenumber = false,
|
||||
number = false,
|
||||
list = false,
|
||||
foldenable = false,
|
||||
winfixwidth = true,
|
||||
winfixheight = true,
|
||||
spell = false,
|
||||
signcolumn = "yes",
|
||||
foldmethod = "manual",
|
||||
foldcolumn = "0",
|
||||
cursorcolumn = false,
|
||||
cursorline = true,
|
||||
cursorlineopt = "both",
|
||||
colorcolumn = "0",
|
||||
wrap = false,
|
||||
winhl = table.concat({
|
||||
"EndOfBuffer:NvimTreeEndOfBuffer",
|
||||
"CursorLine:NvimTreeCursorLine",
|
||||
"CursorLineNr:NvimTreeCursorLineNr",
|
||||
"LineNr:NvimTreeLineNr",
|
||||
"WinSeparator:NvimTreeWinSeparator",
|
||||
"StatusLine:NvimTreeStatusLine",
|
||||
"StatusLineNC:NvimTreeStatuslineNC",
|
||||
"SignColumn:NvimTreeSignColumn",
|
||||
"Normal:NvimTreeNormal",
|
||||
"NormalNC:NvimTreeNormalNC",
|
||||
"NormalFloat:NvimTreeNormalFloat",
|
||||
"FloatBorder:NvimTreeNormalFloatBorder",
|
||||
}, ","),
|
||||
},
|
||||
}
|
||||
|
||||
---@param size (fun():integer)|integer|string
|
||||
---@return integer
|
||||
function M.get_size(size)
|
||||
if type(size) == "number" then
|
||||
return size
|
||||
elseif type(size) == "function" then
|
||||
return M.get_size(size())
|
||||
end
|
||||
local size_as_number = tonumber(size:sub(0, -2))
|
||||
local percent_as_decimal = size_as_number / 100
|
||||
return math.floor(vim.o.columns * percent_as_decimal)
|
||||
end
|
||||
|
||||
---@param size (fun():integer)|integer|nil
|
||||
---@return integer
|
||||
function M.get_width(size)
|
||||
if size then
|
||||
return M.get_size(size)
|
||||
else
|
||||
return M.get_size(M.Active.width)
|
||||
end
|
||||
end
|
||||
|
||||
---Configure width-related config
|
||||
---@param width string|function|number|table|nil
|
||||
local function configure_width(width)
|
||||
if type(width) == "table" then
|
||||
M.Active.adaptive_size = true
|
||||
M.Active.width = width.min or DEFAULT_MIN_WIDTH
|
||||
M.Active.max_width = width.max or DEFAULT_MAX_WIDTH
|
||||
local lines_excluded = width.lines_excluded or DEFAULT_LINES_EXCLUDED
|
||||
M.Active.root_excluded = vim.tbl_contains(lines_excluded, "root")
|
||||
M.Active.padding = width.padding or DEFAULT_PADDING
|
||||
elseif width == nil then
|
||||
if config.g.view.width ~= nil then
|
||||
-- if we had input config - fallback to it
|
||||
M.configure_width(config.g.view.width)
|
||||
else
|
||||
-- otherwise - restore initial width
|
||||
M.Active.width = M.Active.initial_width
|
||||
end
|
||||
else
|
||||
M.Active.adaptive_size = false
|
||||
M.Active.width = width
|
||||
end
|
||||
end
|
||||
|
||||
---Apply global configuration to Active
|
||||
function M.initialize()
|
||||
M.Active.winopts.cursorline = config.g.view.cursorline
|
||||
M.Active.winopts.cursorlineopt = config.g.view.cursorlineopt
|
||||
M.Active.winopts.number = config.g.view.number
|
||||
M.Active.winopts.relativenumber = config.g.view.relativenumber
|
||||
M.Active.winopts.signcolumn = config.g.view.signcolumn
|
||||
|
||||
configure_width(config.g.view.width)
|
||||
|
||||
M.Active.initial_width = M.get_width()
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,7 +1,9 @@
|
||||
local view_state = require("nvim-tree.view-state")
|
||||
local events = require("nvim-tree.events")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local log = require("nvim-tree.log")
|
||||
local notify = require("nvim-tree.notify")
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
---@class OpenInWinOpts
|
||||
---@field hijack_current_buf boolean|nil default true
|
||||
@@ -10,55 +12,6 @@ local notify = require("nvim-tree.notify")
|
||||
|
||||
local M = {}
|
||||
|
||||
local DEFAULT_MIN_WIDTH = 30
|
||||
local DEFAULT_MAX_WIDTH = -1
|
||||
local DEFAULT_LINES_EXCLUDED = {
|
||||
"root",
|
||||
}
|
||||
local DEFAULT_PADDING = 1
|
||||
|
||||
M.View = {
|
||||
adaptive_size = false,
|
||||
centralize_selection = false,
|
||||
tabpages = {},
|
||||
cursors = {},
|
||||
hide_root_folder = false,
|
||||
live_filter = {
|
||||
prev_focused_node = nil,
|
||||
},
|
||||
winopts = {
|
||||
relativenumber = false,
|
||||
number = false,
|
||||
list = false,
|
||||
foldenable = false,
|
||||
winfixwidth = true,
|
||||
winfixheight = true,
|
||||
spell = false,
|
||||
signcolumn = "yes",
|
||||
foldmethod = "manual",
|
||||
foldcolumn = "0",
|
||||
cursorcolumn = false,
|
||||
cursorline = true,
|
||||
cursorlineopt = "both",
|
||||
colorcolumn = "0",
|
||||
wrap = false,
|
||||
winhl = table.concat({
|
||||
"EndOfBuffer:NvimTreeEndOfBuffer",
|
||||
"CursorLine:NvimTreeCursorLine",
|
||||
"CursorLineNr:NvimTreeCursorLineNr",
|
||||
"LineNr:NvimTreeLineNr",
|
||||
"WinSeparator:NvimTreeWinSeparator",
|
||||
"StatusLine:NvimTreeStatusLine",
|
||||
"StatusLineNC:NvimTreeStatuslineNC",
|
||||
"SignColumn:NvimTreeSignColumn",
|
||||
"Normal:NvimTreeNormal",
|
||||
"NormalNC:NvimTreeNormalNC",
|
||||
"NormalFloat:NvimTreeNormalFloat",
|
||||
"FloatBorder:NvimTreeNormalFloatBorder",
|
||||
}, ","),
|
||||
},
|
||||
}
|
||||
|
||||
-- The initial state of a tab
|
||||
local tabinitial = {
|
||||
-- The position of the cursor { line, column }
|
||||
@@ -117,29 +70,6 @@ local function create_buffer(bufnr)
|
||||
events._dispatch_tree_attached_post(M.get_bufnr())
|
||||
end
|
||||
|
||||
---@param size (fun():integer)|integer|string
|
||||
---@return integer
|
||||
local function get_size(size)
|
||||
if type(size) == "number" then
|
||||
return size
|
||||
elseif type(size) == "function" then
|
||||
return get_size(size())
|
||||
end
|
||||
local size_as_number = tonumber(size:sub(0, -2))
|
||||
local percent_as_decimal = size_as_number / 100
|
||||
return math.floor(vim.o.columns * percent_as_decimal)
|
||||
end
|
||||
|
||||
---@param size (fun():integer)|integer|nil
|
||||
---@return integer
|
||||
local function get_width(size)
|
||||
if size then
|
||||
return get_size(size)
|
||||
else
|
||||
return get_size(M.View.width)
|
||||
end
|
||||
end
|
||||
|
||||
local move_tbl = {
|
||||
left = "H",
|
||||
right = "L",
|
||||
@@ -149,46 +79,33 @@ local move_tbl = {
|
||||
---@param tabpage integer
|
||||
local function setup_tabpage(tabpage)
|
||||
local winnr = vim.api.nvim_get_current_win()
|
||||
M.View.tabpages[tabpage] = vim.tbl_extend("force", M.View.tabpages[tabpage] or tabinitial, { winnr = winnr })
|
||||
view_state.Active.tabpages[tabpage] = vim.tbl_extend("force", view_state.Active.tabpages[tabpage] or tabinitial, { winnr = winnr })
|
||||
end
|
||||
|
||||
local function set_window_options_and_buffer()
|
||||
pcall(vim.api.nvim_command, "buffer " .. M.get_bufnr())
|
||||
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
local eventignore = vim.api.nvim_get_option_value("eventignore", {})
|
||||
vim.api.nvim_set_option_value("eventignore", "all", {})
|
||||
local eventignore = vim.api.nvim_get_option_value("eventignore", {})
|
||||
vim.api.nvim_set_option_value("eventignore", "all", {})
|
||||
|
||||
for k, v in pairs(M.View.winopts) do
|
||||
vim.api.nvim_set_option_value(k, v, { scope = "local" })
|
||||
end
|
||||
|
||||
vim.api.nvim_set_option_value("eventignore", eventignore, {})
|
||||
else
|
||||
local eventignore = vim.api.nvim_get_option("eventignore") ---@diagnostic disable-line: deprecated
|
||||
vim.api.nvim_set_option("eventignore", "all") ---@diagnostic disable-line: deprecated
|
||||
|
||||
-- #3009 vim.api.nvim_win_set_option does not set local scope without explicit winid.
|
||||
-- Revert to opt_local instead of propagating it through for just the 0.10 path.
|
||||
for k, v in pairs(M.View.winopts) do
|
||||
vim.opt_local[k] = v
|
||||
end
|
||||
|
||||
vim.api.nvim_set_option("eventignore", eventignore) ---@diagnostic disable-line: deprecated
|
||||
for k, v in pairs(view_state.Active.winopts) do
|
||||
vim.api.nvim_set_option_value(k, v, { scope = "local" })
|
||||
end
|
||||
|
||||
vim.api.nvim_set_option_value("eventignore", eventignore, {})
|
||||
end
|
||||
|
||||
---@return table
|
||||
---@return vim.api.keyset.win_config
|
||||
local function open_win_config()
|
||||
if type(M.View.float.open_win_config) == "function" then
|
||||
return M.View.float.open_win_config()
|
||||
if type(config.g.view.float.open_win_config) == "function" then
|
||||
return config.g.view.float.open_win_config()
|
||||
else
|
||||
return M.View.float.open_win_config
|
||||
return config.g.view.float.open_win_config --[[ @as vim.api.keyset.win_config ]]
|
||||
end
|
||||
end
|
||||
|
||||
local function open_window()
|
||||
if M.View.float.enable then
|
||||
if config.g.view.float.enable then
|
||||
vim.api.nvim_open_win(0, true, open_win_config())
|
||||
else
|
||||
vim.api.nvim_command("vsp")
|
||||
@@ -233,7 +150,7 @@ end
|
||||
---@param tabnr integer
|
||||
local function save_tab_state(tabnr)
|
||||
local tabpage = tabnr or vim.api.nvim_get_current_tabpage()
|
||||
M.View.cursors[tabpage] = vim.api.nvim_win_get_cursor(M.get_winnr(tabpage) or 0)
|
||||
view_state.Active.cursors[tabpage] = vim.api.nvim_win_get_cursor(M.get_winnr(tabpage) or 0)
|
||||
end
|
||||
|
||||
---@param tabpage integer
|
||||
@@ -268,14 +185,14 @@ function M.close_this_tab_only()
|
||||
end
|
||||
|
||||
function M.close_all_tabs()
|
||||
for tabpage, _ in pairs(M.View.tabpages) do
|
||||
for tabpage, _ in pairs(view_state.Active.tabpages) do
|
||||
close(tabpage)
|
||||
end
|
||||
end
|
||||
|
||||
---@param tabpage integer|nil
|
||||
function M.close(tabpage)
|
||||
if M.View.tab.sync.close then
|
||||
if config.g.tab.sync.close then
|
||||
M.close_all_tabs()
|
||||
elseif tabpage then
|
||||
close(tabpage)
|
||||
@@ -307,10 +224,10 @@ function M.open(options)
|
||||
end
|
||||
|
||||
local function grow()
|
||||
local starts_at = (M.is_root_folder_visible(require("nvim-tree.core").get_cwd()) and M.View.root_excluded) and 1 or 0
|
||||
local starts_at = (M.is_root_folder_visible(require("nvim-tree.core").get_cwd()) and view_state.Active.root_excluded) and 1 or 0
|
||||
local lines = vim.api.nvim_buf_get_lines(M.get_bufnr(), starts_at, -1, false)
|
||||
-- number of columns of right-padding to indicate end of path
|
||||
local padding = get_size(M.View.padding)
|
||||
local padding = view_state.get_size(view_state.Active.padding)
|
||||
|
||||
-- account for sign/number columns etc.
|
||||
local wininfo = vim.fn.getwininfo(M.get_winnr())
|
||||
@@ -318,8 +235,8 @@ local function grow()
|
||||
padding = padding + wininfo[1].textoff
|
||||
end
|
||||
|
||||
local final_width = M.View.initial_width
|
||||
local max_width = get_width(M.View.max_width)
|
||||
local final_width = view_state.Active.initial_width
|
||||
local max_width = view_state.get_width(view_state.Active.max_width)
|
||||
if max_width == -1 then
|
||||
max_width = math.huge
|
||||
end
|
||||
@@ -341,14 +258,14 @@ local function grow()
|
||||
end
|
||||
|
||||
function M.grow_from_content()
|
||||
if M.View.adaptive_size then
|
||||
if view_state.Active.adaptive_size then
|
||||
grow()
|
||||
end
|
||||
end
|
||||
|
||||
---@param size string|number|nil
|
||||
function M.resize(size)
|
||||
if M.View.float.enable and not M.View.adaptive_size then
|
||||
if config.g.view.float.enable and not view_state.Active.adaptive_size then
|
||||
-- if the floating windows's adaptive size is not desired, then the
|
||||
-- float size should be defined in view.float.open_win_config
|
||||
return
|
||||
@@ -360,7 +277,7 @@ function M.resize(size)
|
||||
size = tonumber(size)
|
||||
|
||||
if first_char == "+" or first_char == "-" then
|
||||
size = M.View.width + size
|
||||
size = view_state.Active.width + size
|
||||
end
|
||||
end
|
||||
|
||||
@@ -369,8 +286,7 @@ function M.resize(size)
|
||||
end
|
||||
|
||||
if size then
|
||||
M.View.width = size
|
||||
M.View.height = size
|
||||
view_state.Active.width = size
|
||||
end
|
||||
|
||||
if not M.is_visible() then
|
||||
@@ -379,11 +295,11 @@ function M.resize(size)
|
||||
|
||||
local winnr = M.get_winnr() or 0
|
||||
|
||||
local new_size = get_width()
|
||||
local new_size = view_state.get_width()
|
||||
|
||||
if new_size ~= vim.api.nvim_win_get_width(winnr) then
|
||||
vim.api.nvim_win_set_width(winnr, new_size)
|
||||
if not M.View.preserve_window_proportions then
|
||||
if not config.g.view.preserve_window_proportions then
|
||||
vim.cmd(":wincmd =")
|
||||
end
|
||||
end
|
||||
@@ -392,14 +308,14 @@ function M.resize(size)
|
||||
end
|
||||
|
||||
function M.reposition_window()
|
||||
local move_to = move_tbl[M.View.side]
|
||||
local move_to = move_tbl[config.g.view.side]
|
||||
vim.api.nvim_command("wincmd " .. move_to)
|
||||
M.resize()
|
||||
end
|
||||
|
||||
local function set_current_win()
|
||||
local current_tab = vim.api.nvim_get_current_tabpage()
|
||||
M.View.tabpages[current_tab].winnr = vim.api.nvim_get_current_win()
|
||||
view_state.Active.tabpages[current_tab].winnr = vim.api.nvim_get_current_win()
|
||||
end
|
||||
|
||||
---Open the tree in the a window
|
||||
@@ -424,16 +340,16 @@ end
|
||||
function M.abandon_current_window()
|
||||
local tab = vim.api.nvim_get_current_tabpage()
|
||||
BUFNR_PER_TAB[tab] = nil
|
||||
if M.View.tabpages[tab] then
|
||||
M.View.tabpages[tab].winnr = nil
|
||||
if view_state.Active.tabpages[tab] then
|
||||
view_state.Active.tabpages[tab].winnr = nil
|
||||
end
|
||||
end
|
||||
|
||||
function M.abandon_all_windows()
|
||||
for tab, _ in pairs(vim.api.nvim_list_tabpages()) do
|
||||
BUFNR_PER_TAB[tab] = nil
|
||||
if M.View.tabpages[tab] then
|
||||
M.View.tabpages[tab].winnr = nil
|
||||
if view_state.Active.tabpages[tab] then
|
||||
view_state.Active.tabpages[tab].winnr = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -442,15 +358,15 @@ end
|
||||
---@return boolean
|
||||
function M.is_visible(opts)
|
||||
if opts and opts.tabpage then
|
||||
if M.View.tabpages[opts.tabpage] == nil then
|
||||
if view_state.Active.tabpages[opts.tabpage] == nil then
|
||||
return false
|
||||
end
|
||||
local winnr = M.View.tabpages[opts.tabpage].winnr
|
||||
local winnr = view_state.Active.tabpages[opts.tabpage].winnr
|
||||
return winnr and vim.api.nvim_win_is_valid(winnr)
|
||||
end
|
||||
|
||||
if opts and opts.any_tabpage then
|
||||
for _, v in pairs(M.View.tabpages) do
|
||||
for _, v in pairs(view_state.Active.tabpages) do
|
||||
if v.winnr and vim.api.nvim_win_is_valid(v.winnr) then
|
||||
return true
|
||||
end
|
||||
@@ -504,7 +420,7 @@ end
|
||||
--- Restores the state of a NvimTree window if it was initialized before.
|
||||
function M.restore_tab_state()
|
||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
M.set_cursor(M.View.cursors[tabpage])
|
||||
M.set_cursor(view_state.Active.cursors[tabpage])
|
||||
end
|
||||
|
||||
--- Returns the window number for nvim-tree within the tabpage specified
|
||||
@@ -512,7 +428,7 @@ end
|
||||
---@return number|nil
|
||||
function M.get_winnr(tabpage)
|
||||
tabpage = tabpage or vim.api.nvim_get_current_tabpage()
|
||||
local tabinfo = M.View.tabpages[tabpage]
|
||||
local tabinfo = view_state.Active.tabpages[tabpage]
|
||||
if tabinfo and tabinfo.winnr and vim.api.nvim_win_is_valid(tabinfo.winnr) then
|
||||
return tabinfo.winnr
|
||||
end
|
||||
@@ -538,9 +454,9 @@ function M._prevent_buffer_override()
|
||||
local bufname = vim.api.nvim_buf_get_name(curbuf)
|
||||
|
||||
if not bufname:match("NvimTree") then
|
||||
for i, tabpage in ipairs(M.View.tabpages) do
|
||||
for i, tabpage in ipairs(view_state.Active.tabpages) do
|
||||
if tabpage.winnr == view_winnr then
|
||||
M.View.tabpages[i] = nil
|
||||
view_state.Active.tabpages[i] = nil
|
||||
break
|
||||
end
|
||||
end
|
||||
@@ -575,67 +491,34 @@ end
|
||||
---@param cwd string|nil
|
||||
---@return boolean
|
||||
function M.is_root_folder_visible(cwd)
|
||||
return cwd ~= "/" and not M.View.hide_root_folder
|
||||
return cwd ~= "/" and config.g.renderer.root_folder_label ~= false
|
||||
end
|
||||
|
||||
-- used on ColorScheme event
|
||||
function M.reset_winhl()
|
||||
local winnr = M.get_winnr()
|
||||
if winnr and vim.api.nvim_win_is_valid(winnr) then
|
||||
vim.wo[M.get_winnr()].winhl = M.View.winopts.winhl
|
||||
vim.wo[M.get_winnr()].winhl = view_state.Active.winopts.winhl
|
||||
end
|
||||
end
|
||||
|
||||
---Check if width determined or calculated on-fly
|
||||
---@return boolean
|
||||
function M.is_width_determined()
|
||||
return type(M.View.width) ~= "function"
|
||||
return type(view_state.Active.width) ~= "function"
|
||||
end
|
||||
|
||||
---Configure width-related config
|
||||
---@param width string|function|number|table|nil
|
||||
function M.configure_width(width)
|
||||
if type(width) == "table" then
|
||||
M.View.adaptive_size = true
|
||||
M.View.width = width.min or DEFAULT_MIN_WIDTH
|
||||
M.View.max_width = width.max or DEFAULT_MAX_WIDTH
|
||||
local lines_excluded = width.lines_excluded or DEFAULT_LINES_EXCLUDED
|
||||
M.View.root_excluded = vim.tbl_contains(lines_excluded, "root")
|
||||
M.View.padding = width.padding or DEFAULT_PADDING
|
||||
elseif width == nil then
|
||||
if M.config.width ~= nil then
|
||||
-- if we had input config - fallback to it
|
||||
M.configure_width(M.config.width)
|
||||
else
|
||||
-- otherwise - restore initial width
|
||||
M.View.width = M.View.initial_width
|
||||
end
|
||||
---Called on BufWipeout
|
||||
---Prevent new opened file from opening in the same window as nvim-tree
|
||||
function M.wipeout()
|
||||
if not utils.is_nvim_tree_buf(0) then
|
||||
return
|
||||
end
|
||||
if config.g.actions.open_file.eject then
|
||||
M._prevent_buffer_override()
|
||||
else
|
||||
M.View.adaptive_size = false
|
||||
M.View.width = width
|
||||
M.abandon_current_window()
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
local options = opts.view or {}
|
||||
M.View.centralize_selection = options.centralize_selection
|
||||
M.View.side = (options.side == "right") and "right" or "left"
|
||||
M.View.height = options.height
|
||||
M.View.hide_root_folder = opts.renderer.root_folder_label == false
|
||||
M.View.tab = opts.tab
|
||||
M.View.preserve_window_proportions = options.preserve_window_proportions
|
||||
M.View.winopts.cursorline = options.cursorline
|
||||
M.View.winopts.cursorlineopt = options.cursorlineopt
|
||||
M.View.winopts.number = options.number
|
||||
M.View.winopts.relativenumber = options.relativenumber
|
||||
M.View.winopts.signcolumn = options.signcolumn
|
||||
M.View.float = options.float
|
||||
M.on_attach = opts.on_attach
|
||||
|
||||
M.config = options
|
||||
M.configure_width(options.width)
|
||||
|
||||
M.View.initial_width = get_width()
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local notify = require("nvim-tree.notify")
|
||||
local log = require("nvim-tree.log")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local config = require("nvim-tree.config")
|
||||
|
||||
local Class = require("nvim-tree.classic")
|
||||
|
||||
@@ -13,9 +14,7 @@ local FS_EVENT_FLAGS = {
|
||||
recursive = false,
|
||||
}
|
||||
|
||||
local M = {
|
||||
config = {},
|
||||
}
|
||||
local M = {}
|
||||
|
||||
---Registry of all events
|
||||
---@type Event[]
|
||||
@@ -67,7 +66,7 @@ function Event:start()
|
||||
|
||||
local rc, _, name
|
||||
|
||||
self.fs_event, _, name = vim.loop.new_fs_event()
|
||||
self.fs_event, _, name = vim.uv.new_fs_event()
|
||||
if not self.fs_event then
|
||||
self.fs_event = nil
|
||||
notify.warn(string.format("Could not initialize an fs_event watcher for path %s : %s", self.path, name))
|
||||
@@ -79,7 +78,7 @@ function Event:start()
|
||||
log.line("watcher", "event_cb '%s' '%s' FAIL : %s", self.path, filename, err)
|
||||
|
||||
-- do nothing if watchers have already been disabled
|
||||
if not M.config.filesystem_watchers.enable then
|
||||
if not config.g.filesystem_watchers.enable then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -90,7 +89,7 @@ function Event:start()
|
||||
end
|
||||
|
||||
local message = string.format("File system watcher failed (%s) for path %s, halting watcher.", err, self.path)
|
||||
if err == "EPERM" and (utils.is_windows or utils.is_wsl) then
|
||||
if err == "EPERM" and (config.os.windows or config.os.wsl) then
|
||||
-- on directory removal windows will cascade the filesystem events out of order
|
||||
log.line("watcher", message)
|
||||
self:destroy()
|
||||
@@ -238,8 +237,8 @@ M.Watcher = Watcher
|
||||
---@param msg string
|
||||
function M.disable_watchers(msg)
|
||||
notify.warn(string.format("Disabling watchers: %s", msg))
|
||||
M.config.filesystem_watchers.enable = false
|
||||
require("nvim-tree").purge_all_state()
|
||||
config.g.filesystem_watchers.enable = false
|
||||
require("nvim-tree.core").purge_all_state()
|
||||
end
|
||||
|
||||
function M.purge_watchers()
|
||||
@@ -259,11 +258,11 @@ end
|
||||
---@param path string
|
||||
---@return boolean
|
||||
function M.is_fs_event_capable(path)
|
||||
if not utils.is_windows then
|
||||
if not config.os.windows then
|
||||
return true
|
||||
end
|
||||
|
||||
local fs_event = vim.loop.new_fs_event()
|
||||
local fs_event = vim.uv.new_fs_event()
|
||||
if not fs_event then
|
||||
return false
|
||||
end
|
||||
@@ -279,8 +278,4 @@ function M.is_fs_event_capable(path)
|
||||
return true
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config.filesystem_watchers = opts.filesystem_watchers
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,26 +1,17 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Wrapper around Nvim make targets:
|
||||
# Wrapper around Nvim make doc target:
|
||||
#
|
||||
# make doc - gen_vimdoc.lua
|
||||
# Generates doc/nvim-tree-lua.txt
|
||||
# Uses nvim-tree sources defined in scripts/vimdoc_config.lua
|
||||
# Shims above into src/gen/gen_vimdoc.lua, replacing Nvim's config.
|
||||
#
|
||||
# make lintdoc - lintdoc.lua
|
||||
# Validates doc/nvim-tree-lua.txt
|
||||
# Desired:
|
||||
# - tags valid
|
||||
# - links valid
|
||||
# Also:
|
||||
# - brand spelling, notably Nvim and Lua
|
||||
# Generates doc/nvim-tree-lua.txt
|
||||
# Uses nvim-tree sources defined in scripts/vimdoc_config.lua
|
||||
# Shims above into src/gen/gen_vimdoc.lua, replacing Nvim's config.
|
||||
#
|
||||
# There are some hardcoded expectations which we work around as commented.
|
||||
|
||||
set -e
|
||||
|
||||
if [ $# -ne 1 ] || [ "${1}" != "doc" ] && [ "${1}" != "lintdoc" ]; then
|
||||
echo "usage: ${0} <doc|lintdoc>" 1>&2
|
||||
if [ $# -ne 1 ] || [ "${1}" != "doc" ]; then
|
||||
echo "usage: ${0} <doc>" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -38,7 +29,7 @@ fi
|
||||
if [ ! -d "${DIR_NVIM_SRC}" ]; then
|
||||
cat << EOM
|
||||
|
||||
Nvim source v0.11+ is required to run ${0}
|
||||
Nvim stable source is required to run ${0}
|
||||
|
||||
Unavailable: ${DIR_NVIM_SRC_DEF} or \$DIR_NVIM_SRC=${DIR_NVIM_SRC}
|
||||
|
||||
@@ -84,7 +75,15 @@ if [ "${1}" = "doc" ]; then
|
||||
|
||||
# modify gen_vimdoc.lua to use our config, backing up original
|
||||
cp "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua" "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua.org"
|
||||
sed -i -E 's/spairs\(config\)/spairs\(require("gen.vimdoc_config")\)/g' "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua"
|
||||
sed -i -E '
|
||||
|
||||
# use our config
|
||||
s/spairs\(config\)/spairs\(require("gen.vimdoc_config") --[[injected by nvim-tree]]\)/g ;
|
||||
|
||||
# remove the name linter
|
||||
s/(^run\(\)$)/\n--injected by nvim-tree\nlint.lint_names = function\(\)\nend\n\n\1 --/g
|
||||
|
||||
' "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua"
|
||||
|
||||
# leave a generic placeholder to bridge between nvim.gen_vimdoc.Config
|
||||
echo "---@brief placeholder" > "${DIR_NVIM_SRC}/runtime/lua/placeholder.lua"
|
||||
|
||||
@@ -22,7 +22,6 @@ local srcs_config = {
|
||||
{ helptag = "nvim-tree-config-renderer", section = "Config: renderer", path = base .. "_meta/config/renderer.lua", },
|
||||
{ helptag = "nvim-tree-config-hijack-directories", section = "Config: hijack_directories", path = base .. "_meta/config/hijack_directories.lua", },
|
||||
{ helptag = "nvim-tree-config-update-focused-file", section = "Config: update_focused_file", path = base .. "_meta/config/update_focused_file.lua", },
|
||||
{ helptag = "nvim-tree-config-system-open", section = "Config: system_open", path = base .. "_meta/config/system_open.lua", },
|
||||
{ helptag = "nvim-tree-config-git", section = "Config: git", path = base .. "_meta/config/git.lua", },
|
||||
{ helptag = "nvim-tree-config-diagnostics", section = "Config: diagnostics", path = base .. "_meta/config/diagnostics.lua", },
|
||||
{ helptag = "nvim-tree-config-modified", section = "Config: modified", path = base .. "_meta/config/modified.lua", },
|
||||
|
||||
Reference in New Issue
Block a user