Compare commits
6 Commits
2826-remov
...
chore-poc-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91e6b978e0 | ||
|
|
006b27dc0a | ||
|
|
63cd226c3e | ||
|
|
f9dc294829 | ||
|
|
2dcf249d49 | ||
|
|
9ac1e05fc8 |
@@ -7,9 +7,6 @@ end_of_line = lf
|
||||
[nvim-tree-lua.txt]
|
||||
max_line_length = 78
|
||||
|
||||
# keep these in sync with .luarc.json
|
||||
# .editorconfig is used within nvim, overriding .luarc.json
|
||||
# .luarc.json is used by style check
|
||||
[*.lua]
|
||||
indent_style = space
|
||||
max_line_length = 140
|
||||
|
||||
63
.github/workflows/ci.yml
vendored
63
.github/workflows/ci.yml
vendored
@@ -20,25 +20,45 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
lua_version: [ 5.1 ]
|
||||
luacheck_version: [ 1.2.0 ]
|
||||
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: install lua ${{ matrix.lua_version }}
|
||||
uses: leafo/gh-actions-lua@v11
|
||||
- uses: leafo/gh-actions-lua@v10
|
||||
with:
|
||||
luaVersion: ${{ matrix.lua_version }}
|
||||
|
||||
- name: install luarocks
|
||||
uses: leafo/gh-actions-luarocks@v5
|
||||
- uses: leafo/gh-actions-luarocks@v4
|
||||
|
||||
- name: install luacheck ${{ matrix.luacheck_version }}
|
||||
run: luarocks install luacheck ${{ matrix.luacheck_version }}
|
||||
- run: luarocks install luacheck 1.1.1
|
||||
|
||||
- run: make lint
|
||||
|
||||
style:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ matrix.emmy_lua_code_style_version }}-${{ github.head_ref || github.ref_name }}
|
||||
cancel-in-progress: true
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
emmy_lua_code_style_version: [ 1.5.6 ]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: install emmy_lua_code_style
|
||||
run: |
|
||||
mkdir -p CodeFormat
|
||||
curl -L "https://github.com/CppCXY/EmmyLuaCodeStyle/releases/download/${{ matrix.emmy_lua_code_style_version }}/linux-x64.tar.gz" | tar zx --directory CodeFormat
|
||||
|
||||
- run: echo "CodeFormat/linux-x64/bin" >> "$GITHUB_PATH"
|
||||
|
||||
- run: make style
|
||||
|
||||
- run: make style-doc
|
||||
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -49,31 +69,26 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
nvim_version: [ stable, nightly ]
|
||||
luals_version: [ 3.15.0 ]
|
||||
|
||||
env:
|
||||
VIMRUNTIME: /home/runner/nvim-${{ matrix.nvim_version }}/share/nvim/runtime
|
||||
luals_version: [ 3.11.0 ]
|
||||
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: install nvim ${{ matrix.nvim_version }}
|
||||
uses: rhysd/action-setup-vim@v1
|
||||
- uses: rhysd/action-setup-vim@v1
|
||||
with:
|
||||
neovim: true
|
||||
version: ${{ matrix.nvim_version }}
|
||||
|
||||
- name: install lua-language-server ${{ matrix.luals_version }}
|
||||
- name: install luals
|
||||
run: |
|
||||
mkdir -p luals
|
||||
curl -L "https://github.com/LuaLS/lua-language-server/releases/download/${{ matrix.luals_version }}/lua-language-server-${{ matrix.luals_version }}-linux-x64.tar.gz" | tar zx --directory luals
|
||||
echo "luals/bin" >> "$GITHUB_PATH"
|
||||
|
||||
- run: make check
|
||||
- run: echo "luals/bin" >> "$GITHUB_PATH"
|
||||
|
||||
- name: make check
|
||||
env:
|
||||
VIMRUNTIME: /home/runner/nvim-${{ matrix.nvim_version }}/share/nvim/runtime
|
||||
run: make check
|
||||
|
||||
- run: make help-check
|
||||
|
||||
- run: make style
|
||||
|
||||
- run: make style-doc
|
||||
|
||||
4
.github/workflows/luarocks-release.yml
vendored
4
.github/workflows/luarocks-release.yml
vendored
@@ -1,11 +1,9 @@
|
||||
name: Luarocks Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
- 'v[0-9]+.[0-9]+.[0-9]+'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
luarocks-upload:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
/luals-out/
|
||||
/luals/
|
||||
/plenary.nvim/
|
||||
# backup vim files
|
||||
*~
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/usr/bin/env sh
|
||||
#!/bin/sh
|
||||
|
||||
make
|
||||
|
||||
16
.luarc.json
16
.luarc.json
@@ -1,23 +1,13 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
|
||||
"runtime.version.luals-check-only": "Lua 5.1",
|
||||
"workspace": {
|
||||
"library": [
|
||||
"$VIMRUNTIME/lua/vim",
|
||||
"${3rd}/luv/library"
|
||||
"${3rd}/luv/library",
|
||||
"plenary.nvim"
|
||||
]
|
||||
},
|
||||
"format": {
|
||||
"defaultConfig": {
|
||||
"indent_style": "space",
|
||||
"max_line_length": "140",
|
||||
"indent_size": "2",
|
||||
"continuation_indent": "2",
|
||||
"quote_style": "double",
|
||||
"call_arg_parentheses": "always",
|
||||
"space_before_closure_open_parenthesis": "false",
|
||||
"align_continuous_similar_call_args": "true"
|
||||
}
|
||||
},
|
||||
"diagnostics": {
|
||||
"libraryFiles": "Disable",
|
||||
"globals": [],
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
".": "1.13.0"
|
||||
".": "1.10.0"
|
||||
}
|
||||
|
||||
54
CHANGELOG.md
54
CHANGELOG.md
@@ -1,59 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## [1.13.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.12.0...nvim-tree-v1.13.0) (2025-06-14)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **#3113:** add renderer.icons.folder_arrow_padding ([#3114](https://github.com/nvim-tree/nvim-tree.lua/issues/3114)) ([ea5097a](https://github.com/nvim-tree/nvim-tree.lua/commit/ea5097a1e2702b4827cb7380e7fa0bd6da87699c))
|
||||
* **#3132:** add api.node.expand and api.node.collapse ([#3133](https://github.com/nvim-tree/nvim-tree.lua/issues/3133)) ([ae59561](https://github.com/nvim-tree/nvim-tree.lua/commit/ae595611fb2225f2041996c042aa4e4b8663b41e))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* "Invalid buffer id" on closing nvim-tree window ([#3129](https://github.com/nvim-tree/nvim-tree.lua/issues/3129)) ([25d16aa](https://github.com/nvim-tree/nvim-tree.lua/commit/25d16aab7d29ca940a9feb92e6bb734697417009))
|
||||
* **#2746:** background and right aligned icons in floating windows ([#3128](https://github.com/nvim-tree/nvim-tree.lua/issues/3128)) ([cbc3165](https://github.com/nvim-tree/nvim-tree.lua/commit/cbc3165e08893bb499da035c6f6f9d1512b57664))
|
||||
* **#3117:** allow changing filename's casing ([bd54d1d](https://github.com/nvim-tree/nvim-tree.lua/commit/bd54d1d33c20d8630703b9842480291588dbad07))
|
||||
* **#3117:** windows: change file/dir case ([#3135](https://github.com/nvim-tree/nvim-tree.lua/issues/3135)) ([bd54d1d](https://github.com/nvim-tree/nvim-tree.lua/commit/bd54d1d33c20d8630703b9842480291588dbad07))
|
||||
* **#3122:** remove redundant vim.validate ([#3123](https://github.com/nvim-tree/nvim-tree.lua/issues/3123)) ([e7d1b7d](https://github.com/nvim-tree/nvim-tree.lua/commit/e7d1b7dadc62fe2eccc17d814354b0a5688621ce))
|
||||
* **#3124:** fix icon padding for "right_align" placements, notably for dotfiles ([#3125](https://github.com/nvim-tree/nvim-tree.lua/issues/3125)) ([e4cd856](https://github.com/nvim-tree/nvim-tree.lua/commit/e4cd856ebf4fec51db10c69d63e43224b701cbce))
|
||||
* **#3124:** prevent empty icons_right_align response from breaking padding ([e4cd856](https://github.com/nvim-tree/nvim-tree.lua/commit/e4cd856ebf4fec51db10c69d63e43224b701cbce))
|
||||
* **#3134:** setting one glyph to "" no longer disables others ([#3136](https://github.com/nvim-tree/nvim-tree.lua/issues/3136)) ([ebcaccd](https://github.com/nvim-tree/nvim-tree.lua/commit/ebcaccda1c575fa19a8087445276e6671e2b9b37))
|
||||
* **#3143:** actions.open_file.window_picker.exclude applies when not using window picker ([#3144](https://github.com/nvim-tree/nvim-tree.lua/issues/3144)) ([05d8172](https://github.com/nvim-tree/nvim-tree.lua/commit/05d8172ebf9cdb2d140cf25b75625374fbc3df7f))
|
||||
* fixes [#3134](https://github.com/nvim-tree/nvim-tree.lua/issues/3134) ([ebcaccd](https://github.com/nvim-tree/nvim-tree.lua/commit/ebcaccda1c575fa19a8087445276e6671e2b9b37))
|
||||
* invalid buffer issue ([25d16aa](https://github.com/nvim-tree/nvim-tree.lua/commit/25d16aab7d29ca940a9feb92e6bb734697417009))
|
||||
|
||||
## [1.12.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.11.0...nvim-tree-v1.12.0) (2025-04-20)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add TreePreOpen event ([#3105](https://github.com/nvim-tree/nvim-tree.lua/issues/3105)) ([c24c047](https://github.com/nvim-tree/nvim-tree.lua/commit/c24c0470d9de277fbebecd718f33561ed7c90298))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **#3101:** when renderer.highlight_opened_files = "none" do not reload on BufUnload and BufReadPost ([#3102](https://github.com/nvim-tree/nvim-tree.lua/issues/3102)) ([5bea2b3](https://github.com/nvim-tree/nvim-tree.lua/commit/5bea2b37523a31288e0fcab42f3be5c1bd4516bb))
|
||||
* explicitly set `border` to `"none"` in full name float ([#3094](https://github.com/nvim-tree/nvim-tree.lua/issues/3094)) ([c3c1935](https://github.com/nvim-tree/nvim-tree.lua/commit/c3c193594213c5e2f89ec5d7729cad805f76b256))
|
||||
* reliably dispatch exactly one TreeOpen and TreeClose events ([#3107](https://github.com/nvim-tree/nvim-tree.lua/issues/3107)) ([3a63717](https://github.com/nvim-tree/nvim-tree.lua/commit/3a63717d3d332d8f39aaf65be7a0e4c2265af021))
|
||||
|
||||
## [1.11.0](https://github.com/nvim-tree/nvim-tree.lua/compare/nvim-tree-v1.10.0...nvim-tree-v1.11.0) (2025-02-22)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **#1984:** add quit_on_open and focus opts to various api.node.open functions ([#3054](https://github.com/nvim-tree/nvim-tree.lua/issues/3054)) ([3281f33](https://github.com/nvim-tree/nvim-tree.lua/commit/3281f331f7f0bef13eb00fb2d5a9d28b2f6155a2))
|
||||
* **#3037:** add API node.buffer.delete, node.buffer.wipe ([#3040](https://github.com/nvim-tree/nvim-tree.lua/issues/3040)) ([fee1da8](https://github.com/nvim-tree/nvim-tree.lua/commit/fee1da88972f5972a8296813f6c00d7598325ebd))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **#3045:** wipe scratch buffers for full name and show info popups ([#3050](https://github.com/nvim-tree/nvim-tree.lua/issues/3050)) ([fca0b67](https://github.com/nvim-tree/nvim-tree.lua/commit/fca0b67c0b5a31727fb33addc4d9c100736a2894))
|
||||
* **#3059:** test for presence of new 0.11 API vim.hl.range ([#3060](https://github.com/nvim-tree/nvim-tree.lua/issues/3060)) ([70825f2](https://github.com/nvim-tree/nvim-tree.lua/commit/70825f23db61ecd900c4cfea169bffe931926a9d))
|
||||
* arithmetic on nil value error on first git project open ([#3064](https://github.com/nvim-tree/nvim-tree.lua/issues/3064)) ([8052310](https://github.com/nvim-tree/nvim-tree.lua/commit/80523101f0ae48b7f1990e907b685a3d79776c01))
|
||||
* stl and stlnc fillchars are hidden in window picker ([b699143](https://github.com/nvim-tree/nvim-tree.lua/commit/b69914325a945ee5157f0d21047210b42af5776e))
|
||||
* window picker: hide fillchars: stl and stlnc ([#3066](https://github.com/nvim-tree/nvim-tree.lua/issues/3066)) ([b699143](https://github.com/nvim-tree/nvim-tree.lua/commit/b69914325a945ee5157f0d21047210b42af5776e))
|
||||
|
||||
## [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)
|
||||
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ Language server: [luals](https://luals.github.io)
|
||||
|
||||
Lint: [luacheck](https://github.com/lunarmodules/luacheck/)
|
||||
|
||||
Style Fixing: [EmmyLuaCodeStyle](https://github.com/CppCXY/EmmyLuaCodeStyle): `CodeCheck`
|
||||
Style: [EmmyLuaCodeStyle](https://github.com/CppCXY/EmmyLuaCodeStyle): `CodeCheck`
|
||||
|
||||
nvim-tree.lua migrated from stylua to EmmyLuaCodeStyle ~2024/10. `vim.lsp.buf.format()` may be used as it is the default formatter for luals, using an embedded [EmmyLuaCodeStyle](https://github.com/CppCXY/EmmyLuaCodeStyle)
|
||||
nvim-tree.lua migrated from stylua to EmmyLuaCodeStyle ~2024/10. `vim.lsp.buf.format()` may be used as it is the default formatter for luals
|
||||
|
||||
You can install them via you OS package manager e.g. `pacman`, `brew` or other via other package managers such as `cargo` or `luarocks`
|
||||
|
||||
@@ -36,14 +36,14 @@ make lint
|
||||
|
||||
## style
|
||||
|
||||
1. Runs lua language server `codestyle-check` only, using `.luarc.json` settings
|
||||
1. Runs CodeCheck using `.editorconfig` settings
|
||||
1. Runs `scripts/doc-comments.sh` to validate annotated documentation
|
||||
|
||||
```sh
|
||||
make style
|
||||
```
|
||||
|
||||
You can automatically fix style issues using `CodeCheck`:
|
||||
You can automatically fix `CodeCheck` issues via:
|
||||
|
||||
```sh
|
||||
make style-fix
|
||||
|
||||
15
Makefile
15
Makefile
@@ -17,7 +17,7 @@ luacheck:
|
||||
|
||||
# --diagnosis-as-error does not function for workspace, hence we post-process the output
|
||||
style-check:
|
||||
@scripts/luals-check.sh codestyle-check
|
||||
CodeFormat check --config .editorconfig --diagnosis-as-error --workspace lua
|
||||
|
||||
style-doc:
|
||||
scripts/doc-comments.sh
|
||||
@@ -43,6 +43,19 @@ help-update:
|
||||
help-check: help-update
|
||||
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
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ Show the mappings: `g?`
|
||||
`S` Search |nvim-tree-api.tree.search_node()|
|
||||
`u` Rename: Full Path |nvim-tree-api.fs.rename_full()|
|
||||
`U` Toggle Filter: Hidden |nvim-tree-api.tree.toggle_custom_filter()|
|
||||
`W` Collapse All |nvim-tree-api.tree.collapse_all()|
|
||||
`W` Collapse |nvim-tree-api.tree.collapse_all()|
|
||||
`x` Cut |nvim-tree-api.fs.cut()|
|
||||
`y` Copy Name |nvim-tree-api.fs.copy.filename()|
|
||||
`Y` Copy Relative Path |nvim-tree-api.fs.copy.relative_path()|
|
||||
@@ -341,7 +341,7 @@ See |nvim-tree-highlight| for details.
|
||||
|
||||
See |nvim-tree-api.tree.collapse_all()|
|
||||
|
||||
Calls: `api.tree.collapse_all({ keep_buffers = false })`
|
||||
Calls: `api.tree.collapse_all(false)`
|
||||
|
||||
*:NvimTreeCollapseKeepBuffers*
|
||||
|
||||
@@ -350,7 +350,7 @@ See |nvim-tree-highlight| for details.
|
||||
|
||||
See |nvim-tree-api.tree.collapse_all()|
|
||||
|
||||
Calls: `api.tree.collapse_all({ keep_buffers = true })`
|
||||
Calls: `api.tree.collapse_all(true)`
|
||||
|
||||
*:NvimTreeHiTest*
|
||||
|
||||
@@ -398,7 +398,6 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua
|
||||
view = {
|
||||
centralize_selection = false,
|
||||
cursorline = true,
|
||||
cursorlineopt = "both",
|
||||
debounce_delay = 15,
|
||||
side = "left",
|
||||
preserve_window_proportions = false,
|
||||
@@ -463,10 +462,7 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua
|
||||
hidden_placement = "after",
|
||||
diagnostics_placement = "signcolumn",
|
||||
bookmarks_placement = "signcolumn",
|
||||
padding = {
|
||||
icon = " ",
|
||||
folder_arrow = " ",
|
||||
},
|
||||
padding = " ",
|
||||
symlink_arrow = " ➛ ",
|
||||
show = {
|
||||
file = true,
|
||||
@@ -639,7 +635,6 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua
|
||||
},
|
||||
},
|
||||
experimental = {
|
||||
multi_instance = false,
|
||||
},
|
||||
log = {
|
||||
enable = false,
|
||||
@@ -772,10 +767,6 @@ initially centralized, see |zz|.
|
||||
Enable |cursorline| in the tree window.
|
||||
Type: `boolean`, Default: `true`
|
||||
|
||||
*nvim-tree.view.cursorlineopt*
|
||||
Set |cursorlineopt| in the tree window.
|
||||
Type: `string`, Default: `"both"`
|
||||
|
||||
*nvim-tree.view.debounce_delay*
|
||||
Idle milliseconds before some reload / refresh operations.
|
||||
Increase if you experience performance issues around screen refresh.
|
||||
@@ -1072,16 +1063,12 @@ Configuration options for icons.
|
||||
|
||||
*nvim-tree.renderer.icons.bookmarks_placement*
|
||||
Bookmark icon placement.
|
||||
Type: `string`, Default: `"signcolumn"`
|
||||
Type: `string`, Default: `signcolumn`
|
||||
|
||||
*nvim-tree.renderer.icons.padding.icon*
|
||||
*nvim-tree.renderer.icons.padding*
|
||||
Inserted between icon and filename.
|
||||
Type: `string`, Default: `" "`
|
||||
|
||||
*nvim-tree.renderer.icons.padding.folder_arrow*
|
||||
Inserted between folder arrow icon and file/folder icon.
|
||||
Type: `string`, Default: `" "`
|
||||
|
||||
*nvim-tree.renderer.icons.symlink_arrow*
|
||||
Used as a separator between symlinks' source and target.
|
||||
Type: `string`, Default: `" ➛ "`
|
||||
@@ -1386,7 +1373,7 @@ delete/wipe. A reload or filesystem event will result in an update.
|
||||
Type: `boolean`, Default: `false`
|
||||
|
||||
*nvim-tree.filters.no_bookmark*
|
||||
Do not show files that are not bookmarked.
|
||||
Do not show files that are not bookarked.
|
||||
Toggle via |nvim-tree-api.tree.toggle_no_bookmark_filter()|, default `M`
|
||||
Enabling this is not useful as there is no means yet to persist bookmarks.
|
||||
Type: `boolean`, Default: `false`
|
||||
@@ -1476,8 +1463,7 @@ vim |current-directory| behaviour.
|
||||
Type: `boolean`, Default: `false`
|
||||
|
||||
*nvim-tree.actions.expand_all*
|
||||
Configuration for |nvim-tree-api.tree.expand_all()| and
|
||||
|nvim-tree-api.node.expand()|
|
||||
Configuration for expand_all behaviour.
|
||||
|
||||
*nvim-tree.actions.expand_all.max_folder_discovery*
|
||||
Limit the number of folders being explored when expanding every folders.
|
||||
@@ -1520,13 +1506,17 @@ Configuration options for opening a file from nvim-tree.
|
||||
Resizes the tree when opening a file.
|
||||
Type: `boolean`, Default: `true`
|
||||
|
||||
*nvim-tree.experimental.actions.open_file.relative_path*
|
||||
Buffers opened by nvim-tree will use with relative paths instead of
|
||||
absolute.
|
||||
Type: `boolean`, Default: `true`
|
||||
|
||||
*nvim-tree.actions.open_file.window_picker*
|
||||
Window picker configuration.
|
||||
|
||||
*nvim-tree.actions.open_file.window_picker.enable*
|
||||
Enable the feature. If the feature is not enabled, files will open in
|
||||
window from which you last opened the tree, obeying
|
||||
|nvim-tree.actions.open_file.window_picker.exclude|
|
||||
window from which you last opened the tree.
|
||||
Type: `boolean`, Default: `true`
|
||||
|
||||
*nvim-tree.actions.open_file.window_picker.picker*
|
||||
@@ -1545,10 +1535,9 @@ Configuration options for opening a file from nvim-tree.
|
||||
Type: `string`, Default: `"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"`
|
||||
|
||||
*nvim-tree.actions.open_file.window_picker.exclude*
|
||||
Table of buffer option names mapped to a list of option values.
|
||||
Windows containing matching buffers will not be:
|
||||
- available when using a window picker
|
||||
- selected when not using a window picker
|
||||
Table of buffer option names mapped to a list of option values that
|
||||
indicates to the picker that the buffer's window should not be
|
||||
selectable.
|
||||
Type: `table`, Default: >lua
|
||||
{
|
||||
filetype = {
|
||||
@@ -1833,13 +1822,10 @@ tree.find_file({opts}) *nvim-tree-api.tree.find_file()*
|
||||
tree.search_node() *nvim-tree-api.tree.search_node()*
|
||||
Open the search dialogue as per the search_node action.
|
||||
|
||||
tree.collapse_all({opts}) *nvim-tree-api.tree.collapse_all()*
|
||||
tree.collapse_all({keep_buffers}) *nvim-tree-api.tree.collapse_all()*
|
||||
Collapse the tree.
|
||||
|
||||
Parameters: ~
|
||||
• {opts} (table) optional parameters
|
||||
|
||||
Options: ~
|
||||
• {keep_buffers} (boolean) do not collapse nodes with open buffers.
|
||||
|
||||
tree.expand_all({node}) *nvim-tree-api.tree.expand_all()*
|
||||
@@ -2021,99 +2007,43 @@ fs.print_clipboard() *nvim-tree-api.fs.print_clipboard()*
|
||||
Parameters: ~
|
||||
• {node} (Node|nil) file or folder
|
||||
|
||||
node.open.edit({node}, {opts}) *nvim-tree-api.node.open.edit()*
|
||||
node.open.edit({node}) *nvim-tree-api.node.open.edit()*
|
||||
File: open as per |nvim-tree.actions.open_file|
|
||||
Folder: expand or collapse
|
||||
Root: change directory up
|
||||
|
||||
Parameters: ~
|
||||
• {node} (Node|nil) file or folder
|
||||
• {opts} (table) optional parameters
|
||||
|
||||
Options: ~
|
||||
• {quit_on_open} (boolean) quits the tree when opening the file
|
||||
• {focus} (boolean) keep focus in the tree when opening the file
|
||||
|
||||
*nvim-tree-api.node.open.replace_tree_buffer()*
|
||||
node.open.replace_tree_buffer({node})
|
||||
|nvim-tree-api.node.edit()|, file will be opened in place: in the
|
||||
nvim-tree window.
|
||||
|
||||
*nvim-tree-api.node.open.no_window_picker()*
|
||||
node.open.no_window_picker({node}, {opts})
|
||||
node.open.no_window_picker({node})
|
||||
|nvim-tree-api.node.edit()|, window picker will never be used as per
|
||||
|nvim-tree.actions.open_file.window_picker.enable| `false`
|
||||
|
||||
Parameters: ~
|
||||
• {node} (Node|nil) file or folder
|
||||
• {opts} (table) optional parameters
|
||||
|
||||
Options: ~
|
||||
• {quit_on_open} (boolean) quits the tree when opening the file
|
||||
• {focus} (boolean) keep focus in the tree when opening the file
|
||||
|
||||
node.open.vertical({node}, {opts}) *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.
|
||||
|
||||
Parameters: ~
|
||||
• {node} (Node|nil) file or folder
|
||||
• {opts} (table) optional parameters
|
||||
|
||||
Options: ~
|
||||
• {quit_on_open} (boolean) quits the tree when opening the file
|
||||
• {focus} (boolean) keep focus in the tree when opening the file
|
||||
|
||||
*nvim-tree-api.node.open.vertical_no_picker()*
|
||||
node.open.vertical_no_picker({node}, {opts})
|
||||
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`
|
||||
|
||||
Parameters: ~
|
||||
• {node} (Node|nil) file or folder
|
||||
• {opts} (table) optional parameters
|
||||
|
||||
Options: ~
|
||||
• {quit_on_open} (boolean) quits the tree when opening the file
|
||||
• {focus} (boolean) keep focus in the tree when opening the file
|
||||
|
||||
node.open.horizontal({node}, {opts}) *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.
|
||||
|
||||
Parameters: ~
|
||||
• {node} (Node|nil) file or folder
|
||||
• {opts} (table) optional parameters
|
||||
|
||||
Options: ~
|
||||
• {quit_on_open} (boolean) quits the tree when opening the file
|
||||
• {focus} (boolean) keep focus in the tree when opening the file
|
||||
|
||||
*nvim-tree-api.node.open.horizontal_no_picker()*
|
||||
node.open.horizontal_no_picker({node}, {opts})
|
||||
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`
|
||||
|
||||
Parameters: ~
|
||||
• {node} (Node|nil) file or folder
|
||||
• {opts} (table) optional parameters
|
||||
|
||||
Options: ~
|
||||
• {quit_on_open} (boolean) quits the tree when opening the file
|
||||
• {focus} (boolean) keep focus in the tree when opening the file
|
||||
|
||||
*nvim-tree-api.node.open.toggle_group_empty()*
|
||||
node.open.toggle_group_empty({node}, {opts})
|
||||
node.open.toggle_group_empty({node})
|
||||
Toggle |nvim-tree.renderer.group_empty| for a specific folder.
|
||||
Does nothing on files.
|
||||
Needs |nvim-tree.renderer.group_empty| set.
|
||||
|
||||
Parameters: ~
|
||||
• {node} (Node|nil) file or folder
|
||||
• {opts} (table) optional parameters
|
||||
|
||||
Options: ~
|
||||
• {quit_on_open} (boolean) quits the tree when opening the file
|
||||
• {focus} (boolean) keep focus in the tree when opening the file
|
||||
|
||||
node.open.drop({node}) *nvim-tree-api.node.open.drop()*
|
||||
Switch to window with selected file if it exists.
|
||||
Open file otherwise.
|
||||
@@ -2123,17 +2053,9 @@ node.open.drop({node}) *nvim-tree-api.node.open.drop()*
|
||||
Folder: expand or collapse
|
||||
Root: change directory up
|
||||
|
||||
node.open.tab({node}, {opts}) *nvim-tree-api.node.open.tab()*
|
||||
node.open.tab({node}) *nvim-tree-api.node.open.tab()*
|
||||
|nvim-tree-api.node.edit()|, file will be opened in a new tab.
|
||||
|
||||
Parameters: ~
|
||||
• {node} (Node|nil) file or folder
|
||||
• {opts} (table) optional parameters
|
||||
|
||||
Options: ~
|
||||
• {quit_on_open} (boolean) quits the tree when opening the file
|
||||
• {focus} (boolean) keep focus in the tree when opening the file
|
||||
|
||||
*nvim-tree-api.node.open.tab_drop()*
|
||||
node.open.tab_drop({node})
|
||||
Switch to tab containing window with selected file if it exists.
|
||||
@@ -2143,31 +2065,15 @@ node.open.tab_drop({node})
|
||||
Folder: expand or collapse
|
||||
Root: change directory up
|
||||
|
||||
node.open.preview({node}, {opts}) *nvim-tree-api.node.open.preview()*
|
||||
node.open.preview({node}) *nvim-tree-api.node.open.preview()*
|
||||
|nvim-tree-api.node.edit()|, file buffer will have |bufhidden| set to `delete`.
|
||||
|
||||
Parameters: ~
|
||||
• {node} (Node|nil) file or folder
|
||||
• {opts} (table) optional parameters
|
||||
|
||||
Options: ~
|
||||
• {quit_on_open} (boolean) quits the tree when opening the file
|
||||
• {focus} (boolean) keep focus in the tree when opening the file
|
||||
|
||||
*nvim-tree-api.node.open.preview_no_picker()*
|
||||
node.open.preview_no_picker({node}, {opts})
|
||||
node.open.preview_no_picker({node})
|
||||
|nvim-tree-api.node.edit()|, file buffer will have |bufhidden| set to `delete`.
|
||||
window picker will never be used as per
|
||||
|nvim-tree.actions.open_file.window_picker.enable| `false`
|
||||
|
||||
Parameters: ~
|
||||
• {node} (Node|nil) file or folder
|
||||
• {opts} (table) optional parameters
|
||||
|
||||
Options: ~
|
||||
• {quit_on_open} (boolean) quits the tree when opening the file
|
||||
• {focus} (boolean) keep focus in the tree when opening the file
|
||||
|
||||
node.navigate.git.next({node}) *nvim-tree-api.node.navigate.git.next()*
|
||||
Navigate to the next item showing git status.
|
||||
|
||||
@@ -2280,23 +2186,6 @@ node.buffer.wipe({node}, {opts}) *nvim-tree-api.node.buffer.wipe()*
|
||||
Options: ~
|
||||
• {force} (boolean) wipe even if buffer is modified, default false
|
||||
|
||||
node.expand({node}) *nvim-tree-api.node.expand()*
|
||||
Recursively expand all nodes under a directory or a file's parent
|
||||
directory.
|
||||
|
||||
Parameters: ~
|
||||
• {node} (Node|nil) file or folder
|
||||
|
||||
node.collapse({node}, {opts}) *nvim-tree-api.node.collapse()*
|
||||
Collapse the tree under a directory or a file's parent directory.
|
||||
|
||||
Parameters: ~
|
||||
• {node} (Node|nil) file or folder
|
||||
• {opts} (table) optional parameters
|
||||
|
||||
Options: ~
|
||||
• {keep_buffers} (boolean) do not collapse nodes with open buffers.
|
||||
|
||||
==============================================================================
|
||||
6.4 API GIT *nvim-tree-api.git*
|
||||
|
||||
@@ -2551,7 +2440,7 @@ You are encouraged to copy these to your own |nvim-tree.on_attach| function. >lu
|
||||
vim.keymap.set("n", "S", api.tree.search_node, opts("Search"))
|
||||
vim.keymap.set("n", "u", api.fs.rename_full, opts("Rename: Full Path"))
|
||||
vim.keymap.set("n", "U", api.tree.toggle_custom_filter, opts("Toggle Filter: Hidden"))
|
||||
vim.keymap.set("n", "W", api.tree.collapse_all, opts("Collapse All"))
|
||||
vim.keymap.set("n", "W", api.tree.collapse_all, opts("Collapse"))
|
||||
vim.keymap.set("n", "x", api.fs.cut, opts("Cut"))
|
||||
vim.keymap.set("n", "y", api.fs.copy.filename, opts("Copy Name"))
|
||||
vim.keymap.set("n", "Y", api.fs.copy.relative_path, opts("Copy Relative Path"))
|
||||
@@ -2800,21 +2689,13 @@ e.g. handler for node renamed: >lua
|
||||
|nvim_tree_events_kind|
|
||||
|
||||
- Event.Ready
|
||||
When NvimTree has been initialized.
|
||||
• Note: Handler takes no parameter.
|
||||
|
||||
- Event.TreePreOpen
|
||||
Invoked before the window and buffer for NvimTree are created
|
||||
or opened. Before |Event.TreeOpen| event.
|
||||
When NvimTree has been initialized
|
||||
• Note: Handler takes no parameter.
|
||||
|
||||
- Event.TreeOpen
|
||||
Invoked after the NvimTree is opened.
|
||||
• Note: Handler takes no parameter.
|
||||
|
||||
- Event.TreeClose
|
||||
Invoked after the NvimTree is closed, but before the window is
|
||||
closed. Dispatched on |WinClosed| event for NvimTree window.
|
||||
• Note: Handler takes no parameter.
|
||||
|
||||
- Event.Resize - When NvimTree is resized.
|
||||
@@ -2929,33 +2810,9 @@ Decorators may:
|
||||
- Set highlight group for the name or icons
|
||||
- Override node icon
|
||||
|
||||
Create a `nvim_tree.api.decorator.UserDecorator` class and register it with
|
||||
precedence via |nvim-tree.renderer.decorators|
|
||||
|
||||
See |nvim-tree-decorator-example|
|
||||
|
||||
See `nvim-tree/_meta/api_decorator.lua` for full class documentation.
|
||||
|
||||
==============================================================================
|
||||
11.1. DECORATOR EXAMPLE *nvim-tree-decorator-example*
|
||||
|
||||
A decorator class for nodes named "example", overridind all builtin decorators
|
||||
except for Cut.
|
||||
|
||||
- Highlights node name with `IncSearch`
|
||||
- Creates two icons `"1"` and `"2"` placed after the node name, highlighted with
|
||||
`DiffAdd` and `DiffText`
|
||||
- Replaces the node icon with `"N"`, highlighted with `Error `
|
||||
|
||||
Create a class file `~/.config/nvim/lua/my-decorator.lua`
|
||||
|
||||
Require and register it during |nvim-tree-setup|:
|
||||
>lua
|
||||
local MyDecorator = require("my-decorator")
|
||||
|
||||
require("nvim-tree").setup({
|
||||
renderer = {
|
||||
decorators = {
|
||||
Specify decorators and their precedence via |nvim-tree.renderer.decorators|
|
||||
e.g. defaults with a user decorator class being overridden only by Cut: >lua
|
||||
{
|
||||
"Git",
|
||||
"Open",
|
||||
"Hidden",
|
||||
@@ -2965,35 +2822,31 @@ Require and register it during |nvim-tree-setup|:
|
||||
"Copied",
|
||||
MyDecorator,
|
||||
"Cut",
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
See `nvim-tree/_meta/api_decorator.lua` for full
|
||||
`nvim_tree.api.decorator.UserDecorator` class documentation.
|
||||
<
|
||||
Contents of `my-decorator.lua`:
|
||||
==============================================================================
|
||||
11.1. DECORATOR EXAMPLE *nvim-tree-decorator-example*
|
||||
>lua
|
||||
---Create your decorator class
|
||||
---@class (exact) MyDecorator: nvim_tree.api.decorator.UserDecorator
|
||||
---@field private my_icon1 nvim_tree.api.HighlightedString
|
||||
---@field private my_icon2 nvim_tree.api.HighlightedString
|
||||
---@field private my_icon_node nvim_tree.api.HighlightedString
|
||||
---@field private my_highlight_group string
|
||||
---@field private my_icon nvim_tree.api.HighlightedString
|
||||
local MyDecorator = require("nvim-tree.api").decorator.UserDecorator:extend()
|
||||
|
||||
---Mandatory constructor :new() will be called once per tree render, with no arguments.
|
||||
function MyDecorator:new()
|
||||
self.enabled = true
|
||||
self.highlight_range = "name"
|
||||
self.icon_placement = "after"
|
||||
self.highlight_range = "all"
|
||||
self.icon_placement = "signcolumn"
|
||||
|
||||
-- create your icons and highlights once, applied to every node
|
||||
self.my_icon1 = { str = "1", hl = { "DiffAdd" } }
|
||||
self.my_icon2 = { str = "2", hl = { "DiffText" } }
|
||||
self.my_icon_node = { str = "N", hl = { "Error" } }
|
||||
self.my_highlight_group = "IncSearch"
|
||||
-- create your icon once, for convenience
|
||||
self.my_icon = { str = "I", hl = { "MyIcon" } }
|
||||
|
||||
-- Define the icon signs only once
|
||||
-- Define the icon sign only once
|
||||
-- Only needed if you are using icon_placement = "signcolumn"
|
||||
-- self:define_sign(self.my_icon1)
|
||||
-- self:define_sign(self.my_icon2)
|
||||
self:define_sign(self.my_icon)
|
||||
end
|
||||
|
||||
---Override node icon
|
||||
@@ -3001,35 +2854,33 @@ Contents of `my-decorator.lua`:
|
||||
---@return nvim_tree.api.HighlightedString? icon_node
|
||||
function MyDecorator:icon_node(node)
|
||||
if node.name == "example" then
|
||||
return self.my_icon_node
|
||||
return self.my_icon
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
---Return two icons for DecoratorIconPlacement "after"
|
||||
---Return one icon for DecoratorIconPlacement
|
||||
---@param node nvim_tree.api.Node
|
||||
---@return nvim_tree.api.HighlightedString[]? icons
|
||||
function MyDecorator:icons(node)
|
||||
if node.name == "example" then
|
||||
return { self.my_icon1, self.my_icon2, }
|
||||
return { self.my_icon }
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
---Exactly one highlight group for DecoratorHighlightRange "name"
|
||||
---Exactly one highlight group for DecoratorHighlightRange
|
||||
---@param node nvim_tree.api.Node
|
||||
---@return string? highlight_group
|
||||
function MyDecorator:highlight_group(node)
|
||||
if node.name == "example" then
|
||||
return self.my_highlight_group
|
||||
return "MyHighlight"
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
return MyDecorator
|
||||
<
|
||||
==============================================================================
|
||||
12. OS SPECIFIC RESTRICTIONS *nvim-tree-os-specific*
|
||||
@@ -3039,6 +2890,9 @@ Windows WSL and PowerShell
|
||||
- Executable file detection is disabled as this is non-performant and can
|
||||
freeze nvim
|
||||
- Some filesystem watcher error related to permissions will not be reported
|
||||
- Some users have reported unspecified issues with
|
||||
|nvim-tree.experimental.actions.open_file.relative_path|. Please report any
|
||||
issues or disable this feature.
|
||||
|
||||
==============================================================================
|
||||
13. NETRW *nvim-tree-netrw*
|
||||
@@ -3085,7 +2939,6 @@ needed.
|
||||
`sort_by` |nvim-tree.sort.sorter|
|
||||
`git.ignore` |nvim-tree.filters.git_ignored|
|
||||
`renderer.icons.webdev_colors` |nvim-tree.renderer.icons.web_devicons.file.color|
|
||||
`renderer.icons.padding` |nvim-tree.renderer.icons.padding.icon|
|
||||
|
||||
==============================================================================
|
||||
14.2 LEGACY: HIGHLIGHT *nvim-tree-legacy-highlight*
|
||||
@@ -3173,6 +3026,7 @@ highlight group is not, hard linking as follows: >
|
||||
|nvim-tree.diagnostics.show_on_open_dirs|
|
||||
|nvim-tree.disable_netrw|
|
||||
|nvim-tree.experimental|
|
||||
|nvim-tree.experimental.actions.open_file.relative_path|
|
||||
|nvim-tree.filesystem_watchers.debounce_delay|
|
||||
|nvim-tree.filesystem_watchers.enable|
|
||||
|nvim-tree.filesystem_watchers.ignore_dirs|
|
||||
@@ -3241,8 +3095,7 @@ highlight group is not, hard linking as follows: >
|
||||
|nvim-tree.renderer.icons.glyphs.symlink|
|
||||
|nvim-tree.renderer.icons.hidden_placement|
|
||||
|nvim-tree.renderer.icons.modified_placement|
|
||||
|nvim-tree.renderer.icons.padding.folder_arrow|
|
||||
|nvim-tree.renderer.icons.padding.icon|
|
||||
|nvim-tree.renderer.icons.padding|
|
||||
|nvim-tree.renderer.icons.show|
|
||||
|nvim-tree.renderer.icons.show.bookmarks|
|
||||
|nvim-tree.renderer.icons.show.diagnostics|
|
||||
@@ -3293,7 +3146,6 @@ highlight group is not, hard linking as follows: >
|
||||
|nvim-tree.update_focused_file.update_root.ignore_list|
|
||||
|nvim-tree.view.centralize_selection|
|
||||
|nvim-tree.view.cursorline|
|
||||
|nvim-tree.view.cursorlineopt|
|
||||
|nvim-tree.view.debounce_delay|
|
||||
|nvim-tree.view.float|
|
||||
|nvim-tree.view.float.enable|
|
||||
@@ -3350,8 +3202,6 @@ highlight group is not, hard linking as follows: >
|
||||
|nvim-tree-api.marks.toggle()|
|
||||
|nvim-tree-api.node.buffer.delete()|
|
||||
|nvim-tree-api.node.buffer.wipe()|
|
||||
|nvim-tree-api.node.collapse()|
|
||||
|nvim-tree-api.node.expand()|
|
||||
|nvim-tree-api.node.navigate.diagnostics.next()|
|
||||
|nvim-tree-api.node.navigate.diagnostics.next_recursive()|
|
||||
|nvim-tree-api.node.navigate.diagnostics.prev()|
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
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")
|
||||
@@ -73,8 +74,7 @@ function M.change_root(path, bufnr)
|
||||
end
|
||||
|
||||
function M.tab_enter()
|
||||
local explorer = core.get_explorer()
|
||||
if explorer and explorer.view:is_visible({ any_tabpage = true }, "nvim-tree.tab_enter") then
|
||||
if view.is_visible({ any_tabpage = true }) then
|
||||
local bufname = vim.api.nvim_buf_get_name(0)
|
||||
|
||||
local ft
|
||||
@@ -89,15 +89,17 @@ function M.tab_enter()
|
||||
return
|
||||
end
|
||||
end
|
||||
explorer.view:open({ focus_tree = false })
|
||||
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 explorer = core.get_explorer()
|
||||
local should_proceed = _config.hijack_directories.auto_open or explorer and explorer.view:is_visible(nil, "nvim-tree.open_on_directory")
|
||||
local should_proceed = _config.hijack_directories.auto_open or view.is_visible()
|
||||
if not should_proceed then
|
||||
return
|
||||
end
|
||||
@@ -148,6 +150,21 @@ local function setup_autocommands(opts)
|
||||
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 opts.actions.open_file.eject then
|
||||
view._prevent_buffer_override()
|
||||
else
|
||||
view.abandon_current_window()
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
if opts.tab.sync.open then
|
||||
create_nvim_tree_autocmd("TabEnter", { callback = vim.schedule_wrap(M.tab_enter) })
|
||||
end
|
||||
@@ -209,19 +226,16 @@ local function setup_autocommands(opts)
|
||||
})
|
||||
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()
|
||||
if opts.view.float.enable and opts.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
|
||||
end
|
||||
|
||||
local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||
@@ -245,7 +259,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||
view = {
|
||||
centralize_selection = false,
|
||||
cursorline = true,
|
||||
cursorlineopt = "both",
|
||||
debounce_delay = 15,
|
||||
side = "left",
|
||||
preserve_window_proportions = false,
|
||||
@@ -310,10 +323,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||
hidden_placement = "after",
|
||||
diagnostics_placement = "signcolumn",
|
||||
bookmarks_placement = "signcolumn",
|
||||
padding = {
|
||||
icon = " ",
|
||||
folder_arrow = " ",
|
||||
},
|
||||
padding = " ",
|
||||
symlink_arrow = " ➛ ",
|
||||
show = {
|
||||
file = true,
|
||||
@@ -486,7 +496,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||
},
|
||||
},
|
||||
experimental = {
|
||||
multi_instance = false,
|
||||
},
|
||||
log = {
|
||||
enable = false,
|
||||
@@ -666,10 +675,10 @@ local function localise_default_opts()
|
||||
end
|
||||
|
||||
function M.purge_all_state()
|
||||
view.close_all_tabs()
|
||||
view.abandon_all_windows()
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.view:close_all_tabs()
|
||||
explorer.view:abandon_all_windows()
|
||||
require("nvim-tree.git").purge_state()
|
||||
explorer:destroy()
|
||||
core.reset_explorer()
|
||||
@@ -722,12 +731,12 @@ function M.setup(conf)
|
||||
require("nvim-tree.explorer.watch").setup(opts)
|
||||
require("nvim-tree.git").setup(opts)
|
||||
require("nvim-tree.git.utils").setup(opts)
|
||||
require("nvim-tree.view").setup(opts)
|
||||
require("nvim-tree.lib").setup(opts)
|
||||
require("nvim-tree.renderer.components").setup(opts)
|
||||
require("nvim-tree.buffers").setup(opts)
|
||||
require("nvim-tree.help").setup(opts)
|
||||
require("nvim-tree.watcher").setup(opts)
|
||||
require("nvim-tree.multi-instance-debug").setup(opts)
|
||||
|
||||
setup_autocommands(opts)
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local log = require("nvim-tree.log")
|
||||
local view = require("nvim-tree.view")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local core = require("nvim-tree.core")
|
||||
|
||||
@@ -13,7 +14,7 @@ local running = {}
|
||||
---@param path string relative or absolute
|
||||
function M.fn(path)
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer or not explorer.view:is_visible(nil, "finders/find-file.fn1") then
|
||||
if not explorer or not view.is_visible() then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -83,9 +84,9 @@ function M.fn(path)
|
||||
end)
|
||||
:iterate()
|
||||
|
||||
if found and explorer.view:is_visible(nil, "finders/find-file.fn2") then
|
||||
if found and view.is_visible() then
|
||||
explorer.renderer:draw()
|
||||
explorer.view:set_cursor({ line, 0 })
|
||||
view.set_cursor({ line, 0 })
|
||||
end
|
||||
|
||||
running[path_real] = false
|
||||
|
||||
@@ -31,8 +31,6 @@ local Clipboard = Class:extend()
|
||||
---@protected
|
||||
---@param args ClipboardArgs
|
||||
function Clipboard:new(args)
|
||||
args.explorer:log_new("Clipboard")
|
||||
|
||||
self.explorer = args.explorer
|
||||
|
||||
self.data = {
|
||||
@@ -44,10 +42,6 @@ function Clipboard:new(args)
|
||||
self.reg = self.explorer.opts.actions.use_system_clipboard and "+" or "1"
|
||||
end
|
||||
|
||||
function Clipboard:destroy()
|
||||
self.explorer:log_destroy("Clipboard")
|
||||
end
|
||||
|
||||
---@param source string
|
||||
---@param destination string
|
||||
---@return boolean
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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")
|
||||
|
||||
@@ -13,12 +14,10 @@ local M = {
|
||||
|
||||
---@param windows integer[]
|
||||
local function close_windows(windows)
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
-- Prevent from closing when the win count equals 1 or 2,
|
||||
-- where the win to remove could be the last opened.
|
||||
-- For details see #2503.
|
||||
if explorer and explorer.opts.view.float.enable and #vim.api.nvim_list_wins() < 3 then
|
||||
if view.View.float.enable and #vim.api.nvim_list_wins() < 3 then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -31,17 +30,16 @@ end
|
||||
|
||||
---@param absolute_path string
|
||||
local function clear_buffer(absolute_path)
|
||||
local explorer = core.get_explorer()
|
||||
local bufs = vim.fn.getbufinfo({ bufloaded = 1, buflisted = 1 })
|
||||
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 explorer and explorer.opts.view.float.enable) then
|
||||
if buf.hidden == 0 and (#bufs > 1 or view.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 explorer and not explorer.opts.view.float.quit_on_focus_loss then
|
||||
if not view.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
|
||||
@@ -71,16 +69,9 @@ local function remove_dir(cwd)
|
||||
|
||||
-- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility
|
||||
local stat = vim.loop.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 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
|
||||
local ltype = lstat and lstat.type or nil
|
||||
|
||||
if type == "directory" and ltype ~= "link" then
|
||||
if type == "directory" then
|
||||
local success = remove_dir(new_cwd)
|
||||
if not success then
|
||||
return false
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local utils = require("nvim-tree.utils")
|
||||
local view = require("nvim-tree.view")
|
||||
local core = require("nvim-tree.core")
|
||||
local diagnostics = require("nvim-tree.diagnostics")
|
||||
|
||||
@@ -66,9 +67,9 @@ local function move(explorer, where, what, skip_gitignored)
|
||||
end
|
||||
|
||||
if nex then
|
||||
explorer.view:set_cursor({ nex, 0 })
|
||||
view.set_cursor({ nex, 0 })
|
||||
elseif vim.o.wrapscan and first then
|
||||
explorer.view:set_cursor({ first, 0 })
|
||||
view.set_cursor({ first, 0 })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -188,13 +189,13 @@ local function move_prev_recursive(explorer, what, skip_gitignored)
|
||||
|
||||
-- 4.3)
|
||||
if node_init.name == ".." then -- root node
|
||||
explorer.view:set_cursor({ 1, 0 }) -- move to root node (position 1)
|
||||
view.set_cursor({ 1, 0 }) -- move to root node (position 1)
|
||||
else
|
||||
local node_init_line = utils.find_node_line(node_init)
|
||||
if node_init_line < 0 then
|
||||
return
|
||||
end
|
||||
explorer.view:set_cursor({ node_init_line, 0 })
|
||||
view.set_cursor({ node_init_line, 0 })
|
||||
end
|
||||
|
||||
-- 4.4)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
local view = require("nvim-tree.view")
|
||||
local utils = require("nvim-tree.utils")
|
||||
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
@@ -24,7 +25,7 @@ function M.fn(should_close)
|
||||
local parent = (node:get_parent_of_group() or node).parent
|
||||
|
||||
if not parent or not parent.parent then
|
||||
node.explorer.view:set_cursor({ 1, 0 })
|
||||
view.set_cursor({ 1, 0 })
|
||||
return
|
||||
end
|
||||
|
||||
@@ -32,7 +33,7 @@ function M.fn(should_close)
|
||||
return n.absolute_path == parent.absolute_path
|
||||
end)
|
||||
|
||||
node.explorer.view:set_cursor({ line + 1, 0 })
|
||||
view.set_cursor({ line + 1, 0 })
|
||||
if should_close then
|
||||
parent.open = false
|
||||
parent.explorer.renderer:draw()
|
||||
|
||||
@@ -57,9 +57,7 @@ end
|
||||
|
||||
function M.close_popup()
|
||||
if current_popup ~= nil then
|
||||
if vim.api.nvim_win_is_valid(current_popup.winnr) then
|
||||
vim.api.nvim_win_close(current_popup.winnr, true)
|
||||
end
|
||||
vim.cmd("augroup NvimTreeRemoveFilePopup | au! CursorMoved | augroup END")
|
||||
|
||||
current_popup = nil
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
local lib = require("nvim-tree.lib")
|
||||
local notify = require("nvim-tree.notify")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local core = require("nvim-tree.core")
|
||||
local full_name = require("nvim-tree.renderer.components.full-name")
|
||||
local view = require("nvim-tree.view")
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -20,10 +19,9 @@ end
|
||||
---Get all windows in the current tabpage that aren't NvimTree.
|
||||
---@return table with valid win_ids
|
||||
local function usable_win_ids()
|
||||
local explorer = core.get_explorer()
|
||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
|
||||
local tree_winid = explorer and explorer.view:get_winid(tabpage, "open-file.usable_win_ids")
|
||||
local tree_winid = view.get_winnr(tabpage)
|
||||
|
||||
return vim.tbl_filter(function(id)
|
||||
local bufid = vim.api.nvim_win_get_buf(id)
|
||||
@@ -41,15 +39,21 @@ local function usable_win_ids()
|
||||
end
|
||||
|
||||
local win_config = vim.api.nvim_win_get_config(id)
|
||||
return id ~= tree_winid
|
||||
and id ~= full_name.popup_win
|
||||
and win_config.focusable
|
||||
and not win_config.hide
|
||||
and not win_config.external
|
||||
or false
|
||||
return id ~= tree_winid and win_config.focusable and not win_config.external or false
|
||||
end, win_ids)
|
||||
end
|
||||
|
||||
---Find the first window in the tab that is not NvimTree.
|
||||
---@return integer -1 if none available
|
||||
local function first_win_id()
|
||||
local selectable = usable_win_ids()
|
||||
if #selectable > 0 then
|
||||
return selectable[1]
|
||||
else
|
||||
return -1
|
||||
end
|
||||
end
|
||||
|
||||
---Get user to pick a window in the tab that is not NvimTree.
|
||||
---@return integer|nil -- If a valid window was picked, return its id. If an
|
||||
--- invalid window was picked / user canceled, return nil. If there are
|
||||
@@ -76,14 +80,6 @@ local function pick_win_id()
|
||||
local win_map = {}
|
||||
local laststatus = vim.o.laststatus
|
||||
vim.o.laststatus = 2
|
||||
local fillchars = vim.opt.fillchars:get()
|
||||
local stl = fillchars.stl
|
||||
local stlnc = fillchars.stlnc
|
||||
fillchars.stl = nil
|
||||
fillchars.stlnc = nil
|
||||
vim.opt.fillchars = fillchars
|
||||
fillchars.stl = stl
|
||||
fillchars.stlnc = stlnc
|
||||
|
||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
|
||||
@@ -183,7 +179,6 @@ local function pick_win_id()
|
||||
end
|
||||
|
||||
vim.o.laststatus = laststatus
|
||||
vim.opt.fillchars = fillchars
|
||||
|
||||
if not vim.tbl_contains(vim.split(M.window_picker.chars, ""), resp) then
|
||||
return
|
||||
@@ -194,10 +189,7 @@ end
|
||||
|
||||
local function open_file_in_tab(filename)
|
||||
if M.quit_on_open then
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.view:close(nil, "open-file.open_file_in_tab")
|
||||
end
|
||||
view.close()
|
||||
end
|
||||
if M.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
@@ -207,10 +199,7 @@ end
|
||||
|
||||
local function drop(filename)
|
||||
if M.quit_on_open then
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.view:close(nil, "open-file.drop")
|
||||
end
|
||||
view.close()
|
||||
end
|
||||
if M.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
@@ -220,10 +209,7 @@ end
|
||||
|
||||
local function tab_drop(filename)
|
||||
if M.quit_on_open then
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.view:close(nil, "open-file.tab_drop")
|
||||
end
|
||||
view.close()
|
||||
end
|
||||
if M.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
@@ -244,24 +230,16 @@ local function on_preview(buf_loaded)
|
||||
once = true,
|
||||
})
|
||||
end
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.view:focus()
|
||||
end
|
||||
view.focus()
|
||||
end
|
||||
|
||||
local function get_target_winid(mode)
|
||||
local target_winid
|
||||
if not M.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
|
||||
if not vim.tbl_contains(usable_wins, target_winid) then
|
||||
if #usable_wins > 0 then
|
||||
target_winid = usable_wins[1]
|
||||
else
|
||||
target_winid = -1
|
||||
end
|
||||
-- first available window
|
||||
if not vim.tbl_contains(vim.api.nvim_tabpage_list_wins(0), target_winid) then
|
||||
target_winid = first_win_id()
|
||||
end
|
||||
else
|
||||
-- pick a window
|
||||
@@ -292,8 +270,6 @@ local function set_current_win_no_autocmd(winid, autocmd)
|
||||
end
|
||||
|
||||
local function open_in_new_window(filename, mode)
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
if type(mode) ~= "string" then
|
||||
mode = ""
|
||||
end
|
||||
@@ -316,11 +292,7 @@ local function open_in_new_window(filename, mode)
|
||||
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 = "belowright"
|
||||
if explorer and (explorer.view.side == "right") then
|
||||
new_window_side = "aboveleft"
|
||||
end
|
||||
local new_window_side = (view.View.side == "right") and "aboveleft" or "belowright"
|
||||
|
||||
-- Target is invalid: create new window
|
||||
if not vim.tbl_contains(win_ids, target_winid) then
|
||||
@@ -352,7 +324,7 @@ local function open_in_new_window(filename, mode)
|
||||
end
|
||||
end
|
||||
|
||||
if (mode == "preview" or mode == "preview_no_picker") and explorer and explorer.opts.view.float.enable then
|
||||
if (mode == "preview" or mode == "preview_no_picker") and view.View.float.enable then
|
||||
-- ignore "WinLeave" autocmd on preview
|
||||
-- because the registered "WinLeave"
|
||||
-- will kill the floating window immediately
|
||||
@@ -392,12 +364,7 @@ local function is_already_loaded(filename)
|
||||
end
|
||||
|
||||
local function edit_in_current_buf(filename)
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
if explorer then
|
||||
explorer.view:abandon_current_window()
|
||||
end
|
||||
|
||||
require("nvim-tree.view").abandon_current_window()
|
||||
if M.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
end
|
||||
@@ -408,8 +375,6 @@ end
|
||||
---@param filename string
|
||||
---@return nil
|
||||
function M.fn(mode, filename)
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
if type(mode) ~= "string" then
|
||||
mode = ""
|
||||
end
|
||||
@@ -444,16 +409,16 @@ function M.fn(mode, filename)
|
||||
vim.bo.bufhidden = ""
|
||||
end
|
||||
|
||||
if M.resize_window and explorer then
|
||||
explorer.view:resize()
|
||||
if M.resize_window then
|
||||
view.resize()
|
||||
end
|
||||
|
||||
if mode == "preview" or mode == "preview_no_picker" then
|
||||
return on_preview(buf_loaded)
|
||||
end
|
||||
|
||||
if M.quit_on_open and explorer then
|
||||
explorer.view:close(nil, "open-file.fn")
|
||||
if M.quit_on_open then
|
||||
view.close()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ M.force_dirchange = add_profiling_to(function(foldername, should_open_view)
|
||||
if should_change_dir() then
|
||||
cd(M.options.global, foldername)
|
||||
end
|
||||
core.init(foldername, "change-dir")
|
||||
core.init(foldername)
|
||||
end
|
||||
|
||||
if should_open_view then
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
|
||||
local M = {}
|
||||
@@ -40,12 +41,11 @@ function M.fn(opts)
|
||||
return
|
||||
end
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if explorer and explorer.view:is_visible(nil, "tree/find-file.fn") then
|
||||
if view.is_visible() then
|
||||
-- focus
|
||||
if opts.focus then
|
||||
lib.set_target_win()
|
||||
explorer.view:focus()
|
||||
view.focus()
|
||||
end
|
||||
elseif opts.open then
|
||||
-- open
|
||||
|
||||
@@ -2,7 +2,6 @@ local utils = require("nvim-tree.utils")
|
||||
local core = require("nvim-tree.core")
|
||||
local Iterator = require("nvim-tree.iterators.node-iterator")
|
||||
|
||||
local FileNode = require("nvim-tree.node.file")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
local M = {}
|
||||
@@ -24,30 +23,26 @@ local function buf_match()
|
||||
end
|
||||
end
|
||||
|
||||
---Collapse a node, root if nil
|
||||
---@param node Node?
|
||||
---@param opts ApiCollapseOpts
|
||||
local function collapse(node, opts)
|
||||
---@param keep_buffers boolean
|
||||
function M.fn(keep_buffers)
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer then
|
||||
return
|
||||
end
|
||||
|
||||
node = node or explorer
|
||||
|
||||
local node_at_cursor = explorer:get_node_at_cursor()
|
||||
if not node_at_cursor then
|
||||
local node = explorer:get_node_at_cursor()
|
||||
if not node then
|
||||
return
|
||||
end
|
||||
|
||||
local matches = buf_match()
|
||||
|
||||
Iterator.builder({ node:is(FileNode) and node.parent or node:as(DirectoryNode) })
|
||||
Iterator.builder(explorer.nodes)
|
||||
:hidden()
|
||||
:applier(function(n)
|
||||
local dir = n:as(DirectoryNode)
|
||||
if dir then
|
||||
dir.open = opts.keep_buffers == true and matches(dir.absolute_path)
|
||||
dir.open = keep_buffers and matches(dir.absolute_path)
|
||||
end
|
||||
end)
|
||||
:recursor(function(n)
|
||||
@@ -56,26 +51,7 @@ local function collapse(node, opts)
|
||||
:iterate()
|
||||
|
||||
explorer.renderer:draw()
|
||||
utils.focus_node_or_parent(node_at_cursor)
|
||||
end
|
||||
|
||||
|
||||
---@param opts ApiCollapseOpts|boolean|nil legacy -> opts.keep_buffers
|
||||
function M.all(opts)
|
||||
-- legacy arguments
|
||||
if type(opts) == "boolean" then
|
||||
opts = {
|
||||
keep_buffers = opts,
|
||||
}
|
||||
end
|
||||
|
||||
collapse(nil, opts or {})
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
---@param opts ApiCollapseOpts?
|
||||
function M.node(node, opts)
|
||||
collapse(node, opts or {})
|
||||
utils.focus_node_or_parent(node)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -2,7 +2,6 @@ local core = require("nvim-tree.core")
|
||||
local Iterator = require("nvim-tree.iterators.node-iterator")
|
||||
local notify = require("nvim-tree.notify")
|
||||
|
||||
local FileNode = require("nvim-tree.node.file")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
local M = {}
|
||||
@@ -71,38 +70,23 @@ local function gen_iterator()
|
||||
end
|
||||
end
|
||||
|
||||
---@param node Node?
|
||||
local function expand_node(node)
|
||||
if not node then
|
||||
---Expand the directory node or the root
|
||||
---@param node Node
|
||||
function M.fn(node)
|
||||
local explorer = core.get_explorer()
|
||||
local parent = node:as(DirectoryNode) or explorer
|
||||
if not parent then
|
||||
return
|
||||
end
|
||||
|
||||
if gen_iterator()(node) then
|
||||
if gen_iterator()(parent) then
|
||||
notify.warn("expansion iteration was halted after " .. M.MAX_FOLDER_DISCOVERY .. " discovered folders")
|
||||
end
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
end
|
||||
|
||||
---Expand the directory node or the root
|
||||
---@param node Node
|
||||
function M.all(node)
|
||||
expand_node(node and node:as(DirectoryNode) or core.get_explorer())
|
||||
end
|
||||
|
||||
---Expand the directory node or parent node
|
||||
---@param node Node
|
||||
function M.node(node)
|
||||
if not node then
|
||||
return
|
||||
end
|
||||
|
||||
expand_node(node:is(FileNode) and node.parent or node:as(DirectoryNode))
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.MAX_FOLDER_DISCOVERY = opts.actions.expand_all.max_folder_discovery
|
||||
M.EXCLUDE = to_lookup_table(opts.actions.expand_all.exclude)
|
||||
@@ -1,10 +1,10 @@
|
||||
local M = {}
|
||||
|
||||
M.collapse = require("nvim-tree.actions.tree.modifiers.collapse")
|
||||
M.expand = require("nvim-tree.actions.tree.modifiers.expand")
|
||||
M.collapse_all = require("nvim-tree.actions.tree.modifiers.collapse-all")
|
||||
M.expand_all = require("nvim-tree.actions.tree.modifiers.expand-all")
|
||||
|
||||
function M.setup(opts)
|
||||
M.expand.setup(opts)
|
||||
M.expand_all.setup(opts)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
|
||||
local M = {}
|
||||
@@ -23,12 +23,10 @@ function M.fn(opts)
|
||||
opts.path = nil
|
||||
end
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
if explorer and explorer.view:is_visible(nil, "open.fn") then
|
||||
if view.is_visible() then
|
||||
-- focus
|
||||
lib.set_target_win()
|
||||
explorer.view:focus()
|
||||
view.focus()
|
||||
else
|
||||
-- open
|
||||
lib.open({
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local view = require("nvim-tree.view")
|
||||
|
||||
local M = {}
|
||||
|
||||
---Resize the tree, persisting the new size.
|
||||
---@param opts ApiTreeResizeOpts|nil
|
||||
function M.fn(opts)
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer then
|
||||
return
|
||||
end
|
||||
|
||||
if opts == nil then
|
||||
-- reset to config values
|
||||
explorer.view:configure_width()
|
||||
explorer.view:resize()
|
||||
view.configure_width()
|
||||
view.resize()
|
||||
return
|
||||
end
|
||||
|
||||
@@ -21,19 +16,19 @@ function M.fn(opts)
|
||||
local width_cfg = options.width
|
||||
|
||||
if width_cfg ~= nil then
|
||||
explorer.view:configure_width(width_cfg)
|
||||
explorer.view:resize()
|
||||
view.configure_width(width_cfg)
|
||||
view.resize()
|
||||
return
|
||||
end
|
||||
|
||||
if not explorer.view:is_width_determined() then
|
||||
if not view.is_width_determined() then
|
||||
-- {absolute} and {relative} do nothing when {width} is a function.
|
||||
return
|
||||
end
|
||||
|
||||
local absolute = options.absolute
|
||||
if type(absolute) == "number" then
|
||||
explorer.view:resize(absolute)
|
||||
view.resize(absolute)
|
||||
return
|
||||
end
|
||||
|
||||
@@ -44,7 +39,7 @@ function M.fn(opts)
|
||||
relative_size = "+" .. relative_size
|
||||
end
|
||||
|
||||
explorer.view:resize(relative_size)
|
||||
view.resize(relative_size)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
|
||||
local M = {}
|
||||
@@ -10,8 +10,6 @@ local M = {}
|
||||
---@param cwd boolean|nil legacy -> opts.path
|
||||
---@param bang boolean|nil legacy -> opts.update_root
|
||||
function M.fn(opts, no_focus, cwd, bang)
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
-- legacy arguments
|
||||
if type(opts) == "boolean" then
|
||||
opts = {
|
||||
@@ -42,9 +40,9 @@ function M.fn(opts, no_focus, cwd, bang)
|
||||
opts.path = nil
|
||||
end
|
||||
|
||||
if explorer and explorer.view:is_visible(nil, "toggle.fn") then
|
||||
if view.is_visible() then
|
||||
-- close
|
||||
explorer.view:close(nil, "toggle.fn")
|
||||
view.close()
|
||||
else
|
||||
-- open
|
||||
lib.open({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local view = require("nvim-tree.view")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local actions = require("nvim-tree.actions")
|
||||
local appearance_hi_test = require("nvim-tree.appearance.hi-test")
|
||||
@@ -140,9 +141,9 @@ Api.tree.focus = Api.tree.open
|
||||
---@field focus boolean|nil default true
|
||||
|
||||
Api.tree.toggle = wrap(actions.tree.toggle.fn)
|
||||
Api.tree.close = wrap_explorer_member("view", "close")
|
||||
Api.tree.close_in_this_tab = wrap_explorer_member("view", "close_this_tab_only")
|
||||
Api.tree.close_in_all_tabs = wrap_explorer_member("view", "close_all_tabs")
|
||||
Api.tree.close = wrap(view.close)
|
||||
Api.tree.close_in_this_tab = wrap(view.close_this_tab_only)
|
||||
Api.tree.close_in_all_tabs = wrap(view.close_all_tabs)
|
||||
Api.tree.reload = wrap_explorer("reload_explorer")
|
||||
|
||||
---@class ApiTreeResizeOpts
|
||||
@@ -181,12 +182,8 @@ Api.tree.get_nodes = wrap_explorer("get_nodes")
|
||||
|
||||
Api.tree.find_file = wrap(actions.tree.find_file.fn)
|
||||
Api.tree.search_node = wrap(actions.finders.search_node.fn)
|
||||
|
||||
---@class ApiCollapseOpts
|
||||
---@field keep_buffers boolean|nil default false
|
||||
|
||||
Api.tree.collapse_all = wrap(actions.tree.modifiers.collapse.all)
|
||||
Api.tree.expand_all = wrap_node(actions.tree.modifiers.expand.all)
|
||||
Api.tree.collapse_all = wrap(actions.tree.modifiers.collapse_all.fn)
|
||||
Api.tree.expand_all = wrap_node(actions.tree.modifiers.expand_all.fn)
|
||||
Api.tree.toggle_enable_filters = wrap_explorer_member("filters", "toggle")
|
||||
Api.tree.toggle_gitignore_filter = wrap_explorer_member_args("filters", "toggle", "git_ignored")
|
||||
Api.tree.toggle_git_clean_filter = wrap_explorer_member_args("filters", "toggle", "git_clean")
|
||||
@@ -201,12 +198,12 @@ Api.tree.is_tree_buf = wrap(utils.is_nvim_tree_buf)
|
||||
---@field tabpage number|nil
|
||||
---@field any_tabpage boolean|nil default false
|
||||
|
||||
Api.tree.is_visible = wrap_explorer_member("view", "is_visible")
|
||||
Api.tree.is_visible = wrap(view.is_visible)
|
||||
|
||||
---@class ApiTreeWinIdOpts
|
||||
---@field tabpage number|nil default nil
|
||||
|
||||
Api.tree.winid = wrap_explorer_member("view", "api_winid")
|
||||
Api.tree.winid = wrap(view.winid)
|
||||
|
||||
Api.fs.create = wrap_node_or_nil(actions.fs.create_file.fn)
|
||||
Api.fs.remove = wrap_node(actions.fs.remove_file.fn)
|
||||
@@ -225,52 +222,21 @@ Api.fs.copy.absolute_path = wrap_node(wrap_explorer_member("clipboard", "copy_ab
|
||||
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"))
|
||||
---
|
||||
---@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 function edit(mode, node)
|
||||
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()
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
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
|
||||
if explorer then
|
||||
explorer.view:close(cur_tabpage, "api.edit " .. mode)
|
||||
end
|
||||
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
|
||||
if explorer then
|
||||
explorer.view:focus()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param mode string
|
||||
---@param toggle_group boolean?
|
||||
---@return fun(node: Node, edit_opts: NodeEditOpts?)
|
||||
---@return fun(node: Node)
|
||||
local function open_or_expand_or_dir_up(mode, toggle_group)
|
||||
---@param node Node
|
||||
---@param edit_opts NodeEditOpts?
|
||||
return function(node, edit_opts)
|
||||
return function(node)
|
||||
local root = node:as(RootNode)
|
||||
local dir = node:as(DirectoryNode)
|
||||
|
||||
@@ -279,7 +245,7 @@ local function open_or_expand_or_dir_up(mode, toggle_group)
|
||||
elseif dir then
|
||||
dir:expand_or_collapse(toggle_group)
|
||||
elseif not toggle_group then
|
||||
edit(mode, node, edit_opts)
|
||||
edit(mode, node)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -321,9 +287,6 @@ 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.prev = wrap_node(actions.moves.item.fn({ where = "prev", what = "opened" }))
|
||||
|
||||
Api.node.expand = wrap_node(actions.tree.modifiers.expand.node)
|
||||
Api.node.collapse = wrap_node(actions.tree.modifiers.collapse.node)
|
||||
|
||||
---@class ApiNodeDeleteWipeBufferOpts
|
||||
---@field force boolean|nil default false
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ function HighlightDisplay:render(bufnr, fmt, l)
|
||||
|
||||
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { text })
|
||||
|
||||
if vim.fn.has("nvim-0.11") == 1 and vim.hl and vim.hl.range then
|
||||
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
|
||||
|
||||
@@ -134,29 +134,6 @@ M.HIGHLIGHT_GROUPS = {
|
||||
{ group = "NvimTreeDiagnosticHintFolderHL", link = "NvimTreeDiagnosticHintFileHL" },
|
||||
}
|
||||
|
||||
-- winhighlight for most cases
|
||||
M.WIN_HL = 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",
|
||||
}, ",")
|
||||
|
||||
-- winhighlight for help
|
||||
M.WIN_HL_HELP = table.concat({
|
||||
"NormalFloat:NvimTreeNormalFloat",
|
||||
"WinSeparator:NvimTreeWinSeparator",
|
||||
"CursorLine:NvimTreeCursorLine",
|
||||
}, ",")
|
||||
|
||||
-- nvim-tree highlight groups to legacy
|
||||
M.LEGACY_LINKS = {
|
||||
NvimTreeModifiedIcon = "NvimTreeModifiedFile",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local api = require("nvim-tree.api")
|
||||
local core = require("nvim-tree.core")
|
||||
local view = require("nvim-tree.view")
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -111,10 +111,7 @@ local CMDS = {
|
||||
bar = true,
|
||||
},
|
||||
command = function(c)
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.view:resize(c.args)
|
||||
end
|
||||
view.resize(c.args)
|
||||
end,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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 M = {}
|
||||
@@ -9,12 +10,9 @@ local TreeExplorer = nil
|
||||
local first_init_done = false
|
||||
|
||||
---@param foldername string
|
||||
---@param callsite string
|
||||
function M.init(foldername, callsite)
|
||||
function M.init(foldername)
|
||||
local profile = log.profile_start("core init %s", foldername)
|
||||
|
||||
log.line("dev", "core.init(%s, %s)", foldername, callsite)
|
||||
|
||||
if TreeExplorer then
|
||||
TreeExplorer:destroy()
|
||||
end
|
||||
@@ -57,7 +55,7 @@ end
|
||||
---@return integer
|
||||
function M.get_nodes_starting_line()
|
||||
local offset = 1
|
||||
if TreeExplorer and TreeExplorer.view:is_root_folder_visible(M.get_cwd()) then
|
||||
if view.is_root_folder_visible(M.get_cwd()) then
|
||||
offset = offset + 1
|
||||
end
|
||||
if TreeExplorer and TreeExplorer.live_filter.filter then
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local view = require("nvim-tree.view")
|
||||
local log = require("nvim-tree.log")
|
||||
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
@@ -181,15 +182,10 @@ function M.update_coc()
|
||||
end
|
||||
log.profile_end(profile)
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
local bufnr
|
||||
if explorer then
|
||||
bufnr = explorer.view:get_bufnr("diagnostics.update_coc")
|
||||
end
|
||||
|
||||
local bufnr = view.get_bufnr()
|
||||
local should_draw = bufnr and vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_is_loaded(bufnr)
|
||||
if should_draw then
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
|
||||
@@ -8,7 +8,6 @@ M.Event = {
|
||||
Ready = "Ready",
|
||||
WillRenameNode = "WillRenameNode",
|
||||
NodeRenamed = "NodeRenamed",
|
||||
TreePreOpen = "TreePreOpen",
|
||||
TreeOpen = "TreeOpen",
|
||||
TreeClose = "TreeClose",
|
||||
WillCreateFile = "WillCreateFile",
|
||||
@@ -92,11 +91,6 @@ function M._dispatch_folder_removed(folder_name)
|
||||
dispatch(M.Event.FolderRemoved, { folder_name = folder_name })
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_on_tree_pre_open()
|
||||
dispatch(M.Event.TreePreOpen, nil)
|
||||
end
|
||||
|
||||
--@private
|
||||
function M._dispatch_on_tree_open()
|
||||
dispatch(M.Event.TreeOpen, nil)
|
||||
|
||||
@@ -23,8 +23,6 @@ local Filters = Class:extend()
|
||||
---@protected
|
||||
---@param args FiltersArgs
|
||||
function Filters:new(args)
|
||||
args.explorer:log_new("Filters")
|
||||
|
||||
self.explorer = args.explorer
|
||||
self.ignore_list = {}
|
||||
self.exclude_list = self.explorer.opts.filters.exclude
|
||||
@@ -52,10 +50,6 @@ function Filters:new(args)
|
||||
end
|
||||
end
|
||||
|
||||
function Filters:destroy()
|
||||
self.explorer:log_destroy("Filters")
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param path string
|
||||
---@return boolean
|
||||
|
||||
@@ -4,6 +4,7 @@ local core = require("nvim-tree.core")
|
||||
local git = require("nvim-tree.git")
|
||||
local log = require("nvim-tree.log")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local view = require("nvim-tree.view")
|
||||
local node_factory = require("nvim-tree.node.factory")
|
||||
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
@@ -19,7 +20,6 @@ local LiveFilter = require("nvim-tree.explorer.live-filter")
|
||||
local Sorter = require("nvim-tree.explorer.sorter")
|
||||
local Clipboard = require("nvim-tree.actions.fs.clipboard")
|
||||
local Renderer = require("nvim-tree.renderer")
|
||||
local View = require("nvim-tree.explorer.view")
|
||||
|
||||
local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON
|
||||
|
||||
@@ -35,7 +35,6 @@ local config
|
||||
---@field sorters Sorter
|
||||
---@field marks Marks
|
||||
---@field clipboard Clipboard
|
||||
---@field view View
|
||||
local Explorer = RootNode:extend()
|
||||
|
||||
---@class Explorer
|
||||
@@ -56,8 +55,6 @@ function Explorer:new(args)
|
||||
self.uid_explorer = vim.loop.hrtime()
|
||||
self.augroup_id = vim.api.nvim_create_augroup("NvimTree_Explorer_" .. self.uid_explorer, {})
|
||||
|
||||
self:log_new("Explorer")
|
||||
|
||||
self.open = true
|
||||
self.opts = config
|
||||
|
||||
@@ -67,7 +64,6 @@ function Explorer:new(args)
|
||||
self.live_filter = LiveFilter({ explorer = self })
|
||||
self.marks = Marks({ explorer = self })
|
||||
self.clipboard = Clipboard({ explorer = self })
|
||||
self.view = View({ explorer = self })
|
||||
|
||||
self:create_autocmds()
|
||||
|
||||
@@ -75,15 +71,7 @@ function Explorer:new(args)
|
||||
end
|
||||
|
||||
function Explorer:destroy()
|
||||
self.explorer:log_destroy("Explorer")
|
||||
|
||||
self.clipboard:destroy()
|
||||
self.filters:destroy()
|
||||
self.live_filter:destroy()
|
||||
self.marks:destroy()
|
||||
self.renderer:destroy()
|
||||
self.sorters:destroy()
|
||||
self.view:destroy()
|
||||
log.line("dev", "Explorer:destroy")
|
||||
|
||||
vim.api.nvim_del_augroup_by_id(self.augroup_id)
|
||||
|
||||
@@ -96,26 +84,11 @@ function Explorer:create_autocmds()
|
||||
group = self.augroup_id,
|
||||
callback = function()
|
||||
appearance.setup()
|
||||
self.view:reset_winhl()
|
||||
view.reset_winhl()
|
||||
self.renderer:draw()
|
||||
end,
|
||||
})
|
||||
|
||||
if self.opts.view.float.enable and self.opts.view.float.quit_on_focus_loss then
|
||||
vim.api.nvim_create_autocmd("WinLeave", {
|
||||
group = self.augroup_id,
|
||||
pattern = "NvimTree_*",
|
||||
callback = function(data)
|
||||
if self.opts.experimental.multi_instance then
|
||||
log.line("dev", "WinLeave %s", vim.inspect(data, { newline = "" }))
|
||||
end
|
||||
if utils.is_nvim_tree_buf(0) then
|
||||
self.view:close(nil, "WinLeave")
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||
group = self.augroup_id,
|
||||
callback = function()
|
||||
@@ -128,19 +101,10 @@ function Explorer:create_autocmds()
|
||||
vim.api.nvim_create_autocmd("BufReadPost", {
|
||||
group = self.augroup_id,
|
||||
callback = function(data)
|
||||
-- only handle normal files
|
||||
if vim.bo[data.buf].buftype ~= "" then
|
||||
return
|
||||
end
|
||||
|
||||
if self.filters.state.no_buffer then
|
||||
-- full reload is required to update the filter state
|
||||
if (self.filters.state.no_buffer or self.opts.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == "" then
|
||||
utils.debounce("Buf:filter_buffer_" .. self.uid_explorer, self.opts.view.debounce_delay, function()
|
||||
self:reload_explorer()
|
||||
end)
|
||||
elseif self.opts.renderer.highlight_opened_files ~= "none" then
|
||||
-- draw to update opened highlight
|
||||
self.renderer:draw()
|
||||
end
|
||||
end,
|
||||
})
|
||||
@@ -149,40 +113,10 @@ function Explorer:create_autocmds()
|
||||
vim.api.nvim_create_autocmd("BufUnload", {
|
||||
group = self.augroup_id,
|
||||
callback = function(data)
|
||||
-- only handle normal files
|
||||
if vim.bo[data.buf].buftype ~= "" then
|
||||
return
|
||||
end
|
||||
|
||||
if self.filters.state.no_buffer then
|
||||
-- full reload is required to update the filter state
|
||||
if (self.filters.state.no_buffer or self.opts.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == "" then
|
||||
utils.debounce("Buf:filter_buffer_" .. self.uid_explorer, self.opts.view.debounce_delay, function()
|
||||
self:reload_explorer()
|
||||
end)
|
||||
elseif self.opts.renderer.highlight_opened_files ~= "none" then
|
||||
-- draw to update opened highlight; must be delayed as the buffer is still loaded during BufUnload
|
||||
vim.schedule(function()
|
||||
self.renderer:draw()
|
||||
end)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- prevent new opened file from opening in the same window as nvim-tree
|
||||
vim.api.nvim_create_autocmd("BufWipeout", {
|
||||
group = self.augroup_id,
|
||||
pattern = "NvimTree_*",
|
||||
callback = function(data)
|
||||
if self.opts.experimental.multi_instance then
|
||||
log.line("dev", "BufWipeout %s", vim.inspect(data, { newline = "" }))
|
||||
end
|
||||
if not utils.is_nvim_tree_buf(0) then
|
||||
return
|
||||
end
|
||||
if self.opts.actions.open_file.eject then
|
||||
self.view:prevent_buffer_override()
|
||||
else
|
||||
self.view:abandon_current_window()
|
||||
end
|
||||
end,
|
||||
})
|
||||
@@ -280,9 +214,8 @@ function Explorer:reload(node, project)
|
||||
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
|
||||
---@type uv.fs_stat.result|nil
|
||||
local stat = vim.loop.fs_lstat(abs)
|
||||
|
||||
local filter_reason = self.filters:should_filter_as_reason(abs, stat, filter_status)
|
||||
if filter_reason == FILTER_REASON.none then
|
||||
@@ -440,9 +373,8 @@ 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
|
||||
|
||||
---@type uv.fs_stat.result|nil
|
||||
local stat = vim.loop.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
|
||||
local child = node_factory.create({
|
||||
@@ -457,9 +389,9 @@ function Explorer:populate_children(handle, cwd, node, project, parent)
|
||||
nodes_by_path[child.absolute_path] = true
|
||||
child:update_git_status(node_ignored, project)
|
||||
end
|
||||
elseif node.hidden_stats then
|
||||
else
|
||||
for reason, value in pairs(FILTER_REASON) do
|
||||
if filter_reason == value and type(node.hidden_stats[reason]) == "number" then
|
||||
if filter_reason == value then
|
||||
node.hidden_stats[reason] = node.hidden_stats[reason] + 1
|
||||
end
|
||||
end
|
||||
@@ -532,7 +464,7 @@ function Explorer:reload_explorer()
|
||||
|
||||
local projects = git.reload_all_projects()
|
||||
self:refresh_nodes(projects)
|
||||
if self.view:is_visible(nil, "Explorer:reload_explorer") then
|
||||
if view.is_visible() then
|
||||
self.renderer:draw()
|
||||
end
|
||||
event_running = false
|
||||
@@ -554,7 +486,7 @@ end
|
||||
---nil on no explorer or invalid view win
|
||||
---@return integer[]|nil
|
||||
function Explorer:get_cursor_position()
|
||||
local winnr = self.view:get_winid(nil, "Explorer:get_cursor_position")
|
||||
local winnr = view.get_winnr()
|
||||
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
|
||||
return
|
||||
end
|
||||
@@ -569,7 +501,7 @@ function Explorer:get_node_at_cursor()
|
||||
return
|
||||
end
|
||||
|
||||
if cursor[1] == 1 and self.view:is_root_folder_visible(core.get_cwd()) then
|
||||
if cursor[1] == 1 and view.is_root_folder_visible(core.get_cwd()) then
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -603,18 +535,6 @@ function Explorer:get_nodes()
|
||||
return self:clone()
|
||||
end
|
||||
|
||||
---Log a lifecycle message with uid_explorer and absolute_path
|
||||
---@param msg string?
|
||||
function Explorer:log_new(msg)
|
||||
log.line("dev", "+ %-15s %d %s", msg, self.uid_explorer, self.absolute_path)
|
||||
end
|
||||
|
||||
---Log a lifecycle message with uid_explorer and absolute_path
|
||||
---@param msg string?
|
||||
function Explorer:log_destroy(msg)
|
||||
log.line("dev", "- %-15s %d %s", msg, self.uid_explorer, self.absolute_path)
|
||||
end
|
||||
|
||||
function Explorer:setup(opts)
|
||||
config = opts
|
||||
end
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
local view = require("nvim-tree.view")
|
||||
local utils = require("nvim-tree.utils")
|
||||
|
||||
local Class = require("nvim-tree.classic")
|
||||
@@ -20,18 +21,12 @@ local LiveFilter = Class:extend()
|
||||
---@protected
|
||||
---@param args LiveFilterArgs
|
||||
function LiveFilter:new(args)
|
||||
args.explorer:log_new("LiveFilter")
|
||||
|
||||
self.explorer = args.explorer
|
||||
self.prefix = self.explorer.opts.live_filter.prefix
|
||||
self.always_show_folders = self.explorer.opts.live_filter.always_show_folders
|
||||
self.filter = nil
|
||||
end
|
||||
|
||||
function LiveFilter:destroy()
|
||||
self.explorer:log_destroy("LiveFilter")
|
||||
end
|
||||
|
||||
---@param node_ Node?
|
||||
local function reset_filter(self, node_)
|
||||
node_ = node_ or self.explorer
|
||||
@@ -61,14 +56,14 @@ local overlay_bufnr = 0
|
||||
local overlay_winnr = 0
|
||||
|
||||
local function remove_overlay(self)
|
||||
if self.explorer.opts.view.float.enable and self.explorer.opts.view.float.quit_on_focus_loss then
|
||||
if view.View.float.enable and view.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_*",
|
||||
group = vim.api.nvim_create_augroup("NvimTree", { clear = false }),
|
||||
callback = function()
|
||||
if utils.is_nvim_tree_buf(0) then
|
||||
self.explorer.view:close()
|
||||
view.close()
|
||||
end
|
||||
end,
|
||||
})
|
||||
@@ -161,7 +156,7 @@ end
|
||||
|
||||
---@return integer
|
||||
local function calculate_overlay_win_width(self)
|
||||
local wininfo = vim.fn.getwininfo(self.explorer.view:get_winnr())[1]
|
||||
local wininfo = vim.fn.getwininfo(view.get_winnr())[1]
|
||||
|
||||
if wininfo then
|
||||
return wininfo.width - wininfo.textoff - #self.prefix
|
||||
@@ -171,7 +166,7 @@ local function calculate_overlay_win_width(self)
|
||||
end
|
||||
|
||||
local function create_overlay(self)
|
||||
if self.explorer.opts.view.float.enable then
|
||||
if view.View.float.enable then
|
||||
-- don't close nvim-tree float when focus is changed to filter window
|
||||
vim.api.nvim_clear_autocmds({
|
||||
event = "WinLeave",
|
||||
@@ -203,13 +198,13 @@ local function create_overlay(self)
|
||||
end
|
||||
|
||||
function LiveFilter:start_filtering()
|
||||
self.explorer.view.live_filter.prev_focused_node = self.explorer:get_node_at_cursor()
|
||||
view.View.live_filter.prev_focused_node = self.explorer:get_node_at_cursor()
|
||||
self.filter = self.filter or ""
|
||||
|
||||
self.explorer.renderer:draw()
|
||||
local row = require("nvim-tree.core").get_nodes_starting_line() - 1
|
||||
local col = #self.prefix > 0 and #self.prefix - 1 or 1
|
||||
self.explorer.view:set_cursor({ row, col })
|
||||
view.set_cursor({ row, col })
|
||||
-- needs scheduling to let the cursor move before initializing the window
|
||||
vim.schedule(function()
|
||||
return create_overlay(self)
|
||||
@@ -218,7 +213,7 @@ end
|
||||
|
||||
function LiveFilter:clear_filter()
|
||||
local node = self.explorer:get_node_at_cursor()
|
||||
local last_node = self.explorer.view.live_filter.prev_focused_node
|
||||
local last_node = view.View.live_filter.prev_focused_node
|
||||
|
||||
self.filter = nil
|
||||
reset_filter(self)
|
||||
|
||||
@@ -19,15 +19,9 @@ local Sorter = Class:extend()
|
||||
---@protected
|
||||
---@param args SorterArgs
|
||||
function Sorter:new(args)
|
||||
args.explorer:log_new("Sorter")
|
||||
|
||||
self.explorer = args.explorer
|
||||
end
|
||||
|
||||
function Sorter:destroy()
|
||||
self.explorer:log_destroy("Sorter")
|
||||
end
|
||||
|
||||
---Create a shallow copy of a portion of a list.
|
||||
---@param t table
|
||||
---@param first integer First index, inclusive
|
||||
|
||||
@@ -1,811 +0,0 @@
|
||||
local appearance = require("nvim-tree.appearance")
|
||||
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 globals = require("nvim-tree.globals")
|
||||
|
||||
local Class = require("nvim-tree.classic")
|
||||
|
||||
---Window and buffer related settings and operations
|
||||
---@class (exact) View: Class
|
||||
---@field live_filter table
|
||||
---@field side string
|
||||
---@field private explorer Explorer
|
||||
---@field private adaptive_size boolean
|
||||
---@field private winopts table
|
||||
---@field private initial_width integer
|
||||
---@field private width (fun():integer)|integer|string
|
||||
---@field private max_width integer
|
||||
---@field private padding integer
|
||||
-- TODO multi-instance remove or replace with single member
|
||||
---@field private bufnr_by_tabid table<integer, integer>
|
||||
-- TODO multi-instance change to single member
|
||||
---@field private cursors_by_tabid table<integer, integer[]> as per vim.api.nvim_win_get_cursor
|
||||
local View = Class:extend()
|
||||
|
||||
---@class View
|
||||
---@overload fun(args: ViewArgs): View
|
||||
|
||||
---@class (exact) ViewArgs
|
||||
---@field explorer Explorer
|
||||
|
||||
---@protected
|
||||
---@param args ViewArgs
|
||||
function View:new(args)
|
||||
args.explorer:log_new("View")
|
||||
|
||||
self.explorer = args.explorer
|
||||
self.adaptive_size = false
|
||||
self.side = (self.explorer.opts.view.side == "right") and "right" or "left"
|
||||
self.live_filter = { prev_focused_node = nil, }
|
||||
self.bufnr_by_tabid = {}
|
||||
self.cursors_by_tabid = {}
|
||||
|
||||
self.winopts = {
|
||||
relativenumber = self.explorer.opts.view.relativenumber,
|
||||
number = self.explorer.opts.view.number,
|
||||
list = false,
|
||||
foldenable = false,
|
||||
winfixwidth = true,
|
||||
winfixheight = true,
|
||||
spell = false,
|
||||
signcolumn = self.explorer.opts.view.signcolumn,
|
||||
foldmethod = "manual",
|
||||
foldcolumn = "0",
|
||||
cursorcolumn = false,
|
||||
cursorline = self.explorer.opts.view.cursorline,
|
||||
cursorlineopt = self.explorer.opts.view.cursorlineopt,
|
||||
colorcolumn = "0",
|
||||
wrap = false,
|
||||
winhl = appearance.WIN_HL,
|
||||
}
|
||||
|
||||
self:configure_width(self.explorer.opts.view.width)
|
||||
self.initial_width = self:get_width()
|
||||
|
||||
-- TODO multi-instance remove this; delete buffers rather than retaining them
|
||||
local tabid = vim.api.nvim_get_current_tabpage()
|
||||
self.bufnr_by_tabid[tabid] = globals.BUFNR_BY_TABID[tabid]
|
||||
end
|
||||
|
||||
function View:destroy()
|
||||
self.explorer:log_destroy("View")
|
||||
end
|
||||
|
||||
---@type { name: string, value: any }[]
|
||||
local BUFFER_OPTIONS = {
|
||||
{ name = "bufhidden", value = "wipe" },
|
||||
{ name = "buflisted", value = false },
|
||||
{ name = "buftype", value = "nofile" },
|
||||
{ name = "filetype", value = "NvimTree" },
|
||||
{ name = "modifiable", value = false },
|
||||
{ name = "swapfile", value = false },
|
||||
}
|
||||
|
||||
-- TODO multi-instance remove this; delete buffers rather than retaining them
|
||||
---@private
|
||||
---@param bufnr integer
|
||||
---@return boolean
|
||||
function View:matches_bufnr(bufnr)
|
||||
for _, b in pairs(globals.BUFNR_BY_TABID) do
|
||||
if b == bufnr then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- TODO multi-instance remove this; delete buffers rather than retaining them
|
||||
---@private
|
||||
function View:wipe_rogue_buffer()
|
||||
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if not self:matches_bufnr(bufnr) and utils.is_nvim_tree_buf(bufnr) then
|
||||
pcall(vim.api.nvim_buf_delete, bufnr, { force = true })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param bufnr integer|false|nil
|
||||
function View:create_buffer(bufnr)
|
||||
self:wipe_rogue_buffer()
|
||||
|
||||
local tabid = vim.api.nvim_get_current_tabpage()
|
||||
|
||||
bufnr = bufnr or vim.api.nvim_create_buf(false, false)
|
||||
|
||||
-- set both bufnr registries
|
||||
globals.BUFNR_BY_TABID[tabid] = bufnr
|
||||
self.bufnr_by_tabid[tabid] = bufnr
|
||||
|
||||
vim.api.nvim_buf_set_name(bufnr, "NvimTree_" .. tabid)
|
||||
|
||||
for _, option in ipairs(BUFFER_OPTIONS) do
|
||||
vim.api.nvim_set_option_value(option.name, option.value, { buf = bufnr })
|
||||
end
|
||||
|
||||
require("nvim-tree.keymap").on_attach(bufnr)
|
||||
|
||||
events._dispatch_tree_attached_post(bufnr)
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param size (fun():integer)|integer|string
|
||||
---@return integer
|
||||
function View:get_size(size)
|
||||
if type(size) == "number" then
|
||||
return size
|
||||
elseif type(size) == "function" then
|
||||
return self: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 View:get_width(size)
|
||||
if size then
|
||||
return self:get_size(size)
|
||||
else
|
||||
return self:get_size(self.width)
|
||||
end
|
||||
end
|
||||
|
||||
local move_tbl = {
|
||||
left = "H",
|
||||
right = "L",
|
||||
}
|
||||
|
||||
---@private
|
||||
function View:set_window_options_and_buffer()
|
||||
pcall(vim.api.nvim_command, "buffer " .. self:get_bufnr("View:set_window_options_and_buffer"))
|
||||
|
||||
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", {})
|
||||
|
||||
for k, v in pairs(self.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(self.winopts) do
|
||||
vim.opt_local[k] = v
|
||||
end
|
||||
|
||||
vim.api.nvim_set_option("eventignore", eventignore) ---@diagnostic disable-line: deprecated
|
||||
end
|
||||
end
|
||||
|
||||
---@private
|
||||
---@return table
|
||||
function View:open_win_config()
|
||||
if type(self.explorer.opts.view.float.open_win_config) == "function" then
|
||||
return self.explorer.opts.view.float.open_win_config()
|
||||
else
|
||||
return self.explorer.opts.view.float.open_win_config
|
||||
end
|
||||
end
|
||||
|
||||
---@private
|
||||
function View:open_window()
|
||||
if self.explorer.opts.view.float.enable then
|
||||
vim.api.nvim_open_win(0, true, self:open_win_config())
|
||||
else
|
||||
vim.api.nvim_command("vsp")
|
||||
self:reposition_window()
|
||||
end
|
||||
globals.WINID_BY_TABID[vim.api.nvim_get_current_tabpage()] = vim.api.nvim_get_current_win()
|
||||
self:set_window_options_and_buffer()
|
||||
end
|
||||
|
||||
---@param buf integer
|
||||
---@return boolean
|
||||
local function is_buf_displayed(buf)
|
||||
return vim.api.nvim_buf_is_valid(buf) and vim.fn.buflisted(buf) == 1
|
||||
end
|
||||
|
||||
---@return number|nil
|
||||
local function get_alt_or_next_buf()
|
||||
local alt_buf = vim.fn.bufnr("#")
|
||||
if is_buf_displayed(alt_buf) then
|
||||
return alt_buf
|
||||
end
|
||||
|
||||
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if is_buf_displayed(buf) then
|
||||
return buf
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function switch_buf_if_last_buf()
|
||||
if #vim.api.nvim_list_wins() == 1 then
|
||||
local buf = get_alt_or_next_buf()
|
||||
if buf then
|
||||
vim.cmd("sb" .. buf)
|
||||
else
|
||||
vim.cmd("new")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---save any state that should be preserved on reopening
|
||||
---@private
|
||||
---@param tabid integer
|
||||
function View:save_state(tabid)
|
||||
tabid = tabid or vim.api.nvim_get_current_tabpage()
|
||||
self.cursors_by_tabid[tabid] = vim.api.nvim_win_get_cursor(self:get_winid(tabid, "View:save_tab_state") or 0)
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param tabid integer
|
||||
function View:close_internal(tabid)
|
||||
--- BEGIN multi-instance FF
|
||||
if self.explorer.opts.experimental.multi_instance then
|
||||
log.line("dev", "View:close_internal(t%s)", tabid)
|
||||
end
|
||||
--- END multi-instance FF
|
||||
|
||||
if not self:is_visible({ tabpage = tabid }, "View:close_internal") then
|
||||
return
|
||||
end
|
||||
self:save_state(tabid)
|
||||
switch_buf_if_last_buf()
|
||||
local tree_win = self:get_winid(tabid, "View:close_internal")
|
||||
local current_win = vim.api.nvim_get_current_win()
|
||||
for _, win in pairs(vim.api.nvim_tabpage_list_wins(tabid)) do
|
||||
if vim.api.nvim_win_get_config(win).relative == "" then
|
||||
local prev_win = vim.fn.winnr("#") -- this tab only
|
||||
if tree_win == current_win and prev_win > 0 then
|
||||
vim.api.nvim_set_current_win(vim.fn.win_getid(prev_win))
|
||||
end
|
||||
if vim.api.nvim_win_is_valid(tree_win or 0) then
|
||||
--- BEGIN multi-instance FF
|
||||
if self.explorer.opts.experimental.multi_instance then
|
||||
log.line("dev", "View:close_internal(t%s) w%s", tabid, tree_win)
|
||||
end
|
||||
--- END multi-instance FF
|
||||
---
|
||||
local success, error = pcall(vim.api.nvim_win_close, tree_win or 0, true)
|
||||
if not success then
|
||||
notify.debug("Failed to close window: " .. error)
|
||||
return
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function View:close_this_tab_only()
|
||||
--- BEGIN multi-instance FF
|
||||
if self.explorer.opts.experimental.multi_instance then
|
||||
log.line("dev", "View:close_this_tab_only()")
|
||||
end
|
||||
--- END multi-instance FF
|
||||
|
||||
self:close_internal(vim.api.nvim_get_current_tabpage())
|
||||
end
|
||||
|
||||
-- TODO this is broken at 1.13.0 - current tab does not close when tab.sync.close is set
|
||||
function View:close_all_tabs()
|
||||
log.line("dev", "View:close_all_tabs() globals.WINID_BY_TABID=%s", vim.inspect(globals.WINID_BY_TABID))
|
||||
for tabid, _ in pairs(globals.WINID_BY_TABID) do
|
||||
--- BEGIN multi-instance FF
|
||||
if self.explorer.opts.experimental.multi_instance then
|
||||
log.line("dev", "View:close_all_tabs()")
|
||||
end
|
||||
--- END multi-instance FF
|
||||
|
||||
self:close_internal(tabid)
|
||||
end
|
||||
end
|
||||
|
||||
---@param tabid integer|nil
|
||||
---@param callsite string
|
||||
function View:close(tabid, callsite)
|
||||
--- BEGIN multi-instance FF
|
||||
if self.explorer.opts.experimental.multi_instance then
|
||||
log.line("dev", "View:close(t%s, %s)", tabid, callsite)
|
||||
end
|
||||
--- END multi-instance FF
|
||||
|
||||
if self.explorer.opts.tab.sync.close then
|
||||
self:close_all_tabs()
|
||||
elseif tabid then
|
||||
self:close_internal(tabid)
|
||||
else
|
||||
self:close_this_tab_only()
|
||||
end
|
||||
end
|
||||
|
||||
---@param options table|nil
|
||||
function View:open(options)
|
||||
if self:is_visible(nil, "View:open") then
|
||||
return
|
||||
end
|
||||
|
||||
local profile = log.profile_start("view open")
|
||||
|
||||
events._dispatch_on_tree_pre_open()
|
||||
self:create_buffer()
|
||||
self:open_window()
|
||||
self:resize()
|
||||
|
||||
local opts = options or { focus_tree = true }
|
||||
if not opts.focus_tree then
|
||||
vim.cmd("wincmd p")
|
||||
end
|
||||
events._dispatch_on_tree_open()
|
||||
|
||||
log.profile_end(profile)
|
||||
end
|
||||
|
||||
---@private
|
||||
function View:grow()
|
||||
local starts_at = self:is_root_folder_visible(require("nvim-tree.core").get_cwd()) and 1 or 0
|
||||
local lines = vim.api.nvim_buf_get_lines(self:get_bufnr("View:grow1"), starts_at, -1, false)
|
||||
-- number of columns of right-padding to indicate end of path
|
||||
local padding = self:get_size(self.padding)
|
||||
|
||||
-- account for sign/number columns etc.
|
||||
local wininfo = vim.fn.getwininfo(self:get_winid(nil, "View:grow"))
|
||||
if type(wininfo) == "table" and type(wininfo[1]) == "table" then
|
||||
padding = padding + wininfo[1].textoff
|
||||
end
|
||||
|
||||
local resizing_width = self.initial_width - padding
|
||||
local max_width
|
||||
|
||||
-- maybe bound max
|
||||
if self.max_width == -1 then
|
||||
max_width = -1
|
||||
else
|
||||
max_width = self:get_width(self.max_width) - padding
|
||||
end
|
||||
|
||||
local ns_id = vim.api.nvim_get_namespaces()["NvimTreeExtmarks"]
|
||||
for line_nr, l in pairs(lines) do
|
||||
local count = vim.fn.strchars(l)
|
||||
-- also add space for right-aligned icons
|
||||
local extmarks = vim.api.nvim_buf_get_extmarks(self:get_bufnr("View:grow2"), ns_id, { line_nr, 0 }, { line_nr, -1 }, { details = true })
|
||||
count = count + utils.extmarks_length(extmarks)
|
||||
if resizing_width < count then
|
||||
resizing_width = count
|
||||
end
|
||||
if self.adaptive_size and max_width >= 0 and resizing_width >= max_width then
|
||||
resizing_width = max_width
|
||||
break
|
||||
end
|
||||
end
|
||||
self:resize(resizing_width + padding)
|
||||
end
|
||||
|
||||
function View:grow_from_content()
|
||||
if self.adaptive_size then
|
||||
self:grow()
|
||||
end
|
||||
end
|
||||
|
||||
---@param size string|number|nil
|
||||
function View:resize(size)
|
||||
if self.explorer.opts.view.float.enable and not self.adaptive_size then
|
||||
-- if the floating windows's adaptive size is not desired, then the
|
||||
-- float size should be defined in self.explorer.opts.view.float.open_win_config
|
||||
return
|
||||
end
|
||||
|
||||
if type(size) == "string" then
|
||||
size = vim.trim(size)
|
||||
local first_char = size:sub(1, 1)
|
||||
size = tonumber(size)
|
||||
|
||||
if first_char == "+" or first_char == "-" then
|
||||
size = self.width + size
|
||||
end
|
||||
end
|
||||
|
||||
if type(size) == "number" and size <= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
if size then
|
||||
self.width = size
|
||||
end
|
||||
|
||||
if not self:is_visible(nil, "View:resize") then
|
||||
return
|
||||
end
|
||||
|
||||
local winid = self:get_winid(nil, "View:resize") or 0
|
||||
|
||||
local new_size = self:get_width()
|
||||
|
||||
if new_size ~= vim.api.nvim_win_get_width(winid) then
|
||||
vim.api.nvim_win_set_width(winid, new_size)
|
||||
if not self.explorer.opts.view.preserve_window_proportions then
|
||||
vim.cmd(":wincmd =")
|
||||
end
|
||||
end
|
||||
|
||||
events._dispatch_on_tree_resize(new_size)
|
||||
end
|
||||
|
||||
---@private
|
||||
function View:reposition_window()
|
||||
local move_to = move_tbl[self.side]
|
||||
vim.api.nvim_command("wincmd " .. move_to)
|
||||
self:resize()
|
||||
end
|
||||
|
||||
---@private
|
||||
function View:set_current_win()
|
||||
local current_tab = vim.api.nvim_get_current_tabpage()
|
||||
globals.WINID_BY_TABID[current_tab] = vim.api.nvim_get_current_win()
|
||||
end
|
||||
|
||||
---@class OpenInWinOpts
|
||||
---@field hijack_current_buf boolean|nil default true
|
||||
---@field resize boolean|nil default true
|
||||
---@field winid number|nil 0 or nil for current
|
||||
|
||||
---Open the tree in the a window
|
||||
---@param opts OpenInWinOpts|nil
|
||||
function View:open_in_win(opts)
|
||||
opts = opts or { hijack_current_buf = true, resize = true }
|
||||
events._dispatch_on_tree_pre_open()
|
||||
if opts.winid and vim.api.nvim_win_is_valid(opts.winid) then
|
||||
vim.api.nvim_set_current_win(opts.winid)
|
||||
end
|
||||
self:create_buffer(opts.hijack_current_buf and vim.api.nvim_get_current_buf())
|
||||
globals.WINID_BY_TABID[vim.api.nvim_get_current_tabpage()] = vim.api.nvim_get_current_win()
|
||||
self:set_current_win()
|
||||
self:set_window_options_and_buffer()
|
||||
if opts.resize then
|
||||
self:reposition_window()
|
||||
self:resize()
|
||||
end
|
||||
events._dispatch_on_tree_open()
|
||||
end
|
||||
|
||||
function View:abandon_current_window()
|
||||
local tab = vim.api.nvim_get_current_tabpage()
|
||||
|
||||
--- BEGIN multi-instance FF
|
||||
if self.explorer.opts.experimental.multi_instance then
|
||||
log.line("dev", "View:abandon_current_window() t%d w%s b%s member b%s %s",
|
||||
tab,
|
||||
globals.WINID_BY_TABID[tab],
|
||||
globals.BUFNR_BY_TABID[tab],
|
||||
self.bufnr_by_tabid[tab],
|
||||
(globals.BUFNR_BY_TABID[tab] == self.bufnr_by_tabid[tab]) and "" or "MISMATCH")
|
||||
end
|
||||
--- END multi-instance FF
|
||||
|
||||
-- reset both bufnr registries
|
||||
globals.BUFNR_BY_TABID[tab] = nil
|
||||
self.bufnr_by_tabid[tab] = nil
|
||||
|
||||
globals.WINID_BY_TABID[tab] = nil
|
||||
end
|
||||
|
||||
function View:abandon_all_windows()
|
||||
for tab, _ in pairs(vim.api.nvim_list_tabpages()) do
|
||||
globals.BUFNR_BY_TABID[tab] = nil
|
||||
globals.WINID_BY_TABID[tab] = nil
|
||||
end
|
||||
end
|
||||
|
||||
---@param opts table|nil
|
||||
---@param callsite string
|
||||
---@return boolean
|
||||
function View:is_visible(opts, callsite)
|
||||
local msg
|
||||
|
||||
--- BEGIN multi-instance FF
|
||||
if self.explorer.opts.experimental.multi_instance then
|
||||
msg = string.format("View:is_visible(%s, %-20.20s)", vim.inspect(opts, { newline = "" }), callsite)
|
||||
end
|
||||
--- END multi-instance FF
|
||||
|
||||
if opts and opts.tabpage then
|
||||
--- BEGIN multi-instance FF
|
||||
if self.explorer.opts.experimental.multi_instance then
|
||||
local winid = self:winid(opts.tabpage)
|
||||
local winid_by_tabid = opts.tabpage and globals.WINID_BY_TABID[opts.tabpage] or nil
|
||||
msg = string.format("%s globals.WINID_BY_TABID[%s]=w%s view.winid(%s)=w%s",
|
||||
msg,
|
||||
opts.tabpage, winid_by_tabid,
|
||||
opts.tabpage, winid
|
||||
)
|
||||
if winid ~= winid_by_tabid then
|
||||
msg = string.format("%s MISMATCH", msg)
|
||||
notify.error(msg)
|
||||
end
|
||||
log.line("dev", "%s", msg)
|
||||
|
||||
return winid and vim.api.nvim_win_is_valid(winid) or false
|
||||
--- END multi-instance FF
|
||||
else
|
||||
local winid = globals.WINID_BY_TABID[opts.tabpage]
|
||||
return winid and vim.api.nvim_win_is_valid(winid)
|
||||
end
|
||||
end
|
||||
|
||||
if opts and opts.any_tabpage then
|
||||
for tabid, winid_by_tabid in pairs(globals.WINID_BY_TABID) do
|
||||
--- BEGIN multi-instance FF
|
||||
if self.explorer.opts.experimental.multi_instance then
|
||||
local winid = self:winid(tabid)
|
||||
msg = string.format("%s globals.WINID_BY_TABID[%s]=w%s view.winid(%s)=w%s",
|
||||
msg,
|
||||
tabid, winid_by_tabid,
|
||||
tabid, winid
|
||||
)
|
||||
if winid ~= winid_by_tabid then
|
||||
msg = string.format("%s MISMATCH", msg)
|
||||
notify.error(msg)
|
||||
end
|
||||
log.line("dev", "%s", msg)
|
||||
|
||||
if winid and vim.api.nvim_win_is_valid(winid) then
|
||||
return true
|
||||
end
|
||||
--- END multi-instance FF
|
||||
else
|
||||
if winid_by_tabid and vim.api.nvim_win_is_valid(winid_by_tabid) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local winid = self:get_winid(nil, "View:is_visible")
|
||||
return winid ~= nil and vim.api.nvim_win_is_valid(winid or 0)
|
||||
end
|
||||
|
||||
---@param opts table|nil
|
||||
function View:set_cursor(opts)
|
||||
if self:is_visible(nil, "View:set_cursor") then
|
||||
pcall(vim.api.nvim_win_set_cursor, self:get_winid(nil, "View:set_cursor"), opts)
|
||||
end
|
||||
end
|
||||
|
||||
---@param winid number|nil
|
||||
---@param open_if_closed boolean|nil
|
||||
function View:focus(winid, open_if_closed)
|
||||
local wid = winid or self:get_winid(nil, "View:focus1")
|
||||
|
||||
if vim.api.nvim_win_get_tabpage(wid or 0) ~= vim.api.nvim_win_get_tabpage(0) then
|
||||
self:close(nil, "View:focus")
|
||||
self:open()
|
||||
wid = self:get_winid(nil, "View:focus2")
|
||||
elseif open_if_closed and not self:is_visible(nil, "View:focus") then
|
||||
self:open()
|
||||
end
|
||||
|
||||
if wid then
|
||||
vim.api.nvim_set_current_win(wid)
|
||||
end
|
||||
end
|
||||
|
||||
--- Retrieve the winid of the open tree.
|
||||
---@param opts ApiTreeWinIdOpts|nil
|
||||
---@return number|nil winid unlike get_winid(), this returns nil if the nvim-tree window is not visible
|
||||
function View:api_winid(opts)
|
||||
local tabpage = opts and opts.tabpage
|
||||
if tabpage == 0 then
|
||||
tabpage = vim.api.nvim_get_current_tabpage()
|
||||
end
|
||||
if self:is_visible({ tabpage = tabpage }, "View:api_winid") then
|
||||
return self:get_winid(tabpage, "View:winid")
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
---restore any state from last close
|
||||
function View:restore_state()
|
||||
self:set_cursor(self.cursors_by_tabid[vim.api.nvim_get_current_tabpage()])
|
||||
end
|
||||
|
||||
--- winid containing the buffer
|
||||
---@param tabid number|nil (optional) the number of the chosen tabpage. Defaults to current tabpage.
|
||||
---@return integer? winid
|
||||
function View:winid(tabid)
|
||||
local bufnr = self.bufnr_by_tabid[tabid]
|
||||
|
||||
if bufnr then
|
||||
for _, winid in pairs(vim.api.nvim_tabpage_list_wins(tabid or 0)) do
|
||||
if vim.api.nvim_win_get_buf(winid) == bufnr then
|
||||
return winid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Returns the window number for nvim-tree within the tabpage specified
|
||||
---@param tabid number|nil (optional) the number of the chosen tabpage. Defaults to current tabpage.
|
||||
---@param callsite string
|
||||
---@return number|nil
|
||||
function View:get_winid(tabid, callsite)
|
||||
local tabid_param = tabid
|
||||
tabid = tabid or vim.api.nvim_get_current_tabpage()
|
||||
local global_winid = nil
|
||||
|
||||
--- BEGIN multi-instance FF
|
||||
if self.explorer.opts.experimental.multi_instance then
|
||||
local msg_fault = ""
|
||||
if not globals.WINID_BY_TABID[tabid] then
|
||||
msg_fault = "no WINID_BY_TABID"
|
||||
elseif not vim.api.nvim_win_is_valid(globals.WINID_BY_TABID[tabid]) then
|
||||
msg_fault = string.format("invalid globals.WINID_BY_TABID[tabid] %d", globals.WINID_BY_TABID[tabid])
|
||||
else
|
||||
global_winid = globals.WINID_BY_TABID[tabid]
|
||||
end
|
||||
|
||||
local winid = self:winid(tabid)
|
||||
|
||||
if winid ~= global_winid then
|
||||
msg_fault = "MISMATCH"
|
||||
end
|
||||
|
||||
local msg = string.format("View:get_winid(%3s, %-20.20s) globals.WINID_BY_TABID[%s]=w%s view.winid(%s)=w%s %s",
|
||||
tabid_param,
|
||||
callsite,
|
||||
tabid, global_winid,
|
||||
tabid, winid,
|
||||
msg_fault
|
||||
)
|
||||
|
||||
log.line("dev", "%s", msg)
|
||||
|
||||
if winid ~= global_winid then
|
||||
notify.error(msg)
|
||||
end
|
||||
|
||||
return winid
|
||||
end
|
||||
--- END multi-instance FF
|
||||
|
||||
-- legacy codepath
|
||||
if global_winid and vim.api.nvim_win_is_valid(global_winid) then
|
||||
return global_winid
|
||||
end
|
||||
end
|
||||
|
||||
--- Returns the current nvim tree bufnr
|
||||
---@param callsite string
|
||||
---@return number
|
||||
function View:get_bufnr(callsite)
|
||||
local tab = vim.api.nvim_get_current_tabpage()
|
||||
|
||||
--- BEGIN multi-instance FF
|
||||
if self.explorer.opts.experimental.multi_instance then
|
||||
local msg = string.format("View:get_bufnr(%-20.20s) globals.BUFNR_BY_TABID[%s]=b%s view.bufnr_by_tab[%s]=b%s %s",
|
||||
callsite,
|
||||
tab, globals.BUFNR_BY_TABID[tab],
|
||||
tab, self.bufnr_by_tabid[tab],
|
||||
(globals.BUFNR_BY_TABID[tab] == self.bufnr_by_tabid[tab]) and "" or "MISMATCH"
|
||||
)
|
||||
|
||||
if globals.BUFNR_BY_TABID[tab] ~= self.bufnr_by_tabid[tab] then
|
||||
notify.error(msg)
|
||||
end
|
||||
|
||||
log.line("dev", msg)
|
||||
|
||||
return self.bufnr_by_tabid[tab]
|
||||
end
|
||||
--- END multi-instance FF
|
||||
|
||||
return globals.BUFNR_BY_TABID[tab]
|
||||
end
|
||||
|
||||
function View:prevent_buffer_override()
|
||||
local view_winid = self:get_winid(nil, "View:prevent_buffer_override")
|
||||
local view_bufnr = self:get_bufnr("View:prevent_buffer_override")
|
||||
|
||||
-- need to schedule to let the new buffer populate the window
|
||||
-- because this event needs to be run on bufWipeout.
|
||||
-- Otherwise the curwin/curbuf would match the view buffer and the view window.
|
||||
vim.schedule(function()
|
||||
local curwin = vim.api.nvim_get_current_win()
|
||||
local curwinconfig = vim.api.nvim_win_get_config(curwin)
|
||||
local curbuf = vim.api.nvim_win_get_buf(curwin)
|
||||
local bufname = vim.api.nvim_buf_get_name(curbuf)
|
||||
|
||||
if not bufname:match("NvimTree") then
|
||||
for i, winid in ipairs(globals.WINID_BY_TABID) do
|
||||
if winid == view_winid then
|
||||
globals.WINID_BY_TABID[i] = nil
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if curwin ~= view_winid or bufname == "" or curbuf == view_bufnr then
|
||||
return
|
||||
end
|
||||
|
||||
-- patch to avoid the overriding window to be fixed in size
|
||||
-- might need a better patch
|
||||
vim.cmd("setlocal nowinfixwidth")
|
||||
vim.cmd("setlocal nowinfixheight")
|
||||
self:open({ focus_tree = false })
|
||||
|
||||
local explorer = require("nvim-tree.core").get_explorer()
|
||||
if explorer then
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
|
||||
pcall(vim.api.nvim_win_close, curwin, { force = true })
|
||||
|
||||
-- to handle opening a file using :e when nvim-tree is on floating mode
|
||||
-- falling back to the current window instead of creating a new one
|
||||
if curwinconfig.relative ~= "" then
|
||||
require("nvim-tree.actions.node.open-file").fn("edit_in_place", bufname)
|
||||
else
|
||||
require("nvim-tree.actions.node.open-file").fn("edit", bufname)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
---@param cwd string|nil
|
||||
---@return boolean
|
||||
function View:is_root_folder_visible(cwd)
|
||||
return cwd ~= "/" and self.explorer.opts.renderer.root_folder_label ~= false
|
||||
end
|
||||
|
||||
-- used on ColorScheme event
|
||||
function View:reset_winhl()
|
||||
local winid = self:get_winid(nil, "View:reset_winhl")
|
||||
if winid and vim.api.nvim_win_is_valid(winid) then
|
||||
vim.wo[winid].winhl = appearance.WIN_HL
|
||||
end
|
||||
end
|
||||
|
||||
---Check if width determined or calculated on-fly
|
||||
---@return boolean
|
||||
function View:is_width_determined()
|
||||
return type(self.width) ~= "function"
|
||||
end
|
||||
|
||||
-- These are needed as they are populated only by the user, not configuration
|
||||
local DEFAULT_MIN_WIDTH = 30
|
||||
local DEFAULT_MAX_WIDTH = -1
|
||||
local DEFAULT_PADDING = 1
|
||||
|
||||
---Configure width-related config
|
||||
---@param width string|function|number|table|nil
|
||||
function View:configure_width(width)
|
||||
if type(width) == "table" then
|
||||
self.adaptive_size = true
|
||||
self.width = width.min or DEFAULT_MIN_WIDTH
|
||||
self.max_width = width.max or DEFAULT_MAX_WIDTH
|
||||
self.padding = width.padding or DEFAULT_PADDING
|
||||
elseif width == nil then
|
||||
if self.explorer.opts.view.width ~= nil then
|
||||
-- if we had input config - fallback to it
|
||||
self:configure_width(self.explorer.opts.view.width)
|
||||
else
|
||||
-- otherwise - restore initial width
|
||||
self.width = self.initial_width
|
||||
end
|
||||
else
|
||||
self.adaptive_size = false
|
||||
self.width = width
|
||||
end
|
||||
end
|
||||
|
||||
return View
|
||||
@@ -1,10 +0,0 @@
|
||||
-- global state, to be refactored away during multi-instance
|
||||
|
||||
local M = {
|
||||
-- from View
|
||||
WINID_BY_TABID = {},
|
||||
BUFNR_BY_TABID = {},
|
||||
CURSORS = {},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -1,4 +1,3 @@
|
||||
local appearance = require("nvim-tree.appearance")
|
||||
local keymap = require("nvim-tree.keymap")
|
||||
local api = {} -- circular dependency
|
||||
|
||||
@@ -6,6 +5,12 @@ local PAT_MOUSE = "^<.*Mouse"
|
||||
local PAT_CTRL = "^<C%-"
|
||||
local PAT_SPECIAL = "^<.+"
|
||||
|
||||
local WIN_HL = table.concat({
|
||||
"NormalFloat:NvimTreeNormalFloat",
|
||||
"WinSeparator:NvimTreeWinSeparator",
|
||||
"CursorLine:NvimTreeCursorLine",
|
||||
}, ",")
|
||||
|
||||
local namespace_help_id = vim.api.nvim_create_namespace("NvimTreeHelp")
|
||||
|
||||
local M = {
|
||||
@@ -185,7 +190,7 @@ local function open()
|
||||
|
||||
-- highlight it
|
||||
for _, args in ipairs(hl_range_args) do
|
||||
if vim.fn.has("nvim-0.11") == 1 and vim.hl and vim.hl.range then
|
||||
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
|
||||
@@ -205,7 +210,7 @@ local function open()
|
||||
})
|
||||
|
||||
-- style it a bit like the tree
|
||||
vim.wo[M.winnr].winhl = appearance.WIN_HL_HELP
|
||||
vim.wo[M.winnr].winhl = WIN_HL
|
||||
vim.wo[M.winnr].cursorline = M.config.cursorline
|
||||
|
||||
local function toggle_sort()
|
||||
|
||||
@@ -48,7 +48,7 @@ function NodeIterator:recursor(f)
|
||||
end
|
||||
|
||||
---@return Node|nil
|
||||
---@return number
|
||||
---@return number|nil
|
||||
function NodeIterator:iterate()
|
||||
local iteration_count = 0
|
||||
local function iter(nodes)
|
||||
|
||||
@@ -96,7 +96,7 @@ function M.default_on_attach(bufnr)
|
||||
vim.keymap.set("n", "S", api.tree.search_node, opts("Search"))
|
||||
vim.keymap.set("n", "u", api.fs.rename_full, opts("Rename: Full Path"))
|
||||
vim.keymap.set("n", "U", api.tree.toggle_custom_filter, opts("Toggle Filter: Hidden"))
|
||||
vim.keymap.set("n", "W", api.tree.collapse_all, opts("Collapse All"))
|
||||
vim.keymap.set("n", "W", api.tree.collapse_all, opts("Collapse"))
|
||||
vim.keymap.set("n", "x", api.fs.cut, opts("Cut"))
|
||||
vim.keymap.set("n", "y", api.fs.copy.filename, opts("Copy Name"))
|
||||
vim.keymap.set("n", "Y", api.fs.copy.relative_path, opts("Copy Relative Path"))
|
||||
|
||||
@@ -60,13 +60,6 @@ local function refactored(opts)
|
||||
end
|
||||
end
|
||||
utils.move_missing_val(opts, "update_focused_file", "ignore_list", opts, "update_focused_file.update_root", "ignore_list", true)
|
||||
|
||||
-- 2025/04/30
|
||||
if opts.renderer and opts.renderer.icons and type(opts.renderer.icons.padding) == "string" then
|
||||
local icons_padding = opts.renderer.icons.padding
|
||||
opts.renderer.icons.padding = {}
|
||||
opts.renderer.icons.padding.icon = icons_padding
|
||||
end
|
||||
end
|
||||
|
||||
local function deprecated(opts)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
local view = require("nvim-tree.view")
|
||||
local core = require("nvim-tree.core")
|
||||
local events = require("nvim-tree.events")
|
||||
local notify = require("nvim-tree.notify")
|
||||
|
||||
---@class LibOpenOpts
|
||||
@@ -11,11 +13,9 @@ local M = {
|
||||
}
|
||||
|
||||
function M.set_target_win()
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
local id = vim.api.nvim_get_current_win()
|
||||
|
||||
if explorer and id == explorer.view:get_winid(nil, "lib.set_target_win") then
|
||||
local tree_id = view.get_winnr()
|
||||
if tree_id and id == tree_id then
|
||||
M.target_winid = 0
|
||||
return
|
||||
end
|
||||
@@ -31,16 +31,11 @@ local function handle_buf_cwd(cwd)
|
||||
end
|
||||
|
||||
local function open_view_and_draw()
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
local cwd = vim.fn.getcwd()
|
||||
|
||||
if explorer then
|
||||
explorer.view:open()
|
||||
end
|
||||
|
||||
view.open()
|
||||
handle_buf_cwd(cwd)
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
if explorer then
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
@@ -102,42 +97,40 @@ function M.open(opts)
|
||||
M.set_target_win()
|
||||
if not core.get_explorer() or opts.path then
|
||||
if opts.path then
|
||||
core.init(opts.path, "lib.open - opts.path")
|
||||
core.init(opts.path)
|
||||
else
|
||||
local cwd, err = vim.loop.cwd()
|
||||
if not cwd then
|
||||
notify.error(string.format("current working directory unavailable: %s", err))
|
||||
return
|
||||
end
|
||||
core.init(cwd, "lib.open - cwd")
|
||||
core.init(cwd)
|
||||
end
|
||||
end
|
||||
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
if should_hijack_current_buf() then
|
||||
view.close_this_tab_only()
|
||||
view.open_in_win()
|
||||
if explorer then
|
||||
explorer.view:close_this_tab_only()
|
||||
explorer.view:open_in_win()
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
elseif opts.winid then
|
||||
view.open_in_win({ hijack_current_buf = false, resize = false, winid = opts.winid })
|
||||
if explorer then
|
||||
explorer.view:open_in_win({ hijack_current_buf = false, resize = false, winid = opts.winid })
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
elseif opts.current_window then
|
||||
view.open_in_win({ hijack_current_buf = false, resize = false })
|
||||
if explorer then
|
||||
explorer.view:open_in_win({ hijack_current_buf = false, resize = false })
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
else
|
||||
open_view_and_draw()
|
||||
end
|
||||
|
||||
if explorer then
|
||||
explorer.view:restore_state()
|
||||
end
|
||||
view.restore_tab_state()
|
||||
events._dispatch_on_tree_open()
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
|
||||
@@ -25,17 +25,11 @@ local Marks = Class:extend()
|
||||
---@protected
|
||||
---@param args MarksArgs
|
||||
function Marks:new(args)
|
||||
args.explorer:log_new("Marks")
|
||||
|
||||
self.explorer = args.explorer
|
||||
|
||||
self.marks = {}
|
||||
end
|
||||
|
||||
function Marks:destroy()
|
||||
self.explorer:log_destroy("Marks")
|
||||
end
|
||||
|
||||
---Clear all marks and reload if watchers disabled
|
||||
---@private
|
||||
function Marks:clear_reload()
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
local globals = require("nvim-tree.globals")
|
||||
|
||||
local M = {}
|
||||
|
||||
--- Debugging only.
|
||||
--- Tabs show WINID_BY_TABID winid and BUFNR_BY_TABID bufnr for the tab.
|
||||
--- Orphans for inexistent tab_ids are shown at the right.
|
||||
--- lib.target_winid is always shown at the right next to a close button.
|
||||
--- Enable with:
|
||||
--- vim.opt.tabline = "%!v:lua.require('nvim-tree.explorer.view').tab_line()"
|
||||
--- vim.opt.showtabline = 2
|
||||
---@return string
|
||||
function M.tab_line()
|
||||
local tabids = vim.api.nvim_list_tabpages()
|
||||
local tabid_cur = vim.api.nvim_get_current_tabpage()
|
||||
|
||||
local bufnr_by_tabid = vim.deepcopy(globals.BUFNR_BY_TABID)
|
||||
local winid_by_tabid = vim.deepcopy(globals.WINID_BY_TABID)
|
||||
|
||||
local tl = "%#TabLine#"
|
||||
|
||||
for i, tabid in ipairs(tabids) do
|
||||
-- click to select
|
||||
tl = tl .. "%" .. i .. "T"
|
||||
|
||||
-- style
|
||||
if tabid == tabid_cur then
|
||||
tl = tl .. "%#StatusLine#|"
|
||||
else
|
||||
tl = tl .. "|%#TabLine#"
|
||||
end
|
||||
|
||||
-- tab_id itself
|
||||
tl = tl .. " t" .. tabid
|
||||
|
||||
-- winid, if present
|
||||
local tp = globals.WINID_BY_TABID[tabid]
|
||||
if tp then
|
||||
tl = tl .. " w" .. (tp or "nil")
|
||||
else
|
||||
tl = tl .. " "
|
||||
end
|
||||
|
||||
-- bufnr, if present
|
||||
local bpt = globals.BUFNR_BY_TABID[tabid]
|
||||
if bpt then
|
||||
tl = tl .. " b" .. bpt
|
||||
else
|
||||
tl = tl .. " "
|
||||
end
|
||||
|
||||
tl = tl .. " "
|
||||
|
||||
-- remove actively mapped
|
||||
bufnr_by_tabid[tabid] = nil
|
||||
winid_by_tabid[tabid] = nil
|
||||
end
|
||||
|
||||
-- close last and reset
|
||||
tl = tl .. "|%#CursorLine#%T"
|
||||
|
||||
-- collect orphans
|
||||
local orphans = {}
|
||||
for tab_id, bufnr in pairs(bufnr_by_tabid) do
|
||||
orphans[tab_id] = orphans[tab_id] or {}
|
||||
orphans[tab_id].bufnr = bufnr
|
||||
end
|
||||
for tab_id, tp in pairs(winid_by_tabid) do
|
||||
orphans[tab_id] = orphans[tab_id] or {}
|
||||
orphans[tab_id].winid = tp
|
||||
end
|
||||
|
||||
-- right-align
|
||||
tl = tl .. "%=%#TabLine#"
|
||||
|
||||
-- print orphans
|
||||
for tab_id, orphan in pairs(orphans) do
|
||||
-- inexistent tab
|
||||
tl = tl .. "%#error#| t" .. tab_id
|
||||
|
||||
-- maybe winid
|
||||
if orphan.winid then
|
||||
tl = tl .. " w" .. (orphan.winid or "nil")
|
||||
else
|
||||
tl = tl .. " "
|
||||
end
|
||||
|
||||
-- maybe bufnr
|
||||
if orphan.bufnr then
|
||||
tl = tl .. " b" .. orphan.bufnr
|
||||
else
|
||||
tl = tl .. " "
|
||||
end
|
||||
tl = tl .. " "
|
||||
end
|
||||
|
||||
-- target win id and close button
|
||||
tl = tl .. "|%#TabLine# twi" .. (require("nvim-tree.lib").target_winid or "?") .. " %999X| X |"
|
||||
|
||||
return tl
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
if not opts.experimental.multi_instance then
|
||||
return
|
||||
end
|
||||
|
||||
vim.opt.tabline = "%!v:lua.require('nvim-tree.multi-instance-debug').tab_line()"
|
||||
vim.opt.showtabline = 2
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,5 +1,6 @@
|
||||
local notify = require("nvim-tree.notify")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local view = require("nvim-tree.view")
|
||||
|
||||
local Class = require("nvim-tree.classic")
|
||||
|
||||
@@ -134,12 +135,12 @@ end
|
||||
function Builder:format_line(indent_markers, arrows, icon, name, node)
|
||||
local added_len = 0
|
||||
local function add_to_end(t1, t2)
|
||||
if not t2 or vim.tbl_isempty(t2) then
|
||||
if not t2 then
|
||||
return
|
||||
end
|
||||
for _, v in ipairs(t2) do
|
||||
if added_len > 0 then
|
||||
table.insert(t1, { str = self.explorer.opts.renderer.icons.padding.icon })
|
||||
table.insert(t1, { str = self.explorer.opts.renderer.icons.padding })
|
||||
end
|
||||
table.insert(t1, v)
|
||||
end
|
||||
@@ -378,7 +379,7 @@ end
|
||||
|
||||
---@private
|
||||
function Builder:build_header()
|
||||
if self.explorer.view:is_root_folder_visible(self.explorer.absolute_path) then
|
||||
if view.is_root_folder_visible(self.explorer.absolute_path) then
|
||||
local root_name = self:format_root_name(self.explorer.opts.renderer.root_folder_label)
|
||||
table.insert(self.lines, root_name)
|
||||
self:insert_highlight({ "NvimTreeRootFolder" }, 0, string.len(root_name))
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
local appearance = require("nvim-tree.appearance")
|
||||
local utils = require("nvim-tree.utils")
|
||||
|
||||
local M = {}
|
||||
|
||||
local utils = require("nvim-tree.utils")
|
||||
|
||||
local function hide(win)
|
||||
if win then
|
||||
if vim.api.nvim_win_is_valid(win) then
|
||||
@@ -33,7 +32,7 @@ local function effective_win_width()
|
||||
return win_width - win_info[1].textoff
|
||||
end
|
||||
|
||||
local function show(opts)
|
||||
local function show()
|
||||
local line_nr = vim.api.nvim_win_get_cursor(0)[1]
|
||||
if vim.wo.wrap then
|
||||
return
|
||||
@@ -53,11 +52,6 @@ local function show(opts)
|
||||
local text_width = vim.fn.strdisplaywidth(vim.fn.substitute(line, "[^[:print:]]*$", "", "g"))
|
||||
local win_width = effective_win_width()
|
||||
|
||||
-- windows width reduced by right aligned icons
|
||||
local icon_ns_id = vim.api.nvim_get_namespaces()["NvimTreeExtmarks"]
|
||||
local icon_extmarks = vim.api.nvim_buf_get_extmarks(0, icon_ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = true })
|
||||
win_width = win_width - utils.extmarks_length(icon_extmarks)
|
||||
|
||||
if text_width < win_width then
|
||||
return
|
||||
end
|
||||
@@ -70,9 +64,7 @@ local function show(opts)
|
||||
height = 1,
|
||||
noautocmd = true,
|
||||
style = "minimal",
|
||||
border = "none"
|
||||
})
|
||||
vim.wo[M.popup_win].winhl = appearance.WIN_HL
|
||||
|
||||
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 })
|
||||
@@ -88,17 +80,14 @@ local function show(opts)
|
||||
local details = extmark[4]
|
||||
|
||||
if type(details) == "table" then
|
||||
if vim.fn.has("nvim-0.11") == 1 and vim.hl and vim.hl.range 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
|
||||
vim.cmd([[ setlocal nowrap noswapfile nobuflisted buftype=nofile bufhidden=wipe ]])
|
||||
if opts.view.cursorline then
|
||||
vim.cmd([[ setlocal cursorline cursorlineopt=both ]])
|
||||
end
|
||||
vim.cmd([[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=wipe ]])
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -124,7 +113,7 @@ M.setup = function(opts)
|
||||
pattern = { "NvimTree_*" },
|
||||
callback = function()
|
||||
if utils.is_nvim_tree_buf(0) then
|
||||
show(opts)
|
||||
show()
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -95,15 +95,15 @@ 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 = M.config.icons.glyphs.folder["arrow_open"] .. " "
|
||||
hl = "NvimTreeFolderArrowOpen"
|
||||
else
|
||||
str = M.config.icons.glyphs.folder["arrow_closed"] .. M.config.icons.padding.folder_arrow
|
||||
str = M.config.icons.glyphs.folder["arrow_closed"] .. " "
|
||||
end
|
||||
elseif M.config.indent_markers.enable then
|
||||
str = ""
|
||||
else
|
||||
str = " " .. string.rep(" ", #M.config.icons.padding.folder_arrow)
|
||||
str = " "
|
||||
end
|
||||
|
||||
return { str = str, hl = { hl } }
|
||||
|
||||
@@ -62,7 +62,7 @@ function GitDecorator:build_icons_by_status(glyphs)
|
||||
self.icons_by_status.ignored = { str = glyphs.ignored, hl = { "NvimTreeGitIgnoredIcon" }, ord = 7 }
|
||||
end
|
||||
|
||||
---@param icons GitIconsByStatus
|
||||
---@param icons GitIconsByXY
|
||||
function GitDecorator:build_icons_by_xy(icons)
|
||||
self.icons_by_xy = {
|
||||
["M "] = { icons.staged },
|
||||
|
||||
@@ -112,8 +112,9 @@ function Decorator:define_sign(icon)
|
||||
vim.fn.sign_undefine(name)
|
||||
end
|
||||
|
||||
-- don't render sign if empty
|
||||
-- don't use sign if not defined
|
||||
if #icon.str < 1 then
|
||||
self.icon_placement = "none"
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local log = require("nvim-tree.log")
|
||||
local view = require("nvim-tree.view")
|
||||
local events = require("nvim-tree.events")
|
||||
|
||||
local Class = require("nvim-tree.classic")
|
||||
@@ -25,15 +26,9 @@ local Renderer = Class:extend()
|
||||
---@protected
|
||||
---@param args RendererArgs
|
||||
function Renderer:new(args)
|
||||
args.explorer:log_new("Renderer")
|
||||
|
||||
self.explorer = args.explorer
|
||||
end
|
||||
|
||||
function Renderer:destroy()
|
||||
self.explorer:log_destroy("Renderer")
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param bufnr number
|
||||
---@param lines string[]
|
||||
@@ -92,7 +87,7 @@ function Renderer:render_hl(bufnr, hl_range_args)
|
||||
end
|
||||
vim.api.nvim_buf_clear_namespace(bufnr, namespace_highlights_id, 0, -1)
|
||||
for _, args in ipairs(hl_range_args) do
|
||||
if vim.fn.has("nvim-0.11") == 1 and vim.hl and vim.hl.range then
|
||||
if vim.fn.has("nvim-0.11") == 1 then
|
||||
vim.hl.range(bufnr, namespace_highlights_id, args.higroup, args.start, args.finish, {})
|
||||
else
|
||||
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
|
||||
@@ -101,29 +96,28 @@ function Renderer:render_hl(bufnr, hl_range_args)
|
||||
end
|
||||
|
||||
function Renderer:draw()
|
||||
local bufnr = self.explorer.view:get_bufnr("Renderer:draw")
|
||||
local bufnr = view.get_bufnr()
|
||||
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||
return
|
||||
end
|
||||
local winid = self.explorer.view:get_winid(nil, "Renderer:draw")
|
||||
|
||||
local profile = log.profile_start("draw")
|
||||
|
||||
local cursor = vim.api.nvim_win_get_cursor(winid or 0)
|
||||
local cursor = vim.api.nvim_win_get_cursor(view.get_winnr() or 0)
|
||||
|
||||
local builder = Builder(self.explorer):build()
|
||||
|
||||
self:_draw(bufnr, builder.lines, builder.hl_range_args, builder.signs, builder.extmarks, builder.virtual_lines)
|
||||
|
||||
if cursor and #builder.lines >= cursor[1] then
|
||||
vim.api.nvim_win_set_cursor(winid or 0, cursor)
|
||||
vim.api.nvim_win_set_cursor(view.get_winnr() or 0, cursor)
|
||||
end
|
||||
|
||||
self.explorer.view:grow_from_content()
|
||||
view.grow_from_content()
|
||||
|
||||
log.profile_end(profile)
|
||||
|
||||
events._dispatch_on_tree_rendered(bufnr, winid)
|
||||
events._dispatch_on_tree_rendered(bufnr, view.get_winnr())
|
||||
end
|
||||
|
||||
return Renderer
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local Iterator = require("nvim-tree.iterators.node-iterator")
|
||||
local notify = require("nvim-tree.notify")
|
||||
|
||||
local M = {
|
||||
debouncers = {},
|
||||
@@ -10,6 +11,10 @@ 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
|
||||
|
||||
function M._is_windows()
|
||||
return vim.fn.has("win32") == 1 or vim.fn.has("win32unix") == 1
|
||||
end
|
||||
|
||||
---@param haystack string
|
||||
---@param needle string
|
||||
---@return boolean
|
||||
@@ -143,16 +148,10 @@ function M.find_node(nodes, fn)
|
||||
return node.group_next and { node.group_next } or (node.open and #node.nodes > 0 and node.nodes)
|
||||
end)
|
||||
:iterate()
|
||||
|
||||
if node then
|
||||
if not node.explorer.view:is_root_folder_visible() then
|
||||
i = i - 1
|
||||
end
|
||||
if node.explorer.live_filter.filter then
|
||||
i = require("nvim-tree.view").is_root_folder_visible() and i or i - 1
|
||||
if node and node.explorer.live_filter.filter then
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
return node, i
|
||||
end
|
||||
|
||||
@@ -178,21 +177,6 @@ function M.find_node_line(node)
|
||||
return -1
|
||||
end
|
||||
|
||||
---@param extmarks vim.api.keyset.get_extmark_item[] as per vim.api.nvim_buf_get_extmarks
|
||||
---@return number
|
||||
function M.extmarks_length(extmarks)
|
||||
local length = 0
|
||||
for _, extmark in ipairs(extmarks) do
|
||||
local details = extmark[4]
|
||||
if details and details.virt_text then
|
||||
for _, text in ipairs(details.virt_text) do
|
||||
length = length + vim.fn.strchars(text[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
return length
|
||||
end
|
||||
|
||||
-- get the node in the tree state depending on the absolute path of the node
|
||||
-- (grouped or hidden too)
|
||||
---@param path string
|
||||
@@ -309,57 +293,17 @@ function M.rename_loaded_buffers(old_path, new_path)
|
||||
end
|
||||
end
|
||||
|
||||
local is_windows_drive = function(path)
|
||||
return (M.is_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)
|
||||
return error == nil
|
||||
end
|
||||
|
||||
-- Windows is case-insensetive, but case-preserving
|
||||
-- If a file's name is being changed into itself
|
||||
-- with different casing, windows will falsely
|
||||
-- report that file is already existing, so a hand-rolled
|
||||
-- implementation of checking for existance is needed.
|
||||
-- Same holds for WSL, since it can sometimes
|
||||
-- access Windows files directly.
|
||||
-- For more details see (#3117).
|
||||
|
||||
if is_windows_drive(path) then
|
||||
return vim.fn.isdirectory(path) == 1
|
||||
end
|
||||
|
||||
local parent = vim.fn.fnamemodify(path, ":h")
|
||||
local filename = vim.fn.fnamemodify(path, ":t")
|
||||
|
||||
local handle = vim.loop.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)
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
if name == filename then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
---@param path string
|
||||
---@return string
|
||||
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)
|
||||
end
|
||||
return path
|
||||
@@ -409,6 +353,20 @@ end
|
||||
---@param dst_pos string value pos
|
||||
---@param remove boolean
|
||||
function M.move_missing_val(src, src_path, src_pos, dst, dst_path, dst_pos, remove)
|
||||
local ok, err = pcall(vim.validate, {
|
||||
src = { src, "table" },
|
||||
src_path = { src_path, "string" },
|
||||
src_pos = { src_pos, "string" },
|
||||
dst = { dst, "table" },
|
||||
dst_path = { dst_path, "string" },
|
||||
dst_pos = { dst_pos, "string" },
|
||||
remove = { remove, "boolean" },
|
||||
})
|
||||
if not ok then
|
||||
notify.warn("move_missing_val: " .. (err or "invalid arguments"))
|
||||
return
|
||||
end
|
||||
|
||||
for pos in string.gmatch(src_path, "([^%.]+)%.*") do
|
||||
if src[pos] and type(src[pos]) == "table" then
|
||||
src = src[pos]
|
||||
@@ -543,10 +501,7 @@ function M.focus_file(path)
|
||||
local _, i = M.find_node(require("nvim-tree.core").get_explorer().nodes, function(node)
|
||||
return node.absolute_path == path
|
||||
end)
|
||||
local explorer = require("nvim-tree.core").get_explorer()
|
||||
if explorer then
|
||||
explorer.view:set_cursor({ i + 1, 1 })
|
||||
end
|
||||
require("nvim-tree.view").set_cursor({ i + 1, 1 })
|
||||
end
|
||||
|
||||
---Focus node passed as parameter if visible, otherwise focus first visible parent.
|
||||
@@ -566,7 +521,7 @@ function M.focus_node_or_parent(node)
|
||||
end)
|
||||
|
||||
if found_node or node.parent == nil then
|
||||
explorer.view:set_cursor({ i + 1, 1 })
|
||||
require("nvim-tree.view").set_cursor({ i + 1, 1 })
|
||||
break
|
||||
end
|
||||
|
||||
@@ -661,29 +616,32 @@ function M.is_executable(absolute_path)
|
||||
end
|
||||
end
|
||||
|
||||
---@class UtilEnumerateOptionsOpts
|
||||
---@field keyset_opts vim.api.keyset.option
|
||||
---@field was_set boolean? as per vim.api.keyset.get_option_info
|
||||
---List of all option info/values
|
||||
---@param opts vim.api.keyset.option passed directly to vim.api.nvim_get_option_info2 and vim.api.nvim_get_option_value
|
||||
---@param was_set boolean filter was_set
|
||||
---@return { info: vim.api.keyset.get_option_info, val: any }[]
|
||||
function M.enumerate_options(opts, was_set)
|
||||
local res = {}
|
||||
|
||||
---Option name/values
|
||||
---@param opts UtilEnumerateOptionsOpts
|
||||
---@return table<string, any>
|
||||
function M.enumerate_options(opts)
|
||||
-- enumerate all options, limiting buf and win scopes
|
||||
return vim.tbl_map(function(info)
|
||||
if opts.keyset_opts.buf and info.scope ~= "buf" then
|
||||
return nil
|
||||
elseif opts.keyset_opts.win and info.scope ~= "win" then
|
||||
return nil
|
||||
local infos = vim.tbl_filter(function(info)
|
||||
if opts.buf and info.scope ~= "buf" then
|
||||
return false
|
||||
elseif opts.win and info.scope ~= "win" then
|
||||
return false
|
||||
else
|
||||
-- optional, lazy was_set check
|
||||
if not opts.was_set or vim.api.nvim_get_option_info2(info.name, opts.keyset_opts).was_set then
|
||||
return vim.api.nvim_get_option_value(info.name, opts.keyset_opts)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
return true
|
||||
end
|
||||
end, vim.api.nvim_get_all_options_info())
|
||||
|
||||
for _, info in vim.spairs(infos) do
|
||||
local _, info2 = pcall(vim.api.nvim_get_option_info2, info.name, opts)
|
||||
if not was_set or info2.was_set then
|
||||
local val = pcall(vim.api.nvim_get_option_value, info.name, opts)
|
||||
table.insert(res, { info = info2, val = val })
|
||||
end
|
||||
end
|
||||
|
||||
return res
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
641
lua/nvim-tree/view.lua
Normal file
641
lua/nvim-tree/view.lua
Normal file
@@ -0,0 +1,641 @@
|
||||
local events = require("nvim-tree.events")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local log = require("nvim-tree.log")
|
||||
local notify = require("nvim-tree.notify")
|
||||
|
||||
---@class OpenInWinOpts
|
||||
---@field hijack_current_buf boolean|nil default true
|
||||
---@field resize boolean|nil default true
|
||||
---@field winid number|nil 0 or nil for current
|
||||
|
||||
local M = {}
|
||||
|
||||
local DEFAULT_MIN_WIDTH = 30
|
||||
local DEFAULT_MAX_WIDTH = -1
|
||||
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 }
|
||||
cursor = { 0, 0 },
|
||||
-- The NvimTree window number
|
||||
winnr = nil,
|
||||
}
|
||||
|
||||
local BUFNR_PER_TAB = {}
|
||||
|
||||
---@type { name: string, value: any }[]
|
||||
local BUFFER_OPTIONS = {
|
||||
{ name = "bufhidden", value = "wipe" },
|
||||
{ name = "buflisted", value = false },
|
||||
{ name = "buftype", value = "nofile" },
|
||||
{ name = "filetype", value = "NvimTree" },
|
||||
{ name = "modifiable", value = false },
|
||||
{ name = "swapfile", value = false },
|
||||
}
|
||||
|
||||
---@param bufnr integer
|
||||
---@return boolean
|
||||
local function matches_bufnr(bufnr)
|
||||
for _, b in pairs(BUFNR_PER_TAB) do
|
||||
if b == bufnr then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function wipe_rogue_buffer()
|
||||
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if not matches_bufnr(bufnr) and utils.is_nvim_tree_buf(bufnr) then
|
||||
pcall(vim.api.nvim_buf_delete, bufnr, { force = true })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param bufnr integer|boolean|nil
|
||||
local function create_buffer(bufnr)
|
||||
wipe_rogue_buffer()
|
||||
|
||||
local tab = vim.api.nvim_get_current_tabpage()
|
||||
BUFNR_PER_TAB[tab] = bufnr or vim.api.nvim_create_buf(false, false)
|
||||
vim.api.nvim_buf_set_name(M.get_bufnr(), "NvimTree_" .. tab)
|
||||
|
||||
bufnr = M.get_bufnr()
|
||||
for _, option in ipairs(BUFFER_OPTIONS) do
|
||||
vim.api.nvim_set_option_value(option.name, option.value, { buf = bufnr })
|
||||
end
|
||||
|
||||
require("nvim-tree.keymap").on_attach(M.get_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",
|
||||
}
|
||||
|
||||
-- setup_tabpage sets up the initial state of a tab
|
||||
---@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 })
|
||||
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", {})
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
---@return table
|
||||
local function open_win_config()
|
||||
if type(M.View.float.open_win_config) == "function" then
|
||||
return M.View.float.open_win_config()
|
||||
else
|
||||
return M.View.float.open_win_config
|
||||
end
|
||||
end
|
||||
|
||||
local function open_window()
|
||||
if M.View.float.enable then
|
||||
vim.api.nvim_open_win(0, true, open_win_config())
|
||||
else
|
||||
vim.api.nvim_command("vsp")
|
||||
M.reposition_window()
|
||||
end
|
||||
setup_tabpage(vim.api.nvim_get_current_tabpage())
|
||||
set_window_options_and_buffer()
|
||||
end
|
||||
|
||||
---@param buf integer
|
||||
---@return boolean
|
||||
local function is_buf_displayed(buf)
|
||||
return vim.api.nvim_buf_is_valid(buf) and vim.fn.buflisted(buf) == 1
|
||||
end
|
||||
|
||||
---@return number|nil
|
||||
local function get_alt_or_next_buf()
|
||||
local alt_buf = vim.fn.bufnr("#")
|
||||
if is_buf_displayed(alt_buf) then
|
||||
return alt_buf
|
||||
end
|
||||
|
||||
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if is_buf_displayed(buf) then
|
||||
return buf
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function switch_buf_if_last_buf()
|
||||
if #vim.api.nvim_list_wins() == 1 then
|
||||
local buf = get_alt_or_next_buf()
|
||||
if buf then
|
||||
vim.cmd("sb" .. buf)
|
||||
else
|
||||
vim.cmd("new")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- save_tab_state saves any state that should be preserved across redraws.
|
||||
---@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)
|
||||
end
|
||||
|
||||
---@param tabpage integer
|
||||
local function close(tabpage)
|
||||
if not M.is_visible({ tabpage = tabpage }) then
|
||||
return
|
||||
end
|
||||
save_tab_state(tabpage)
|
||||
switch_buf_if_last_buf()
|
||||
local tree_win = M.get_winnr(tabpage)
|
||||
local current_win = vim.api.nvim_get_current_win()
|
||||
for _, win in pairs(vim.api.nvim_tabpage_list_wins(tabpage)) do
|
||||
if vim.api.nvim_win_get_config(win).relative == "" then
|
||||
local prev_win = vim.fn.winnr("#") -- this tab only
|
||||
if tree_win == current_win and prev_win > 0 then
|
||||
vim.api.nvim_set_current_win(vim.fn.win_getid(prev_win))
|
||||
end
|
||||
if vim.api.nvim_win_is_valid(tree_win or 0) then
|
||||
local success, error = pcall(vim.api.nvim_win_close, tree_win or 0, true)
|
||||
if not success then
|
||||
notify.debug("Failed to close window: " .. error)
|
||||
return
|
||||
end
|
||||
end
|
||||
events._dispatch_on_tree_close()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.close_this_tab_only()
|
||||
close(vim.api.nvim_get_current_tabpage())
|
||||
end
|
||||
|
||||
function M.close_all_tabs()
|
||||
for tabpage, _ in pairs(M.View.tabpages) do
|
||||
close(tabpage)
|
||||
end
|
||||
end
|
||||
|
||||
function M.close()
|
||||
if M.View.tab.sync.close then
|
||||
M.close_all_tabs()
|
||||
else
|
||||
M.close_this_tab_only()
|
||||
end
|
||||
end
|
||||
|
||||
---@param options table|nil
|
||||
function M.open(options)
|
||||
if M.is_visible() then
|
||||
return
|
||||
end
|
||||
|
||||
local profile = log.profile_start("view open")
|
||||
|
||||
create_buffer()
|
||||
open_window()
|
||||
M.resize()
|
||||
|
||||
local opts = options or { focus_tree = true }
|
||||
if not opts.focus_tree then
|
||||
vim.cmd("wincmd p")
|
||||
end
|
||||
events._dispatch_on_tree_open()
|
||||
|
||||
log.profile_end(profile)
|
||||
end
|
||||
|
||||
local function grow()
|
||||
local starts_at = M.is_root_folder_visible(require("nvim-tree.core").get_cwd()) 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)
|
||||
|
||||
-- account for sign/number columns etc.
|
||||
local wininfo = vim.fn.getwininfo(M.get_winnr())
|
||||
if type(wininfo) == "table" and type(wininfo[1]) == "table" then
|
||||
padding = padding + wininfo[1].textoff
|
||||
end
|
||||
|
||||
local resizing_width = M.View.initial_width - padding
|
||||
local max_width
|
||||
|
||||
-- maybe bound max
|
||||
if M.View.max_width == -1 then
|
||||
max_width = -1
|
||||
else
|
||||
max_width = get_width(M.View.max_width) - padding
|
||||
end
|
||||
|
||||
local ns_id = vim.api.nvim_get_namespaces()["NvimTreeExtmarks"]
|
||||
for line_nr, l in pairs(lines) do
|
||||
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
|
||||
resizing_width = count
|
||||
end
|
||||
if M.View.adaptive_size and max_width >= 0 and resizing_width >= max_width then
|
||||
resizing_width = max_width
|
||||
break
|
||||
end
|
||||
end
|
||||
M.resize(resizing_width + padding)
|
||||
end
|
||||
|
||||
function M.grow_from_content()
|
||||
if M.View.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 the floating windows's adaptive size is not desired, then the
|
||||
-- float size should be defined in view.float.open_win_config
|
||||
return
|
||||
end
|
||||
|
||||
if type(size) == "string" then
|
||||
size = vim.trim(size)
|
||||
local first_char = size:sub(1, 1)
|
||||
size = tonumber(size)
|
||||
|
||||
if first_char == "+" or first_char == "-" then
|
||||
size = M.View.width + size
|
||||
end
|
||||
end
|
||||
|
||||
if type(size) == "number" and size <= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
if size then
|
||||
M.View.width = size
|
||||
M.View.height = size
|
||||
end
|
||||
|
||||
if not M.is_visible() then
|
||||
return
|
||||
end
|
||||
|
||||
local winnr = M.get_winnr() or 0
|
||||
|
||||
local new_size = 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
|
||||
vim.cmd(":wincmd =")
|
||||
end
|
||||
end
|
||||
|
||||
events._dispatch_on_tree_resize(new_size)
|
||||
end
|
||||
|
||||
function M.reposition_window()
|
||||
local move_to = move_tbl[M.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()
|
||||
end
|
||||
|
||||
---Open the tree in the a window
|
||||
---@param opts OpenInWinOpts|nil
|
||||
function M.open_in_win(opts)
|
||||
opts = opts or { hijack_current_buf = true, resize = true }
|
||||
if opts.winid and vim.api.nvim_win_is_valid(opts.winid) then
|
||||
vim.api.nvim_set_current_win(opts.winid)
|
||||
end
|
||||
create_buffer(opts.hijack_current_buf and vim.api.nvim_get_current_buf())
|
||||
setup_tabpage(vim.api.nvim_get_current_tabpage())
|
||||
set_current_win()
|
||||
set_window_options_and_buffer()
|
||||
if opts.resize then
|
||||
M.reposition_window()
|
||||
M.resize()
|
||||
end
|
||||
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
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param opts table|nil
|
||||
---@return boolean
|
||||
function M.is_visible(opts)
|
||||
if opts and opts.tabpage then
|
||||
if M.View.tabpages[opts.tabpage] == nil then
|
||||
return false
|
||||
end
|
||||
local winnr = M.View.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
|
||||
if v.winnr and vim.api.nvim_win_is_valid(v.winnr) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
return M.get_winnr() ~= nil and vim.api.nvim_win_is_valid(M.get_winnr() or 0)
|
||||
end
|
||||
|
||||
---@param opts table|nil
|
||||
function M.set_cursor(opts)
|
||||
if M.is_visible() then
|
||||
pcall(vim.api.nvim_win_set_cursor, M.get_winnr(), opts)
|
||||
end
|
||||
end
|
||||
|
||||
---@param winnr number|nil
|
||||
---@param open_if_closed boolean|nil
|
||||
function M.focus(winnr, open_if_closed)
|
||||
local wnr = winnr or M.get_winnr()
|
||||
|
||||
if vim.api.nvim_win_get_tabpage(wnr or 0) ~= vim.api.nvim_win_get_tabpage(0) then
|
||||
M.close()
|
||||
M.open()
|
||||
wnr = M.get_winnr()
|
||||
elseif open_if_closed and not M.is_visible() then
|
||||
M.open()
|
||||
end
|
||||
|
||||
if wnr then
|
||||
vim.api.nvim_set_current_win(wnr)
|
||||
end
|
||||
end
|
||||
|
||||
--- Retrieve the winid of the open tree.
|
||||
---@param opts ApiTreeWinIdOpts|nil
|
||||
---@return number|nil winid unlike get_winnr(), this returns nil if the nvim-tree window is not visible
|
||||
function M.winid(opts)
|
||||
local tabpage = opts and opts.tabpage
|
||||
if tabpage == 0 then
|
||||
tabpage = vim.api.nvim_get_current_tabpage()
|
||||
end
|
||||
if M.is_visible({ tabpage = tabpage }) then
|
||||
return M.get_winnr(tabpage)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
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])
|
||||
end
|
||||
|
||||
--- Returns the window number for nvim-tree within the tabpage specified
|
||||
---@param tabpage number|nil (optional) the number of the chosen tabpage. Defaults to current tabpage.
|
||||
---@return number|nil
|
||||
function M.get_winnr(tabpage)
|
||||
tabpage = tabpage or vim.api.nvim_get_current_tabpage()
|
||||
local tabinfo = M.View.tabpages[tabpage]
|
||||
if tabinfo and tabinfo.winnr and vim.api.nvim_win_is_valid(tabinfo.winnr) then
|
||||
return tabinfo.winnr
|
||||
end
|
||||
end
|
||||
|
||||
--- Returns the current nvim tree bufnr
|
||||
---@return number
|
||||
function M.get_bufnr()
|
||||
return BUFNR_PER_TAB[vim.api.nvim_get_current_tabpage()]
|
||||
end
|
||||
|
||||
function M._prevent_buffer_override()
|
||||
local view_winnr = M.get_winnr()
|
||||
local view_bufnr = M.get_bufnr()
|
||||
|
||||
-- need to schedule to let the new buffer populate the window
|
||||
-- because this event needs to be run on bufWipeout.
|
||||
-- Otherwise the curwin/curbuf would match the view buffer and the view window.
|
||||
vim.schedule(function()
|
||||
local curwin = vim.api.nvim_get_current_win()
|
||||
local curwinconfig = vim.api.nvim_win_get_config(curwin)
|
||||
local curbuf = vim.api.nvim_win_get_buf(curwin)
|
||||
local bufname = vim.api.nvim_buf_get_name(curbuf)
|
||||
|
||||
if not bufname:match("NvimTree") then
|
||||
for i, tabpage in ipairs(M.View.tabpages) do
|
||||
if tabpage.winnr == view_winnr then
|
||||
M.View.tabpages[i] = nil
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if curwin ~= view_winnr or bufname == "" or curbuf == view_bufnr then
|
||||
return
|
||||
end
|
||||
|
||||
-- patch to avoid the overriding window to be fixed in size
|
||||
-- might need a better patch
|
||||
vim.cmd("setlocal nowinfixwidth")
|
||||
vim.cmd("setlocal nowinfixheight")
|
||||
M.open({ focus_tree = false })
|
||||
|
||||
local explorer = require("nvim-tree.core").get_explorer()
|
||||
if explorer then
|
||||
explorer.renderer:draw()
|
||||
end
|
||||
|
||||
pcall(vim.api.nvim_win_close, curwin, { force = true })
|
||||
|
||||
-- to handle opening a file using :e when nvim-tree is on floating mode
|
||||
-- falling back to the current window instead of creating a new one
|
||||
if curwinconfig.relative ~= "" then
|
||||
require("nvim-tree.actions.node.open-file").fn("edit_in_place", bufname)
|
||||
else
|
||||
require("nvim-tree.actions.node.open-file").fn("edit", bufname)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
---@param cwd string|nil
|
||||
---@return boolean
|
||||
function M.is_root_folder_visible(cwd)
|
||||
return cwd ~= "/" and not M.View.hide_root_folder
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
---Check if width determined or calculated on-fly
|
||||
---@return boolean
|
||||
function M.is_width_determined()
|
||||
return type(M.View.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
|
||||
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
|
||||
else
|
||||
M.View.adaptive_size = false
|
||||
M.View.width = width
|
||||
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.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,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/bin/bash
|
||||
|
||||
out=$(grep -nr "^--- @" lua)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
#!/bin/sh
|
||||
|
||||
# run after changing nvim-tree.lua DEFAULT_OPTS or keymap.lua M.default_on_attach
|
||||
# scrapes and updates nvim-tree-lua.txt
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#!/usr/bin/env sh
|
||||
#!/bin/sh
|
||||
|
||||
# Performs a lua-language-server check on all files.
|
||||
# luals-out/check.json will be produced on any issues, returning 1.
|
||||
# Outputs only check.json to stdout, all other messages to stderr, to allow jq etc.
|
||||
# $VIMRUNTIME specifies neovim runtime path, defaults to "/usr/share/nvim/runtime" if unset.
|
||||
#
|
||||
# Call with codestyle-check param to enable only codestyle-check
|
||||
|
||||
if [ -z "${VIMRUNTIME}" ]; then
|
||||
export VIMRUNTIME="/usr/share/nvim/runtime"
|
||||
@@ -19,24 +17,11 @@ FILE_LUARC="${DIR_OUT}/luarc.json"
|
||||
rm -rf "${DIR_OUT}"
|
||||
mkdir "${DIR_OUT}"
|
||||
|
||||
case "${1}" in
|
||||
"codestyle-check")
|
||||
jq \
|
||||
'.diagnostics.neededFileStatus[] = "None" | .diagnostics.neededFileStatus."codestyle-check" = "Any"' \
|
||||
"${PWD}/.luarc.json" > "${FILE_LUARC}"
|
||||
# Uncomment runtime.version for strict neovim baseline 5.1
|
||||
# It is not set normally, to prevent luals loading 5.1 and 5.x, resulting in both versions being chosen on vim.lsp.buf.definition()
|
||||
cat "${PWD}/.luarc.json" | sed -E 's/.luals-check-only//g' > "${FILE_LUARC}"
|
||||
|
||||
;;
|
||||
*)
|
||||
# Add runtime.version for strict neovim baseline 5.1
|
||||
# It is not set normally, to prevent luals loading 5.1 and 5.x, resulting in both versions being chosen on vim.lsp.buf.definition
|
||||
jq \
|
||||
'."runtime.version" = "Lua 5.1"' \
|
||||
"${PWD}/.luarc.json" > "${FILE_LUARC}"
|
||||
|
||||
;;
|
||||
esac
|
||||
|
||||
# execute inside lua directory to prevent luals itself from being checked
|
||||
# execute inside lua to prevent luals itself from being checked
|
||||
OUT=$(lua-language-server --check="${DIR_SRC}" --configpath="${FILE_LUARC}" --checklevel=Information --logpath="${DIR_OUT}" --loglevel=error)
|
||||
RC=$?
|
||||
|
||||
|
||||
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