Skip to content

Commit 46010a9

Browse files
committed
Merge branch 'master' into feat-branch-complete-on-attach
2 parents b36b7b4 + b17358f commit 46010a9

24 files changed

+390
-194
lines changed

README.md

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<br clear="left"/>
2323
<br />
2424

25+
Take a look at the [wiki](https://github.com/nvim-tree/nvim-tree.lua/wiki) for Showcases, Tips, Recipes and more.
26+
2527
[Join us on matrix](https://matrix.to/#/#nvim-tree:matrix.org)
2628

2729
## Requirements
@@ -129,7 +131,7 @@ Development is focused on:
129131

130132
nvim-tree exposes a public API. This is non breaking, with additions made as necessary.
131133

132-
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 insufficent for your needs. [Pull requests](#contributing) are always welcome.
134+
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 insufficent for your needs. [Contributions](#Contributing) are always welcome.
133135

134136
[:help nvim-tree-api](doc/nvim-tree-lua.txt)
135137

@@ -145,59 +147,11 @@ Custom actions may be mapped which can invoke API or perform your own actions.
145147

146148
[:help nvim-tree-mappings](doc/nvim-tree-lua.txt)
147149

148-
## Tips & tricks
149-
150-
* You can add a directory by adding a `/` at the end of the paths, entering multiple directories `BASE/foo/bar/baz` will add directory foo, then bar and add a file baz to it.
151-
* You can update window options for the tree by setting `require"nvim-tree.view".View.winopts.MY_OPTION = MY_OPTION_VALUE`
152-
* `toggle` has a second parameter which allows to toggle without focusing the explorer (`require"nvim-tree".toggle(false, true)`).
153-
* You can allow nvim-tree to behave like vinegar, see [:help nvim-tree-vinegar](doc/nvim-tree-lua.txt)
154-
* If you `:set nosplitright`, the files will open on the left side of the tree, placing the tree window in the right side of the file you opened.
155-
* You can automatically close the tab/vim when nvim-tree is the last window in the tab: <https://github.com/nvim-tree/nvim-tree.lua/discussions/1115>. WARNING: this can catastrophically fail: <https://github.com/nvim-tree/nvim-tree.lua/issues/1368>. This will not be added to nvim-tree and the team will not provide support / assistance with this, due to complexities in vim event timings and side-effects.
156-
* Hide the `.git` folder: `filters = { custom = { "^.git$" } }`. See [:help nvim-tree.filters.custom](doc/nvim-tree-lua.txt).
157-
* To disable the display of icons see [:help nvim-tree.renderer.icons.show](doc/nvim-tree-lua.txt).
158-
159-
## Troubleshooting
160-
161-
## Diagnostic Logging
162-
163-
You may enable diagnostic logging to `$XDG_CACHE_HOME/nvim/nvim-tree.log`. See [:help nvim-tree.log](doc/nvim-tree-lua.txt)
164-
165-
## netrw Keeps Popping Up
166-
167-
Eagerly disable netrw. See [:help nvim-tree.disable_netrw](doc/nvim-tree-lua.txt)
168-
169-
## Performance Issues
170-
171-
If you are experiencing performance issues with nvim-tree.lua, you can enable profiling in the logs. It is advisable to enable git logging at the same time, as that can be a source of performance problems.
172-
173-
```lua
174-
log = {
175-
enable = true,
176-
truncate = true,
177-
types = {
178-
diagnostics = true,
179-
git = true,
180-
profile = true,
181-
watcher = true,
182-
},
183-
},
184-
```
185-
186-
Please attach `$XDG_CACHE_HOME/nvim/nvim-tree.log` if you raise an issue.
187-
188-
*Performance Tips:*
189-
190-
* If you are using fish as an editor shell (which might be fixed in the future), try set `shell=/bin/bash` in your vim config. Alternatively, you can [prevent fish from loading interactive configuration in a non-interactive shell](https://github.com/nvim-tree/nvim-tree.lua/issues/549#issuecomment-1127394585).
191-
192-
* Try manually running the git command (see the logs) in your shell e.g. `git --no-optional-locks status --porcelain=v1 --ignored=matching -u`.
193-
194-
* Huge git repositories may timeout after the default `git.timeout` of 400ms. Try increasing that in your setup if you see `[git] job timed out` in the logs.
195-
196-
* Try temporarily disabling git integration by setting `git.enable = false` in your setup.
197-
198150
## Contributing
199151

200-
PRs are always welcome. See [CONTRIBUTING.md](CONTRIBUTING.md)
152+
PRs are always welcome. See [wiki](https://github.com/nvim-tree/nvim-tree.lua/wiki/Development) to get started.
153+
154+
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.
201155

202156
### Help Wanted
203157

doc/nvim-tree-lua.txt

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ Subsequent calls to setup will replace the previous configuration.
177177
ignore_buffer_on_setup = false,
178178
open_on_setup = false,
179179
open_on_setup_file = false,
180-
open_on_tab = false,
181-
ignore_buf_on_tab_change = {},
182180
sort_by = "name",
183181
root_dirs = {},
184182
prefer_startup_root = false,
@@ -223,7 +221,7 @@ Subsequent calls to setup will replace the previous configuration.
223221
highlight_git = false,
224222
full_name = false,
225223
highlight_opened_files = "none",
226-
root_folder_modifier = ":~",
224+
root_folder_label = ":~:s?$?/..?",
227225
indent_width = 2,
228226
indent_markers = {
229227
enable = false,
@@ -293,6 +291,10 @@ Subsequent calls to setup will replace the previous configuration.
293291
enable = false,
294292
show_on_dirs = false,
295293
debounce_delay = 50,
294+
severity = {
295+
min = vim.diagnostic.severity.HINT,
296+
max = vim.diagnostic.severity.ERROR
297+
},
296298
icons = {
297299
hint = "",
298300
info = "",
@@ -360,6 +362,16 @@ Subsequent calls to setup will replace the previous configuration.
360362
prefix = "[FILTER]: ",
361363
always_show_folders = true,
362364
},
365+
tab = {
366+
sync = {
367+
open = false,
368+
close = false,
369+
ignore = {},
370+
},
371+
},
372+
notify = {
373+
threshold = vim.log.levels.INFO,
374+
},
363375
log = {
364376
enable = false,
365377
truncate = false,
@@ -374,9 +386,6 @@ Subsequent calls to setup will replace the previous configuration.
374386
watcher = false,
375387
},
376388
},
377-
notify = {
378-
threshold = vim.log.levels.INFO,
379-
},
380389
} -- END_DEFAULT_OPTS
381390
<
382391

@@ -417,10 +426,6 @@ You can use this option if you don't want the tree to open
417426
in some scenarios (eg using vim startify).
418427
Type: {string}, Default: `{}`
419428

420-
*nvim-tree.ignore_buf_on_tab_change*
421-
List of filetypes or buffer names that will prevent `open_on_tab` to open.
422-
Type: {string}, Default: `{}`
423-
424429
*nvim-tree.auto_reload_on_write*
425430
Reloads the explorer every time a buffer is written to.
426431
Type: `boolean`, Default: `true`
@@ -430,11 +435,6 @@ Creating a file when the cursor is on a closed folder will set the
430435
path to be inside the closed folder, otherwise the parent folder.
431436
Type: `boolean`, Default: `false`
432437

433-
*nvim-tree.open_on_tab*
434-
Opens the tree automatically when switching tabpage or opening a new tabpage
435-
if the tree was previously open.
436-
Type: `boolean`, Default: `false`
437-
438438
*nvim-tree.sort_by*
439439
Changes how files within the same directory are sorted.
440440
Can be one of `name`, `case_sensitive`, `modification_time`, `extension` or a
@@ -536,6 +536,13 @@ Configuration options for the system open command.
536536
*nvim-tree.diagnostics*
537537
Show LSP and COC diagnostics in the signcolumn
538538

539+
`NOTE`: it will use the default diagnostic color groups to highlight the signs.
540+
If you wish to customize, you can override these groups:
541+
- `NvimTreeLspDiagnosticsError`
542+
- `NvimTreeLspDiagnosticsWarning`
543+
- `NvimTreeLspDiagnosticsInformation`
544+
- `NvimTreeLspDiagnosticsHint`
545+
539546
*nvim-tree.diagnostics.enable*
540547
Enable/disable the feature.
541548
Type: `boolean`, Default: `false`
@@ -552,12 +559,16 @@ Show LSP and COC diagnostics in the signcolumn
552559
Icons for diagnostic severity.
553560
Type: `table`, Default: `{ hint = "", info = "", warning = "", error = "" }`
554561

555-
`NOTE`: it will use the default diagnostic color groups to highlight the signs.
556-
If you wish to customize, you can override these groups:
557-
- `NvimTreeLspDiagnosticsError`
558-
- `NvimTreeLspDiagnosticsWarning`
559-
- `NvimTreeLspDiagnosticsInformation`
560-
- `NvimTreeLspDiagnosticsHint`
562+
*nvim-tree.diagnostics.severity*
563+
Severity for which the diagnostics will be displayed. See |diagnostic-severity|
564+
565+
*nvim-tree.diagnostics.severity.min*
566+
Minimum severity.
567+
Type: |vim.diagnostic.severity|, Default: `vim.diagnostic.severity.HINT`
568+
569+
*nvim-tree.diagnostics.severity.max*
570+
Maximum severity.
571+
Type: |vim.diagnostic.severity|, Default: `vim.diagnostic.severity.ERROR`
561572

562573
*nvim-tree.git*
563574
Git integration with icons and colors.
@@ -749,11 +760,17 @@ UI rendering setup
749760
Value can be `"none"`, `"icon"`, `"name"` or `"all"`.
750761
Type: `string`, Default: `"none"`
751762

752-
*nvim-tree.renderer.root_folder_modifier*
763+
*nvim-tree.renderer.root_folder_label* (previously `renderer.root_folder_modifier`)
753764
In what format to show root folder. See `:help filename-modifiers` for
754-
available options.
755-
Type: `string`, Default: `":~"`
756-
765+
available `string` options.
766+
Type: `string` or `function(root_cwd)`, Default: `":~:s?$?/..?"`
767+
768+
Function is passed the absolute path of the root folder and should return a string.
769+
e.g. >
770+
my_root_folder_label = function(path)
771+
return ".../" .. vim.fn.fnamemodify(path, ":t")
772+
end
773+
<
757774
*nvim-tree.renderer.indent_width*
758775
Number of spaces for an each tree nesting level. Minimum 1.
759776
Type: `number`, Default: `2`
@@ -1002,6 +1019,26 @@ The filter can be cleared with the `F` key by default.
10021019
Whether to filter folders or not.
10031020
Type: `boolean`, Default: `true`
10041021

1022+
*nvim-tree.tab*
1023+
Configuration for tab behaviour.
1024+
1025+
*nvim-tree.tab.sync*
1026+
Configuration for syncing nvim-tree across tabs.
1027+
1028+
*nvim-tree.tab.sync.open* (previously `nvim-tree.open_on_tab`)
1029+
Opens the tree automatically when switching tabpage or opening a new
1030+
tabpage if the tree was previously open.
1031+
Type: `boolean`, Default: `false`
1032+
1033+
*nvim-tree.tab.sync.close*
1034+
Closes the tree across all tabpages when the tree is closed.
1035+
Type: `boolean`, Default: `false`
1036+
1037+
*nvim-tree.tab.sync.ignore* (previously `nvim-tree.ignore_buf_on_tab_change`)
1038+
List of filetypes or buffer names on new tab that will prevent
1039+
|nvim-tree.tab.sync.open| and |nvim-tree.tab.sync.close|
1040+
Type: {string}, Default: `{}`
1041+
10051042
*nvim-tree.notify*
10061043
Configuration for notification.
10071044

@@ -1074,8 +1111,9 @@ You can easily implement a toggle using this too:
10741111
>
10751112
local function toggle_replace()
10761113
local view = require"nvim-tree.view"
1114+
local api = require"nvim-tree.api"
10771115
if view.is_visible() then
1078-
view.close()
1116+
api.tree.close()
10791117
else
10801118
require"nvim-tree".open_replacing_current_buffer()
10811119
end
@@ -1130,6 +1168,7 @@ exists.
11301168
- change_root_to_node
11311169
- change_root_to_parent
11321170
- get_node_under_cursor
1171+
- get_nodes
11331172
- find_file `(filename: string)`
11341173
- search_node
11351174
- collapse_all `(keep_buffers?: bool)`

lua/nvim-tree.lua

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ function M.open_replacing_current_buffer(cwd)
113113
require("nvim-tree.actions.finders.find-file").fn(bufname)
114114
end
115115

116-
function M.tab_change()
116+
function M.tab_enter()
117117
if view.is_visible { any_tabpage = true } then
118118
local bufname = vim.api.nvim_buf_get_name(0)
119119
local ft = vim.api.nvim_buf_get_option(0, "ft")
120-
for _, filter in ipairs(M.config.ignore_buf_on_tab_change) do
120+
for _, filter in ipairs(M.config.tab.sync.ignore) do
121121
if bufname:match(filter) ~= nil or ft:match(filter) ~= nil then
122122
return
123123
end
@@ -223,9 +223,9 @@ function M.on_enter(netrw_disabled)
223223
local is_file = stats and stats.type == "file"
224224
local cwd
225225
if is_dir then
226-
cwd = vim.fn.expand(bufname)
226+
cwd = vim.fn.expand(vim.fn.fnameescape(bufname))
227227
-- INFO: could potentially conflict with rooter plugins
228-
vim.cmd("noautocmd cd " .. cwd)
228+
vim.cmd("noautocmd cd " .. vim.fn.fnameescape(cwd))
229229
end
230230

231231
local lines = not is_dir and vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) or {}
@@ -358,8 +358,8 @@ local function setup_autocommands(opts)
358358
})
359359
end
360360

361-
if opts.open_on_tab then
362-
create_nvim_tree_autocmd("TabEnter", { callback = vim.schedule_wrap(M.tab_change) })
361+
if opts.tab.sync.open then
362+
create_nvim_tree_autocmd("TabEnter", { callback = vim.schedule_wrap(M.tab_enter) })
363363
end
364364
if opts.hijack_cursor then
365365
create_nvim_tree_autocmd("CursorMoved", {
@@ -453,8 +453,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
453453
ignore_buffer_on_setup = false,
454454
open_on_setup = false,
455455
open_on_setup_file = false,
456-
open_on_tab = false,
457-
ignore_buf_on_tab_change = {},
458456
sort_by = "name",
459457
root_dirs = {},
460458
prefer_startup_root = false,
@@ -499,7 +497,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
499497
highlight_git = false,
500498
full_name = false,
501499
highlight_opened_files = "none",
502-
root_folder_modifier = ":~",
500+
root_folder_label = ":~:s?$?/..?",
503501
indent_width = 2,
504502
indent_markers = {
505503
enable = false,
@@ -569,6 +567,10 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
569567
enable = false,
570568
show_on_dirs = false,
571569
debounce_delay = 50,
570+
severity = {
571+
min = vim.diagnostic.severity.HINT,
572+
max = vim.diagnostic.severity.ERROR,
573+
},
572574
icons = {
573575
hint = "",
574576
info = "",
@@ -636,6 +638,13 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
636638
prefix = "[FILTER]: ",
637639
always_show_folders = true,
638640
},
641+
tab = {
642+
sync = {
643+
open = false,
644+
close = false,
645+
ignore = {},
646+
},
647+
},
639648
notify = {
640649
threshold = vim.log.levels.INFO,
641650
},
@@ -668,6 +677,7 @@ local FIELD_OVERRIDE_TYPECHECK = {
668677
remove_keymaps = { boolean = true, table = true },
669678
on_attach = { ["function"] = true, string = true },
670679
sort_by = { ["function"] = true, string = true },
680+
root_folder_label = { ["function"] = true, string = true },
671681
}
672682

673683
local function validate_options(conf)
@@ -736,7 +746,6 @@ function M.setup(conf)
736746
_config.open_on_setup_file = opts.open_on_setup_file
737747
_config.ignore_buffer_on_setup = opts.ignore_buffer_on_setup
738748
_config.ignore_ft_on_setup = opts.ignore_ft_on_setup
739-
_config.ignore_buf_on_tab_change = opts.ignore_buf_on_tab_change
740749
_config.hijack_directories = opts.hijack_directories
741750
_config.hijack_directories.enable = _config.hijack_directories.enable and netrw_disabled
742751

@@ -771,9 +780,9 @@ function M.setup(conf)
771780
setup_vim_commands()
772781
end
773782

774-
if M.setup_called and view.is_visible() then
775-
view.close()
776-
view.abandon_current_window()
783+
if M.setup_called then
784+
view.close_all_tabs()
785+
view.abandon_all_windows()
777786
end
778787

779788
if M.setup_called and core.get_explorer() ~= nil then

0 commit comments

Comments
 (0)