From ad22603c80fe19b6dac9b861ca8eb77b70c394cc Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 17 Feb 2026 12:52:24 +1100 Subject: [PATCH 1/7] chore(#3271): add new format-check, rename style-fix to format-fix --- .github/workflows/ci.yml | 2 ++ CONTRIBUTING.md | 23 +++++++++++++++++++---- Makefile | 10 +++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e32aefbaf3c..401701ccc49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,6 +77,8 @@ jobs: - run: make style-doc + - run: make format-check + - name: build Nvim from source run: | mkdir -p "${DIR_NVIM_SRC}" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 086f807557f..9315b548bec 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,7 +15,9 @@ markdown-toc --maxdepth=2 -i CONTRIBUTING.md - [Quality](#quality) * [lint](#lint) * [style](#style) + * [format-fix](#format-fix) * [check](#check) + * [format-check](#format-check) - [Diagnostics](#diagnostics) - [Backwards Compatibility](#backwards-compatibility) - [:help Documentation](#help-documentation) @@ -36,10 +38,10 @@ Language server: [luals](https://luals.github.io) Lint: [luacheck](https://github.com/lunarmodules/luacheck/) -Style Fixing: [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) +Formatting: [EmmyLuaCodeStyle](https://github.com/CppCXY/EmmyLuaCodeStyle): `CodeFormat` executable + You can install them via you OS package manager e.g. `pacman`, `brew` or other via other package managers such as `cargo` or `luarocks` # Quality @@ -67,10 +69,12 @@ make lint make style ``` -You can automatically fix style issues using `CodeCheck`: +## format-fix + +You can automatically fix most style issues using `CodeFormat`: ```sh -make style-fix +make format-fix ``` ## check @@ -96,6 +100,17 @@ curl -L "https://github.com/LuaLS/lua-language-server/releases/download/3.15.0/l PATH="luals/bin:${PATH}" make check ``` +## format-check + +This is run in CI. Commit or stage your changes and run: + +```sh +make format-check +``` + +- Re-runs `make format-fix` +- Checks that `git diff` is empty, to ensure that all content has been generated. This is why a stage or commit is necessary. + # Diagnostics Diagnostics issues may not be suppressed. See [luals](https://luals.github.io) documentation for details on how to structure the code and comments. diff --git a/Makefile b/Makefile index c6c837f5ab2..6d668cf2b6a 100644 --- a/Makefile +++ b/Makefile @@ -25,11 +25,15 @@ luals: scripts/luals-check.sh # -# fixes +# format # -style-fix: +format-fix: CodeFormat format --config .editorconfig --workspace lua +format-check: + CodeFormat format --config .editorconfig --workspace lua + git diff --exit-code lua + # # utility # @@ -46,5 +50,5 @@ help-check: help-update git diff --ignore-blank-lines --exit-code doc/nvim-tree-lua.txt -.PHONY: all lint style check luacheck style-check style-doc luals style-fix help-update help-check +.PHONY: all lint style check luacheck style-check style-doc luals format-fix format-check help-update help-check From fb08b3b13b1f4a19f7a64aa5f5de01e03d79be1d Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 17 Feb 2026 13:12:52 +1100 Subject: [PATCH 2/7] chore(#3271): CI install CodeFormat from luarocks --- .github/workflows/ci.yml | 4 ++++ Makefile | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 401701ccc49..f15ee073a5c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,7 @@ jobs: matrix: nvim_version: [ stable, nightly ] luals_version: [ 3.15.0 ] + emmyluacodestyle_version: [ 1.5.7 ] env: VIMRUNTIME: /home/runner/nvim-${{ matrix.nvim_version }}/share/nvim/runtime @@ -71,6 +72,9 @@ jobs: 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" + - name: install emmyluacodestyle ${{ matrix.emmyluacodestyle_version }} + run: luarocks install emmyluacodestyle ${{ matrix.emmyluacodestyle_version }} + - run: make check - run: make style diff --git a/Makefile b/Makefile index 6d668cf2b6a..d40aab39143 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ format-fix: format-check: CodeFormat format --config .editorconfig --workspace lua - git diff --exit-code lua + git diff --exit-code lua || printf "\n\nPlease run: make format-fix\n" # # utility From 296aeee7333e7be222cf1e6ccd3c8418a114caa9 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 17 Feb 2026 13:14:33 +1100 Subject: [PATCH 3/7] chore(#3271): CI install CodeFormat from luarocks --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f15ee073a5c..fded9d42712 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,6 +72,9 @@ jobs: 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" + - name: install luarocks + uses: leafo/gh-actions-luarocks@v6 + - name: install emmyluacodestyle ${{ matrix.emmyluacodestyle_version }} run: luarocks install emmyluacodestyle ${{ matrix.emmyluacodestyle_version }} From 98e71d6e1d4a8ac8156f9837eed5d20e0f9eb9ae Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 17 Feb 2026 13:16:51 +1100 Subject: [PATCH 4/7] chore(#3271): CI install CodeFormat from luarocks --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fded9d42712..c00d89c0ef6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,7 @@ jobs: strategy: matrix: + lua_version: [ 5.1 ] nvim_version: [ stable, nightly ] luals_version: [ 3.15.0 ] emmyluacodestyle_version: [ 1.5.7 ] @@ -72,6 +73,11 @@ jobs: 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" + - name: install lua ${{ matrix.lua_version }} + uses: leafo/gh-actions-lua@v12 + with: + luaVersion: ${{ matrix.lua_version }} + - name: install luarocks uses: leafo/gh-actions-luarocks@v6 From 7209c01d1f44c5c7485acf533d2fc33ed8de3a19 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 17 Feb 2026 13:21:22 +1100 Subject: [PATCH 5/7] chore(#3271): remove bad printf after format-check failure --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d40aab39143..6d668cf2b6a 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ format-fix: format-check: CodeFormat format --config .editorconfig --workspace lua - git diff --exit-code lua || printf "\n\nPlease run: make format-fix\n" + git diff --exit-code lua # # utility From 0fc8e24ea64aba10f9bd8582311713dfab1fc646 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 17 Feb 2026 13:28:09 +1100 Subject: [PATCH 6/7] chore(#3271): install CodeFormat from binary as luarocks is too slow --- .github/workflows/ci.yml | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c00d89c0ef6..b827c6fb423 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,15 +43,14 @@ jobs: runs-on: ubuntu-latest concurrency: - group: ${{ github.workflow }}-${{ matrix.nvim_version }}-${{ matrix.luals_version }}-${{ github.head_ref || github.ref_name }} + group: ${{ github.workflow }}-${{ matrix.nvim_version }}-${{ matrix.luals_version }}-${{ matrix.emmyluacodestyle_version }}-${{ github.head_ref || github.ref_name }} cancel-in-progress: true strategy: matrix: - lua_version: [ 5.1 ] nvim_version: [ stable, nightly ] luals_version: [ 3.15.0 ] - emmyluacodestyle_version: [ 1.5.7 ] + emmyluacodestyle_version: [ 1.6.0 ] env: VIMRUNTIME: /home/runner/nvim-${{ matrix.nvim_version }}/share/nvim/runtime @@ -73,16 +72,11 @@ jobs: 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" - - name: install lua ${{ matrix.lua_version }} - uses: leafo/gh-actions-lua@v12 - with: - luaVersion: ${{ matrix.lua_version }} - - - name: install luarocks - uses: leafo/gh-actions-luarocks@v6 - - - name: install emmyluacodestyle ${{ matrix.emmyluacodestyle_version }} - run: luarocks install emmyluacodestyle ${{ matrix.emmyluacodestyle_version }} + - name: install EmmyLuaCodeStyle ${{ matrix.emmyluacodestyle_version }} + run: | + mkdir -p EmmyLuaCodeStyle + curl -L "https://github.com/CppCXY/EmmyLuaCodeStyle/releases/download/${{ matrix.emmyluacodestyle_version }}/linux-x64.tar.gz" | tar zx --directory EmmyLuaCodeStyle + echo "EmmyLuaCodeStyle/linux-x64/bin" >> "$GITHUB_PATH" - run: make check From 394cb15108d0c99b6b564d4939995ce95c83e23b Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 17 Feb 2026 13:29:49 +1100 Subject: [PATCH 7/7] chore(#3271): no broken windows - all formatting fixed --- lua/nvim-tree/_meta/api/decorator.lua | 2 +- lua/nvim-tree/_meta/api/decorator_example.lua | 16 ++++++++-------- lua/nvim-tree/_meta/config/renderer.lua | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lua/nvim-tree/_meta/api/decorator.lua b/lua/nvim-tree/_meta/api/decorator.lua index c4ef939765b..1d1b9dbb723 100644 --- a/lua/nvim-tree/_meta/api/decorator.lua +++ b/lua/nvim-tree/_meta/api/decorator.lua @@ -41,7 +41,7 @@ local Class = require("nvim-tree.classic") --- ---@class nvim_tree.api.highlighted_string --- ----One or many glyphs/characters. +---One or many glyphs/characters. ---@field str string --- ---Highlight group names to apply in order. Empty table for no highlighting. diff --git a/lua/nvim-tree/_meta/api/decorator_example.lua b/lua/nvim-tree/_meta/api/decorator_example.lua index 32ccc4fd991..c4d42c5cb24 100644 --- a/lua/nvim-tree/_meta/api/decorator_example.lua +++ b/lua/nvim-tree/_meta/api/decorator_example.lua @@ -14,7 +14,7 @@ error("Cannot require a meta file") ---```lua --- --- local MyDecorator = require("my-decorator") ---- +--- --- require("nvim-tree").setup({ --- renderer = { --- decorators = { @@ -40,25 +40,25 @@ error("Cannot require a meta file") --- ---@field private my_icon_node nvim_tree.api.highlighted_string --- ---@field private my_highlight_group string --- local MyDecorator = require("nvim-tree.api").Decorator: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" ---- +--- --- -- 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" ---- +--- --- -- Define the icon signs only once --- -- Only needed if you are using icon_placement = "signcolumn" --- -- self:define_sign(self.my_icon1) --- -- self:define_sign(self.my_icon2) --- end ---- +--- --- ---Override node icon --- ---@param node nvim_tree.api.Node --- ---@return nvim_tree.api.highlighted_string? icon_node @@ -69,7 +69,7 @@ error("Cannot require a meta file") --- return nil --- end --- end ---- +--- --- ---Return two icons for DecoratorIconPlacement "after" --- ---@param node nvim_tree.api.Node --- ---@return nvim_tree.api.highlighted_string[]? icons @@ -80,7 +80,7 @@ error("Cannot require a meta file") --- return nil --- end --- end ---- +--- --- ---Exactly one highlight group for DecoratorHighlightRange "name" --- ---@param node nvim_tree.api.Node --- ---@return string? highlight_group @@ -91,6 +91,6 @@ error("Cannot require a meta file") --- return nil --- end --- end ---- +--- --- return MyDecorator ---``` diff --git a/lua/nvim-tree/_meta/config/renderer.lua b/lua/nvim-tree/_meta/config/renderer.lua index 4e7d419f101..6f61d864efe 100644 --- a/lua/nvim-tree/_meta/config/renderer.lua +++ b/lua/nvim-tree/_meta/config/renderer.lua @@ -364,7 +364,7 @@ error("Cannot require a meta file") --- for reason, count in pairs(hidden_stats) do --- total_count = total_count + count --- end ---- +--- --- if total_count > 0 then --- return "(" .. tostring(total_count) .. " hidden)" --- end