Compare commits
18 Commits
v1.9.0
...
chore-poc-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91e6b978e0 | ||
|
|
006b27dc0a | ||
|
|
63cd226c3e | ||
|
|
f9dc294829 | ||
|
|
2dcf249d49 | ||
|
|
9ac1e05fc8 | ||
|
|
d05881f65f | ||
|
|
fee1da8897 | ||
|
|
db7403243d | ||
|
|
fca0b67c0b | ||
|
|
d529a99f88 | ||
|
|
39bc630816 | ||
|
|
aae01853dd | ||
|
|
68fc4c20f5 | ||
|
|
f7b76cd1a7 | ||
|
|
c3d9b1779f | ||
|
|
db8d7ac1f5 | ||
|
|
6b4be1dc0c |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
/luals-out/
|
/luals-out/
|
||||||
/luals/
|
/luals/
|
||||||
|
/plenary.nvim/
|
||||||
# backup vim files
|
# backup vim files
|
||||||
*~
|
*~
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
"workspace": {
|
"workspace": {
|
||||||
"library": [
|
"library": [
|
||||||
"$VIMRUNTIME/lua/vim",
|
"$VIMRUNTIME/lua/vim",
|
||||||
"${3rd}/luv/library"
|
"${3rd}/luv/library",
|
||||||
|
"plenary.nvim"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"diagnostics": {
|
"diagnostics": {
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
".": "1.9.0"
|
".": "1.10.0"
|
||||||
}
|
}
|
||||||
|
|||||||
17
CHANGELOG.md
17
CHANGELOG.md
@@ -1,5 +1,22 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [1.10.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.9.0...nvim-tree-v1.10.0) (2025-01-13)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **api:** add node.open.vertical_no_picker, node.open.horizontal_no_picker ([#3031](https://github.com/nvim-tree/nvim-tree.lua/issues/3031)) ([68fc4c2](https://github.com/nvim-tree/nvim-tree.lua/commit/68fc4c20f5803444277022c681785c5edd11916d))
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **#3015:** dynamic width no longer truncates on right_align icons ([#3022](https://github.com/nvim-tree/nvim-tree.lua/issues/3022)) ([f7b76cd](https://github.com/nvim-tree/nvim-tree.lua/commit/f7b76cd1a75615c8d6254fc58bedd2a7304eb7d8))
|
||||||
|
* **#3018:** error when focusing nvim-tree when in terminal mode ([#3019](https://github.com/nvim-tree/nvim-tree.lua/issues/3019)) ([db8d7ac](https://github.com/nvim-tree/nvim-tree.lua/commit/db8d7ac1f524fc6f808764b29fa695c51e014aa6))
|
||||||
|
* **#3041:** use vim.diagnostic.get for updating diagnostics ([#3042](https://github.com/nvim-tree/nvim-tree.lua/issues/3042)) ([aae0185](https://github.com/nvim-tree/nvim-tree.lua/commit/aae01853ddbd790d1efd6ff04ff96cf38c02c95f))
|
||||||
|
* Can't re-enter normal mode from terminal mode ([db8d7ac](https://github.com/nvim-tree/nvim-tree.lua/commit/db8d7ac1f524fc6f808764b29fa695c51e014aa6))
|
||||||
|
* hijack directory "BufEnter", "BufNewFile" events are nested ([#3044](https://github.com/nvim-tree/nvim-tree.lua/issues/3044)) ([39bc630](https://github.com/nvim-tree/nvim-tree.lua/commit/39bc63081605c1d4b974131ebecaea11e8a8595f))
|
||||||
|
* view.width functions may return strings ([#3020](https://github.com/nvim-tree/nvim-tree.lua/issues/3020)) ([6b4be1d](https://github.com/nvim-tree/nvim-tree.lua/commit/6b4be1dc0cd4d5d5b8e8b56b510a75016e99746f))
|
||||||
|
|
||||||
## [1.9.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.8.0...nvim-tree-v1.9.0) (2024-12-07)
|
## [1.9.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.8.0...nvim-tree-v1.9.0) (2024-12-07)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
Makefile
13
Makefile
@@ -43,6 +43,19 @@ help-update:
|
|||||||
help-check: help-update
|
help-check: help-update
|
||||||
git diff --exit-code doc/nvim-tree-lua.txt
|
git diff --exit-code doc/nvim-tree-lua.txt
|
||||||
|
|
||||||
|
#
|
||||||
|
# test
|
||||||
|
#
|
||||||
|
test: plenary.nvim
|
||||||
|
scripts/test.sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Dependencies
|
||||||
|
#
|
||||||
|
# no plenary tags or releases available
|
||||||
|
plenary.nvim:
|
||||||
|
git clone git@github.com:nvim-lua/plenary.nvim.git
|
||||||
|
|
||||||
|
|
||||||
.PHONY: all lint style check luacheck style-check style-doc luals style-fix help-update help-check
|
.PHONY: all lint style check luacheck style-check style-doc luals style-fix help-update help-check
|
||||||
|
|
||||||
|
|||||||
@@ -162,13 +162,13 @@ nvim-tree exposes a public API. This is non breaking, with additions made as nec
|
|||||||
|
|
||||||
See wiki [Recipes](https://github.com/nvim-tree/nvim-tree.lua/wiki/Recipes) and [Tips](https://github.com/nvim-tree/nvim-tree.lua/wiki/Tips) for ideas and inspiration.
|
See wiki [Recipes](https://github.com/nvim-tree/nvim-tree.lua/wiki/Recipes) and [Tips](https://github.com/nvim-tree/nvim-tree.lua/wiki/Tips) for ideas and inspiration.
|
||||||
|
|
||||||
Please raise a [feature request](https://github.com/nvim-tree/nvim-tree.lua/issues/new?assignees=&labels=feature+request&template=feature_request.md&title=) if the API is insufficient for your needs. [Contributions](#Contributing) are always welcome.
|
Please raise a [feature request](https://github.com/nvim-tree/nvim-tree.lua/issues/new?assignees=&labels=feature+request&template=feature_request.md&title=) if the API is insufficient for your needs. Contributions are always welcome, see below.
|
||||||
|
|
||||||
You may also subscribe to events that nvim-tree will dispatch in a variety of situations, see [:help nvim-tree-events](doc/nvim-tree-lua.txt)
|
You may also subscribe to events that nvim-tree will dispatch in a variety of situations, see [:help nvim-tree-events](doc/nvim-tree-lua.txt)
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
PRs are always welcome. See [wiki](https://github.com/nvim-tree/nvim-tree.lua/wiki/Development) to get started.
|
PRs are always welcome. See [CONTRIBUTING](CONTRIBUTING.md) and [wiki: Development](https://github.com/nvim-tree/nvim-tree.lua/wiki/Development) to get started.
|
||||||
|
|
||||||
See [bug](https://github.com/nvim-tree/nvim-tree.lua/issues?q=is%3Aissue+is%3Aopen+label%3Abug) and [PR Please](https://github.com/nvim-tree/nvim-tree.lua/issues?q=is%3Aopen+is%3Aissue+label%3A%22PR+please%22) issues if you are looking for some work to get you started.
|
See [bug](https://github.com/nvim-tree/nvim-tree.lua/issues?q=is%3Aissue+is%3Aopen+label%3Abug) and [PR Please](https://github.com/nvim-tree/nvim-tree.lua/issues?q=is%3Aopen+is%3Aissue+label%3A%22PR+please%22) issues if you are looking for some work to get you started.
|
||||||
|
|
||||||
|
|||||||
@@ -800,22 +800,22 @@ Width of the window: can be a `%` string, a number representing columns, a
|
|||||||
function or a table.
|
function or a table.
|
||||||
A table indicates that the view should be dynamically sized based on the
|
A table indicates that the view should be dynamically sized based on the
|
||||||
longest line.
|
longest line.
|
||||||
Type: `string | number | table | function()` returning a number
|
Type: `string | number | table | fun(): number|string`
|
||||||
Default: `30`
|
Default: `30`
|
||||||
|
|
||||||
*nvim-tree.view.width.min*
|
*nvim-tree.view.width.min*
|
||||||
Minimum dynamic width.
|
Minimum dynamic width.
|
||||||
Type: `string | number | function()` returning a number
|
Type: `string | number | fun(): number|string`
|
||||||
Default: `30`
|
Default: `30`
|
||||||
|
|
||||||
*nvim-tree.view.width.max*
|
*nvim-tree.view.width.max*
|
||||||
Maximum dynamic width, -1 for unbounded.
|
Maximum dynamic width, -1 for unbounded.
|
||||||
Type: `string | number | function()` returning a number
|
Type: `string | number | fun(): number|string`
|
||||||
Default: `-1`
|
Default: `-1`
|
||||||
|
|
||||||
*nvim-tree.view.width.padding*
|
*nvim-tree.view.width.padding*
|
||||||
Extra padding to the right.
|
Extra padding to the right.
|
||||||
Type: `number | function()` returning a number
|
Type: `number | fun(): number|string`
|
||||||
Default: `1`
|
Default: `1`
|
||||||
|
|
||||||
*nvim-tree.view.float*
|
*nvim-tree.view.float*
|
||||||
@@ -1894,7 +1894,7 @@ tree.winid({opts}) *nvim-tree-api.tree.winid()*
|
|||||||
• {opts} (table) optional parameters
|
• {opts} (table) optional parameters
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
• {tabpage} (number|nil) tabpage, 0 or nil for current, default nil
|
• {tabpage} (number|nil) tabpage, 0 or nil for current, default nil
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
(number) winid or nil if tree is not visible
|
(number) winid or nil if tree is not visible
|
||||||
@@ -2025,9 +2025,19 @@ node.open.no_window_picker({node})
|
|||||||
node.open.vertical({node}) *nvim-tree-api.node.open.vertical()*
|
node.open.vertical({node}) *nvim-tree-api.node.open.vertical()*
|
||||||
|nvim-tree-api.node.edit()|, file will be opened in a new vertical split.
|
|nvim-tree-api.node.edit()|, file will be opened in a new vertical split.
|
||||||
|
|
||||||
|
*nvim-tree-api.node.open.vertical_no_picker()*
|
||||||
|
node.open.vertical_no_picker({node})
|
||||||
|
|nvim-tree-api.node.vertical()|, window picker will never be used as per
|
||||||
|
|nvim-tree.actions.open_file.window_picker.enable| `false`
|
||||||
|
|
||||||
node.open.horizontal({node}) *nvim-tree-api.node.open.horizontal()*
|
node.open.horizontal({node}) *nvim-tree-api.node.open.horizontal()*
|
||||||
|nvim-tree-api.node.edit()|, file will be opened in a new horizontal split.
|
|nvim-tree-api.node.edit()|, file will be opened in a new horizontal split.
|
||||||
|
|
||||||
|
*nvim-tree-api.node.open.horizontal_no_picker()*
|
||||||
|
node.open.horizontal_no_picker({node})
|
||||||
|
|nvim-tree-api.node.horizontal()|, window picker will never be used as per
|
||||||
|
|nvim-tree.actions.open_file.window_picker.enable| `false`
|
||||||
|
|
||||||
*nvim-tree-api.node.open.toggle_group_empty()*
|
*nvim-tree-api.node.open.toggle_group_empty()*
|
||||||
node.open.toggle_group_empty({node})
|
node.open.toggle_group_empty({node})
|
||||||
Toggle |nvim-tree.renderer.group_empty| for a specific folder.
|
Toggle |nvim-tree.renderer.group_empty| for a specific folder.
|
||||||
@@ -2154,6 +2164,28 @@ node.run.cmd({node}) *nvim-tree-api.node.run.cmd()*
|
|||||||
node.run.system({node}) *nvim-tree-api.node.run.system()*
|
node.run.system({node}) *nvim-tree-api.node.run.system()*
|
||||||
Execute |nvim-tree.system_open|
|
Execute |nvim-tree.system_open|
|
||||||
|
|
||||||
|
node.buffer.delete({node}, {opts}) *nvim-tree-api.node.buffer.delete()*
|
||||||
|
Deletes node's related buffer, if one exists.
|
||||||
|
Executes |:bdelete| or |:bdelete|!
|
||||||
|
|
||||||
|
Parameters: ~
|
||||||
|
• {node} (Node|nil) file or folder
|
||||||
|
• {opts} (table) optional parameters
|
||||||
|
|
||||||
|
Options: ~
|
||||||
|
• {force} (boolean) delete even if buffer is modified, default false
|
||||||
|
|
||||||
|
node.buffer.wipe({node}, {opts}) *nvim-tree-api.node.buffer.wipe()*
|
||||||
|
Wipes node's related buffer, if one exists.
|
||||||
|
Executes |:bwipe| or |:bwipe|!
|
||||||
|
|
||||||
|
Parameters: ~
|
||||||
|
• {node} (Node|nil) file or folder
|
||||||
|
• {opts} (table) optional parameters
|
||||||
|
|
||||||
|
Options: ~
|
||||||
|
• {force} (boolean) wipe even if buffer is modified, default false
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
6.4 API GIT *nvim-tree-api.git*
|
6.4 API GIT *nvim-tree-api.git*
|
||||||
|
|
||||||
@@ -3168,6 +3200,8 @@ highlight group is not, hard linking as follows: >
|
|||||||
|nvim-tree-api.marks.navigate.prev()|
|
|nvim-tree-api.marks.navigate.prev()|
|
||||||
|nvim-tree-api.marks.navigate.select()|
|
|nvim-tree-api.marks.navigate.select()|
|
||||||
|nvim-tree-api.marks.toggle()|
|
|nvim-tree-api.marks.toggle()|
|
||||||
|
|nvim-tree-api.node.buffer.delete()|
|
||||||
|
|nvim-tree-api.node.buffer.wipe()|
|
||||||
|nvim-tree-api.node.navigate.diagnostics.next()|
|
|nvim-tree-api.node.navigate.diagnostics.next()|
|
||||||
|nvim-tree-api.node.navigate.diagnostics.next_recursive()|
|
|nvim-tree-api.node.navigate.diagnostics.next_recursive()|
|
||||||
|nvim-tree-api.node.navigate.diagnostics.prev()|
|
|nvim-tree-api.node.navigate.diagnostics.prev()|
|
||||||
@@ -3189,6 +3223,7 @@ highlight group is not, hard linking as follows: >
|
|||||||
|nvim-tree-api.node.open.drop()|
|
|nvim-tree-api.node.open.drop()|
|
||||||
|nvim-tree-api.node.open.edit()|
|
|nvim-tree-api.node.open.edit()|
|
||||||
|nvim-tree-api.node.open.horizontal()|
|
|nvim-tree-api.node.open.horizontal()|
|
||||||
|
|nvim-tree-api.node.open.horizontal_no_picker()|
|
||||||
|nvim-tree-api.node.open.no_window_picker()|
|
|nvim-tree-api.node.open.no_window_picker()|
|
||||||
|nvim-tree-api.node.open.preview()|
|
|nvim-tree-api.node.open.preview()|
|
||||||
|nvim-tree-api.node.open.preview_no_picker()|
|
|nvim-tree-api.node.open.preview_no_picker()|
|
||||||
@@ -3197,6 +3232,7 @@ highlight group is not, hard linking as follows: >
|
|||||||
|nvim-tree-api.node.open.tab_drop()|
|
|nvim-tree-api.node.open.tab_drop()|
|
||||||
|nvim-tree-api.node.open.toggle_group_empty()|
|
|nvim-tree-api.node.open.toggle_group_empty()|
|
||||||
|nvim-tree-api.node.open.vertical()|
|
|nvim-tree-api.node.open.vertical()|
|
||||||
|
|nvim-tree-api.node.open.vertical_no_picker()|
|
||||||
|nvim-tree-api.node.run.cmd()|
|
|nvim-tree-api.node.run.cmd()|
|
||||||
|nvim-tree-api.node.run.system()|
|
|nvim-tree-api.node.run.system()|
|
||||||
|nvim-tree-api.node.show_info_popup()|
|
|nvim-tree-api.node.show_info_popup()|
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ local function setup_autocommands(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if opts.hijack_directories.enable then
|
if opts.hijack_directories.enable then
|
||||||
create_nvim_tree_autocmd({ "BufEnter", "BufNewFile" }, { callback = M.open_on_directory })
|
create_nvim_tree_autocmd({ "BufEnter", "BufNewFile" }, { callback = M.open_on_directory, nested = true })
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts.view.centralize_selection then
|
if opts.view.centralize_selection then
|
||||||
@@ -199,6 +199,10 @@ local function setup_autocommands(opts)
|
|||||||
callback = function()
|
callback = function()
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.api.nvim_buf_call(0, 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]])
|
vim.cmd([[norm! zz]])
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
58
lua/nvim-tree/actions/node/buffer.lua
Normal file
58
lua/nvim-tree/actions/node/buffer.lua
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
-- Copyright 2019 Yazdani Kiyan under MIT License
|
||||||
|
local notify = require("nvim-tree.notify")
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---@param node Node
|
||||||
|
---@param opts ApiNodeDeleteWipeBufferOpts|nil
|
||||||
|
---@return nil
|
||||||
|
function M.delete(node, opts)
|
||||||
|
M.delete_buffer("delete", node.absolute_path, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param node Node
|
||||||
|
---@param opts ApiNodeDeleteWipeBufferOpts|nil
|
||||||
|
---@return nil
|
||||||
|
function M.wipe(node, opts)
|
||||||
|
M.delete_buffer("wipe", node.absolute_path, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@alias ApiNodeDeleteWipeBufferMode '"delete"'|'"wipe"'
|
||||||
|
|
||||||
|
---@param mode ApiNodeDeleteWipeBufferMode
|
||||||
|
---@param filename string
|
||||||
|
---@param opts ApiNodeDeleteWipeBufferOpts|nil
|
||||||
|
---@return nil
|
||||||
|
function M.delete_buffer(mode, filename, opts)
|
||||||
|
if type(mode) ~= "string" then
|
||||||
|
mode = "delete"
|
||||||
|
end
|
||||||
|
|
||||||
|
local buf_fn = vim.cmd.bdelete
|
||||||
|
if mode == "wipe" then
|
||||||
|
buf_fn = vim.cmd.bwipe
|
||||||
|
end
|
||||||
|
|
||||||
|
opts = opts or { force = false }
|
||||||
|
|
||||||
|
local notify_node = notify.render_path(filename)
|
||||||
|
|
||||||
|
-- check if buffer for file at cursor exists and if it is loaded
|
||||||
|
local bufnr_at_filename = vim.fn.bufnr(filename)
|
||||||
|
if bufnr_at_filename == -1 or vim.fn.getbufinfo(bufnr_at_filename)[1].loaded == 0 then
|
||||||
|
notify.info("No loaded buffer coincides with " .. notify_node)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local force = opts.force
|
||||||
|
-- check if buffer is modified
|
||||||
|
local buf_modified = vim.fn.getbufinfo(bufnr_at_filename)[1].changed
|
||||||
|
if not force and buf_modified == 1 then
|
||||||
|
notify.error("Buffer for file " .. notify_node .. " is modified")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
buf_fn({ filename, bang = force })
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -50,6 +50,7 @@ local function setup_window(node)
|
|||||||
file_path = node.absolute_path,
|
file_path = node.absolute_path,
|
||||||
}
|
}
|
||||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.bo[bufnr].bufhidden = "wipe"
|
||||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||||
vim.api.nvim_win_set_buf(winnr, bufnr)
|
vim.api.nvim_win_set_buf(winnr, bufnr)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ M.file_popup = require("nvim-tree.actions.node.file-popup")
|
|||||||
M.open_file = require("nvim-tree.actions.node.open-file")
|
M.open_file = require("nvim-tree.actions.node.open-file")
|
||||||
M.run_command = require("nvim-tree.actions.node.run-command")
|
M.run_command = require("nvim-tree.actions.node.run-command")
|
||||||
M.system_open = require("nvim-tree.actions.node.system-open")
|
M.system_open = require("nvim-tree.actions.node.system-open")
|
||||||
|
M.buffer = require("nvim-tree.actions.node.buffer")
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
require("nvim-tree.actions.node.system-open").setup(opts)
|
require("nvim-tree.actions.node.system-open").setup(opts)
|
||||||
|
|||||||
@@ -235,9 +235,8 @@ end
|
|||||||
|
|
||||||
local function get_target_winid(mode)
|
local function get_target_winid(mode)
|
||||||
local target_winid
|
local target_winid
|
||||||
if not M.window_picker.enable or mode == "edit_no_picker" or mode == "preview_no_picker" then
|
if not M.window_picker.enable or string.find(mode, "no_picker") then
|
||||||
target_winid = lib.target_winid
|
target_winid = lib.target_winid
|
||||||
|
|
||||||
-- first available window
|
-- first available window
|
||||||
if not vim.tbl_contains(vim.api.nvim_tabpage_list_wins(0), target_winid) then
|
if not vim.tbl_contains(vim.api.nvim_tabpage_list_wins(0), target_winid) then
|
||||||
target_winid = first_win_id()
|
target_winid = first_win_id()
|
||||||
@@ -280,6 +279,11 @@ local function open_in_new_window(filename, mode)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local position = string.find(mode, "no_picker")
|
||||||
|
if position then
|
||||||
|
mode = string.sub(mode, 0, position - 2)
|
||||||
|
end
|
||||||
|
|
||||||
-- non-floating, non-nvim-tree windows
|
-- non-floating, non-nvim-tree windows
|
||||||
local win_ids = vim.tbl_filter(function(id)
|
local win_ids = vim.tbl_filter(function(id)
|
||||||
local config = vim.api.nvim_win_get_config(id)
|
local config = vim.api.nvim_win_get_config(id)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ end
|
|||||||
---@param new_tabpage integer
|
---@param new_tabpage integer
|
||||||
---@return boolean
|
---@return boolean
|
||||||
local function is_window_event(new_tabpage)
|
local function is_window_event(new_tabpage)
|
||||||
local is_event_scope_window = vim.v.event.scope == "window" or vim.v.event.changed_window
|
local is_event_scope_window = vim.v.event.scope == "window" or vim.v.event.changed_window or false
|
||||||
return is_event_scope_window and new_tabpage == M.current_tab
|
return is_event_scope_window and new_tabpage == M.current_tab
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ local Api = {
|
|||||||
},
|
},
|
||||||
run = {},
|
run = {},
|
||||||
open = {},
|
open = {},
|
||||||
|
buffer = {},
|
||||||
},
|
},
|
||||||
events = {},
|
events = {},
|
||||||
marks = {
|
marks = {
|
||||||
@@ -255,7 +256,9 @@ 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.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.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 = 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 = 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.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.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 = wrap_node(open_or_expand_or_dir_up("preview"))
|
||||||
@@ -284,6 +287,16 @@ Api.node.navigate.diagnostics.prev_recursive = wrap_node(actions.moves.item.fn({
|
|||||||
Api.node.navigate.opened.next = wrap_node(actions.moves.item.fn({ where = "next", what = "opened" }))
|
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.navigate.opened.prev = wrap_node(actions.moves.item.fn({ where = "prev", what = "opened" }))
|
||||||
|
|
||||||
|
---@class ApiNodeDeleteWipeBufferOpts
|
||||||
|
---@field force boolean|nil default false
|
||||||
|
|
||||||
|
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.git.reload = wrap_explorer("reload_git")
|
Api.git.reload = wrap_explorer("reload_git")
|
||||||
|
|
||||||
Api.events.subscribe = events.subscribe
|
Api.events.subscribe = events.subscribe
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ local Class = require("nvim-tree.classic")
|
|||||||
-- others with name and links less than this arbitrary value are short
|
-- others with name and links less than this arbitrary value are short
|
||||||
local SHORT_LEN = 50
|
local SHORT_LEN = 50
|
||||||
|
|
||||||
|
local namespace_hi_test_id = vim.api.nvim_create_namespace("NvimTreeHiTest")
|
||||||
|
|
||||||
---@class (exact) HighlightDisplay: Class for :NvimTreeHiTest
|
---@class (exact) HighlightDisplay: Class for :NvimTreeHiTest
|
||||||
---@field group string nvim-tree highlight group name
|
---@field group string nvim-tree highlight group name
|
||||||
---@field links string link chain to a concretely defined group
|
---@field links string link chain to a concretely defined group
|
||||||
@@ -52,7 +54,12 @@ function HighlightDisplay:render(bufnr, fmt, l)
|
|||||||
local text = string.format(fmt, self.group, self.links, self.def)
|
local text = string.format(fmt, self.group, self.links, self.def)
|
||||||
|
|
||||||
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { text })
|
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { text })
|
||||||
vim.api.nvim_buf_add_highlight(bufnr, -1, self.group, l, 0, #self.group)
|
|
||||||
|
if vim.fn.has("nvim-0.11") == 1 then
|
||||||
|
vim.hl.range(bufnr, namespace_hi_test_id, self.group, { l, 0 }, { l, #self.group, }, {})
|
||||||
|
else
|
||||||
|
vim.api.nvim_buf_add_highlight(bufnr, -1, self.group, l, 0, #self.group) ---@diagnostic disable-line: deprecated
|
||||||
|
end
|
||||||
|
|
||||||
return l + 1
|
return l + 1
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -128,8 +128,7 @@ function M.update_lsp(ev)
|
|||||||
|
|
||||||
local profile_event = log.profile_start("DiagnosticChanged event")
|
local profile_event = log.profile_start("DiagnosticChanged event")
|
||||||
|
|
||||||
---@type vim.Diagnostic[]
|
local diagnostics = vim.diagnostic.get(ev.buf)
|
||||||
local diagnostics = ev.data.diagnostics
|
|
||||||
|
|
||||||
-- use the buffer from the event, as ev.data.diagnostics will be empty on resolved diagnostics
|
-- use the buffer from the event, as ev.data.diagnostics will be empty on resolved diagnostics
|
||||||
local bufname = uniformize_path(vim.api.nvim_buf_get_name(ev.buf))
|
local bufname = uniformize_path(vim.api.nvim_buf_get_name(ev.buf))
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ local WIN_HL = table.concat({
|
|||||||
"CursorLine:NvimTreeCursorLine",
|
"CursorLine:NvimTreeCursorLine",
|
||||||
}, ",")
|
}, ",")
|
||||||
|
|
||||||
|
local namespace_help_id = vim.api.nvim_create_namespace("NvimTreeHelp")
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
config = {},
|
config = {},
|
||||||
|
|
||||||
@@ -82,8 +84,8 @@ end
|
|||||||
|
|
||||||
--- Compute all lines for the buffer
|
--- Compute all lines for the buffer
|
||||||
---@param map table keymap.get_keymap
|
---@param map table keymap.get_keymap
|
||||||
---@return table strings of text
|
---@return string[] lines of text
|
||||||
---@return table arrays of arguments 3-6 for nvim_buf_add_highlight()
|
---@return HighlightRangeArgs[] hl_range_args for lines
|
||||||
---@return number maximum length of text
|
---@return number maximum length of text
|
||||||
local function compute(map)
|
local function compute(map)
|
||||||
local head_lhs = "nvim-tree mappings"
|
local head_lhs = "nvim-tree mappings"
|
||||||
@@ -130,10 +132,10 @@ local function compute(map)
|
|||||||
local width = #lines[1]
|
local width = #lines[1]
|
||||||
|
|
||||||
-- header highlight, assume one character keys
|
-- header highlight, assume one character keys
|
||||||
local hl = {
|
local hl_range_args = {
|
||||||
{ "NvimTreeFolderName", 0, 0, #head_lhs },
|
{ higroup = "NvimTreeFolderName", start = { 0, 0, }, finish = { 0, #head_lhs, }, },
|
||||||
{ "NvimTreeFolderName", 0, width - 1, width },
|
{ higroup = "NvimTreeFolderName", start = { 0, width - 1, }, finish = { 0, width, }, },
|
||||||
{ "NvimTreeFolderName", 1, width - 1, width },
|
{ higroup = "NvimTreeFolderName", start = { 1, width - 1, }, finish = { 1, width, }, },
|
||||||
}
|
}
|
||||||
|
|
||||||
-- mappings, left padded 1
|
-- mappings, left padded 1
|
||||||
@@ -145,10 +147,10 @@ local function compute(map)
|
|||||||
width = math.max(#line, width)
|
width = math.max(#line, width)
|
||||||
|
|
||||||
-- highlight lhs
|
-- highlight lhs
|
||||||
table.insert(hl, { "NvimTreeFolderName", i + 1, 1, #l.lhs + 1 })
|
table.insert(hl_range_args, { higroup = "NvimTreeFolderName", start = { i + 1, 1, }, finish = { i + 1, #l.lhs + 1, }, })
|
||||||
end
|
end
|
||||||
|
|
||||||
return lines, hl, width
|
return lines, hl_range_args, width
|
||||||
end
|
end
|
||||||
|
|
||||||
--- close the window and delete the buffer, if they exist
|
--- close the window and delete the buffer, if they exist
|
||||||
@@ -172,7 +174,7 @@ local function open()
|
|||||||
local map = keymap.get_keymap()
|
local map = keymap.get_keymap()
|
||||||
|
|
||||||
-- text and highlight
|
-- text and highlight
|
||||||
local lines, hl, width = compute(map)
|
local lines, hl_range_args, width = compute(map)
|
||||||
|
|
||||||
-- create the buffer
|
-- create the buffer
|
||||||
M.bufnr = vim.api.nvim_create_buf(false, true)
|
M.bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
@@ -187,8 +189,12 @@ local function open()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- highlight it
|
-- highlight it
|
||||||
for _, h in ipairs(hl) do
|
for _, args in ipairs(hl_range_args) do
|
||||||
vim.api.nvim_buf_add_highlight(M.bufnr, -1, h[1], h[2], h[3], h[4])
|
if vim.fn.has("nvim-0.11") == 1 then
|
||||||
|
vim.hl.range(M.bufnr, namespace_help_id, args.higroup, args.start, args.finish, {})
|
||||||
|
else
|
||||||
|
vim.api.nvim_buf_add_highlight(M.bufnr, -1, args.higroup, args.start[1], args.start[2], args.finish[2]) ---@diagnostic disable-line: deprecated
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- open a very restricted window
|
-- open a very restricted window
|
||||||
|
|||||||
@@ -33,15 +33,9 @@ local BUILTIN_DECORATORS = {
|
|||||||
Cut = CutDecorator,
|
Cut = CutDecorator,
|
||||||
}
|
}
|
||||||
|
|
||||||
---@class (exact) AddHighlightArgs
|
|
||||||
---@field group string[]
|
|
||||||
---@field line number
|
|
||||||
---@field col_start number
|
|
||||||
---@field col_end number
|
|
||||||
|
|
||||||
---@class (exact) Builder
|
---@class (exact) Builder
|
||||||
---@field lines string[] includes icons etc.
|
---@field lines string[] includes icons etc.
|
||||||
---@field hl_args AddHighlightArgs[] line highlights
|
---@field hl_range_args HighlightRangeArgs[] highlights for lines
|
||||||
---@field signs string[] line signs
|
---@field signs string[] line signs
|
||||||
---@field extmarks table[] extra marks for right icon placement
|
---@field extmarks table[] extra marks for right icon placement
|
||||||
---@field virtual_lines table[] virtual lines for hidden count display
|
---@field virtual_lines table[] virtual lines for hidden count display
|
||||||
@@ -67,7 +61,7 @@ function Builder:new(args)
|
|||||||
self.explorer = args.explorer
|
self.explorer = args.explorer
|
||||||
self.index = 0
|
self.index = 0
|
||||||
self.depth = 0
|
self.depth = 0
|
||||||
self.hl_args = {}
|
self.hl_range_args = {}
|
||||||
self.combined_groups = {}
|
self.combined_groups = {}
|
||||||
self.lines = {}
|
self.lines = {}
|
||||||
self.markers = {}
|
self.markers = {}
|
||||||
@@ -106,7 +100,9 @@ end
|
|||||||
---@param start number
|
---@param start number
|
||||||
---@param end_ number|nil
|
---@param end_ number|nil
|
||||||
function Builder:insert_highlight(groups, start, end_)
|
function Builder:insert_highlight(groups, start, end_)
|
||||||
table.insert(self.hl_args, { groups, self.index, start, end_ or -1 })
|
for _, higroup in ipairs(groups) do
|
||||||
|
table.insert(self.hl_range_args, { higroup = higroup, start = { self.index, start, }, finish = { self.index, end_ or -1, } })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
|
|||||||
@@ -79,9 +79,15 @@ local function show()
|
|||||||
---@type vim.api.keyset.extmark_details
|
---@type vim.api.keyset.extmark_details
|
||||||
local details = extmark[4]
|
local details = extmark[4]
|
||||||
|
|
||||||
vim.api.nvim_buf_add_highlight(0, ns_id, details.hl_group, 0, col, details.end_col)
|
if type(details) == "table" then
|
||||||
|
if vim.fn.has("nvim-0.12") == 1 then
|
||||||
|
vim.hl.range(0, ns_id, details.hl_group, { 0, col }, { 0, details.end_col, }, {})
|
||||||
|
else
|
||||||
|
vim.api.nvim_buf_add_highlight(0, ns_id, details.hl_group, 0, col, details.end_col) ---@diagnostic disable-line: deprecated
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
vim.cmd([[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=hide ]])
|
vim.cmd([[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=wipe ]])
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ local namespace_highlights_id = vim.api.nvim_create_namespace("NvimTreeHighlight
|
|||||||
local namespace_extmarks_id = vim.api.nvim_create_namespace("NvimTreeExtmarks")
|
local namespace_extmarks_id = vim.api.nvim_create_namespace("NvimTreeExtmarks")
|
||||||
local namespace_virtual_lines_id = vim.api.nvim_create_namespace("NvimTreeVirtualLines")
|
local namespace_virtual_lines_id = vim.api.nvim_create_namespace("NvimTreeVirtualLines")
|
||||||
|
|
||||||
|
---@alias HighlightRangeArgs { higroup:string, start:integer[], finish:integer[] } named arguments for vim.hl.range
|
||||||
|
|
||||||
---@class (exact) Renderer: Class
|
---@class (exact) Renderer: Class
|
||||||
---@field explorer Explorer
|
---@field explorer Explorer
|
||||||
local Renderer = Class:extend()
|
local Renderer = Class:extend()
|
||||||
@@ -30,11 +32,11 @@ end
|
|||||||
---@private
|
---@private
|
||||||
---@param bufnr number
|
---@param bufnr number
|
||||||
---@param lines string[]
|
---@param lines string[]
|
||||||
---@param hl_args AddHighlightArgs[]
|
---@param hl_range_args HighlightRangeArgs[]
|
||||||
---@param signs string[]
|
---@param signs string[]
|
||||||
---@param extmarks table[] extra marks for right icon placement
|
---@param extmarks table[] extra marks for right icon placement
|
||||||
---@param virtual_lines table[] virtual lines for hidden count display
|
---@param virtual_lines table[] virtual lines for hidden count display
|
||||||
function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
|
function Renderer:_draw(bufnr, lines, hl_range_args, signs, extmarks, virtual_lines)
|
||||||
if vim.fn.has("nvim-0.10") == 1 then
|
if vim.fn.has("nvim-0.10") == 1 then
|
||||||
vim.api.nvim_set_option_value("modifiable", true, { buf = bufnr })
|
vim.api.nvim_set_option_value("modifiable", true, { buf = bufnr })
|
||||||
else
|
else
|
||||||
@@ -42,7 +44,7 @@ function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
|
|||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||||
self:render_hl(bufnr, hl_args)
|
self:render_hl(bufnr, hl_range_args)
|
||||||
|
|
||||||
if vim.fn.has("nvim-0.10") == 1 then
|
if vim.fn.has("nvim-0.10") == 1 then
|
||||||
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
|
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
|
||||||
@@ -77,16 +79,18 @@ function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
function Renderer:render_hl(bufnr, hl)
|
---@param bufnr integer
|
||||||
|
---@param hl_range_args HighlightRangeArgs[]
|
||||||
|
function Renderer:render_hl(bufnr, hl_range_args)
|
||||||
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
|
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
vim.api.nvim_buf_clear_namespace(bufnr, namespace_highlights_id, 0, -1)
|
vim.api.nvim_buf_clear_namespace(bufnr, namespace_highlights_id, 0, -1)
|
||||||
for _, data in ipairs(hl) do
|
for _, args in ipairs(hl_range_args) do
|
||||||
if type(data[1]) == "table" then
|
if vim.fn.has("nvim-0.11") == 1 then
|
||||||
for _, group in ipairs(data[1]) do
|
vim.hl.range(bufnr, namespace_highlights_id, args.higroup, args.start, args.finish, {})
|
||||||
vim.api.nvim_buf_add_highlight(bufnr, namespace_highlights_id, group, data[2], data[3], data[4])
|
else
|
||||||
end
|
vim.api.nvim_buf_add_highlight(bufnr, namespace_highlights_id, args.higroup, args.start[1], args.start[2], args.finish[2]) ---@diagnostic disable-line: deprecated
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -103,7 +107,7 @@ function Renderer:draw()
|
|||||||
|
|
||||||
local builder = Builder(self.explorer):build()
|
local builder = Builder(self.explorer):build()
|
||||||
|
|
||||||
self:_draw(bufnr, builder.lines, builder.hl_args, builder.signs, builder.extmarks, builder.virtual_lines)
|
self:_draw(bufnr, builder.lines, builder.hl_range_args, builder.signs, builder.extmarks, builder.virtual_lines)
|
||||||
|
|
||||||
if cursor and #builder.lines >= cursor[1] then
|
if cursor and #builder.lines >= cursor[1] then
|
||||||
vim.api.nvim_win_set_cursor(view.get_winnr() or 0, cursor)
|
vim.api.nvim_win_set_cursor(view.get_winnr() or 0, cursor)
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ M.is_wsl = vim.fn.has("wsl") == 1
|
|||||||
-- false for WSL
|
-- false for WSL
|
||||||
M.is_windows = vim.fn.has("win32") == 1 or vim.fn.has("win32unix") == 1
|
M.is_windows = vim.fn.has("win32") == 1 or vim.fn.has("win32unix") == 1
|
||||||
|
|
||||||
|
function M._is_windows()
|
||||||
|
return vim.fn.has("win32") == 1 or vim.fn.has("win32unix") == 1
|
||||||
|
end
|
||||||
|
|
||||||
---@param haystack string
|
---@param haystack string
|
||||||
---@param needle string
|
---@param needle string
|
||||||
---@return boolean
|
---@return boolean
|
||||||
@@ -299,7 +303,7 @@ end
|
|||||||
---@param path string
|
---@param path string
|
||||||
---@return string
|
---@return string
|
||||||
function M.canonical_path(path)
|
function M.canonical_path(path)
|
||||||
if M.is_windows and path:match("^%a:") then
|
if M._is_windows() and path:match("^%a:") then
|
||||||
return path:sub(1, 1):upper() .. path:sub(2)
|
return path:sub(1, 1):upper() .. path:sub(2)
|
||||||
end
|
end
|
||||||
return path
|
return path
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ local function get_size(size)
|
|||||||
if type(size) == "number" then
|
if type(size) == "number" then
|
||||||
return size
|
return size
|
||||||
elseif type(size) == "function" then
|
elseif type(size) == "function" then
|
||||||
return size()
|
return get_size(size())
|
||||||
end
|
end
|
||||||
local size_as_number = tonumber(size:sub(0, -2))
|
local size_as_number = tonumber(size:sub(0, -2))
|
||||||
local percent_as_decimal = size_as_number / 100
|
local percent_as_decimal = size_as_number / 100
|
||||||
@@ -321,8 +321,19 @@ local function grow()
|
|||||||
max_width = get_width(M.View.max_width) - padding
|
max_width = get_width(M.View.max_width) - padding
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, l in pairs(lines) do
|
local ns_id = vim.api.nvim_get_namespaces()["NvimTreeExtmarks"]
|
||||||
|
for line_nr, l in pairs(lines) do
|
||||||
local count = vim.fn.strchars(l)
|
local count = vim.fn.strchars(l)
|
||||||
|
-- also add space for right-aligned icons
|
||||||
|
local extmarks = vim.api.nvim_buf_get_extmarks(M.get_bufnr(), ns_id, { line_nr, 0 }, { line_nr, -1 }, { details = true })
|
||||||
|
for _, extmark in ipairs(extmarks) do
|
||||||
|
local virt_texts = extmark[4].virt_text
|
||||||
|
if virt_texts then
|
||||||
|
for _, virt_text in ipairs(virt_texts) do
|
||||||
|
count = count + vim.fn.strchars(virt_text[1])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
if resizing_width < count then
|
if resizing_width < count then
|
||||||
resizing_width = count
|
resizing_width = count
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ local utils = require("nvim-tree.utils")
|
|||||||
|
|
||||||
local Class = require("nvim-tree.classic")
|
local Class = require("nvim-tree.classic")
|
||||||
|
|
||||||
|
local MESSAGE_EMFILE = "fs.inotify.max_user_watches exceeded, see https://github.com/nvim-tree/nvim-tree.lua/wiki/Troubleshooting"
|
||||||
|
|
||||||
local FS_EVENT_FLAGS = {
|
local FS_EVENT_FLAGS = {
|
||||||
-- inotify or equivalent will be used; fallback to stat has not yet been implemented
|
-- inotify or equivalent will be used; fallback to stat has not yet been implemented
|
||||||
stat = false,
|
stat = false,
|
||||||
@@ -75,6 +77,18 @@ function Event:start()
|
|||||||
local event_cb = vim.schedule_wrap(function(err, filename)
|
local event_cb = vim.schedule_wrap(function(err, filename)
|
||||||
if err then
|
if err then
|
||||||
log.line("watcher", "event_cb '%s' '%s' FAIL : %s", self.path, filename, err)
|
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
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- EMFILE is catastrophic
|
||||||
|
if name == "EMFILE" then
|
||||||
|
M.disable_watchers(MESSAGE_EMFILE)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local message = string.format("File system watcher failed (%s) for path %s, halting watcher.", err, self.path)
|
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 (utils.is_windows or utils.is_wsl) then
|
||||||
-- on directory removal windows will cascade the filesystem events out of order
|
-- on directory removal windows will cascade the filesystem events out of order
|
||||||
@@ -94,7 +108,7 @@ function Event:start()
|
|||||||
rc, _, name = self.fs_event:start(self.path, FS_EVENT_FLAGS, event_cb)
|
rc, _, name = self.fs_event:start(self.path, FS_EVENT_FLAGS, event_cb)
|
||||||
if rc ~= 0 then
|
if rc ~= 0 then
|
||||||
if name == "EMFILE" then
|
if name == "EMFILE" then
|
||||||
M.disable_watchers("fs.inotify.max_user_watches exceeded, see https://github.com/nvim-tree/nvim-tree.lua/wiki/Troubleshooting")
|
M.disable_watchers(MESSAGE_EMFILE)
|
||||||
else
|
else
|
||||||
notify.warn(string.format("Could not start the fs_event watcher for path %s : %s", self.path, name))
|
notify.warn(string.format("Could not start the fs_event watcher for path %s : %s", self.path, name))
|
||||||
end
|
end
|
||||||
|
|||||||
25
scripts/test.sh
Executable file
25
scripts/test.sh
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DIR_REPO="$(git rev-parse --show-toplevel)"
|
||||||
|
export DIR_REPO
|
||||||
|
|
||||||
|
DIR_PLENARY="${DIR_REPO}/plenary.nvim"
|
||||||
|
export DIR_PLENARY
|
||||||
|
|
||||||
|
if [ "${#}" -eq 1 ]; then
|
||||||
|
TEST_NAME="${1}"
|
||||||
|
elif [ -z "${TEST_NAME}" ]; then
|
||||||
|
TEST_NAME="tests"
|
||||||
|
fi
|
||||||
|
export TEST_NAME
|
||||||
|
|
||||||
|
echo "testing: ${TEST_NAME}"
|
||||||
|
|
||||||
|
nvim --headless \
|
||||||
|
--clean \
|
||||||
|
-u "${DIR_REPO}/tests/minimal_init.lua" \
|
||||||
|
-l "${DIR_REPO}/tests/test_init.lua" \
|
||||||
|
-c "qa!"
|
||||||
|
|
||||||
8
tests/minimal_init.lua
Normal file
8
tests/minimal_init.lua
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
-- Prepend these as plenary appends a "." and plenary directory
|
||||||
|
-- The spawned processes don't specify --clean so contain the full ~/.local runtime path
|
||||||
|
vim.o.runtimepath = string.format(
|
||||||
|
"%s,%s,%s",
|
||||||
|
vim.env.DIR_REPO,
|
||||||
|
vim.env.DIR_PLENARY,
|
||||||
|
vim.o.runtimepath
|
||||||
|
)
|
||||||
9
tests/test_init.lua
Normal file
9
tests/test_init.lua
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
local test_harness = require("plenary.test_harness")
|
||||||
|
|
||||||
|
test_harness.test_directory(
|
||||||
|
vim.env.TEST_NAME,
|
||||||
|
{
|
||||||
|
minimal_init = vim.env.DIR_REPO .. "/tests/minimal_init.lua",
|
||||||
|
sequential = true,
|
||||||
|
}
|
||||||
|
)
|
||||||
30
tests/unit/utils_spec.lua
Normal file
30
tests/unit/utils_spec.lua
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
---@type Luassert
|
||||||
|
local assert = require("luassert")
|
||||||
|
local stub = require("luassert.stub")
|
||||||
|
|
||||||
|
local utils = require("nvim-tree.utils")
|
||||||
|
|
||||||
|
describe("utils.path_add_trailing", function()
|
||||||
|
it("trailing added", function()
|
||||||
|
assert.equals("foo/", utils.path_add_trailing("foo"))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("trailing already present", function()
|
||||||
|
assert.equals("foo/", utils.path_add_trailing("foo/"))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe("utils.canonical_path", function()
|
||||||
|
before_each(function()
|
||||||
|
stub(vim.fn, "has")
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("is windows", function()
|
||||||
|
vim.fn.has.on_call_with("win32unix").returns(1)
|
||||||
|
assert.equals("C:\\foo\\bar", utils.canonical_path("c:\\foo\\bar"), "should be uppercase drive")
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("not windows", function()
|
||||||
|
assert.equals("c:\\foo\\bar", utils.canonical_path("c:\\foo\\bar"))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
Reference in New Issue
Block a user