From 6fa941a01f25cd104c91c54a7556e54361381b08 Mon Sep 17 00:00:00 2001 From: user <17591696+sand4rt@users.noreply.github.com> Date: Thu, 16 Apr 2026 21:35:06 +0200 Subject: [PATCH] fix: resizing with top/bottom integrations --- .luarc.json | 5 +- Makefile | 42 +++++++-- lua/zen/init.lua | 2 +- tests/scripts/init_with_zen.lua | 20 ++++- tests/scripts/minimal_init.lua | 2 +- tests/test_resizing.lua | 146 ++++++++++++++++++++++++++++++++ 6 files changed, 203 insertions(+), 14 deletions(-) create mode 100644 tests/test_resizing.lua diff --git a/.luarc.json b/.luarc.json index b92ade8..23abe37 100644 --- a/.luarc.json +++ b/.luarc.json @@ -1,13 +1,14 @@ { "diagnostics": { "globals": [ - "dofile" + "dofile", + "MiniTest" ] }, "workspace": { "library": [ "$VIMRUNTIME", - "deps/mini.nvim" + "deps/pack/testing/start/mini.nvim" ] } } diff --git a/Makefile b/Makefile index 1c78e0d..2879d6e 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,41 @@ DEPS_DIR := $(CURDIR)/deps +START_DIR := $(DEPS_DIR)/pack/testing/start .PHONY: test deps -# Download mini.nvim if not present, then run all tests test: deps nvim --headless -u tests/scripts/minimal_init.lua -c "lua MiniTest.run()" -# Clone mini.nvim into deps/ -deps: - @if [ ! -d "$(DEPS_DIR)/mini.nvim" ]; then \ - echo "Downloading mini.nvim..."; \ - mkdir -p "$(DEPS_DIR)"; \ - git clone --depth 1 https://github.com/echasnovski/mini.nvim "$(DEPS_DIR)/mini.nvim"; \ - fi +deps: \ + $(START_DIR)/mini.nvim \ + $(START_DIR)/vim-fugitive \ + $(START_DIR)/fyler.nvim \ + $(START_DIR)/trouble.nvim \ + $(START_DIR)/neotest \ + $(START_DIR)/nvim-nio \ + $(START_DIR)/plenary.nvim \ + $(START_DIR)/fixcursorhold + +$(START_DIR)/mini.nvim: + git clone --depth 1 https://github.com/echasnovski/mini.nvim $@ + +$(START_DIR)/vim-fugitive: + git clone --depth 1 https://github.com/tpope/vim-fugitive $@ + +$(START_DIR)/fyler.nvim: + git clone --depth 1 https://github.com/A7Lavinraj/fyler.nvim $@ + +$(START_DIR)/trouble.nvim: + git clone --depth 1 https://github.com/folke/trouble.nvim $@ + +$(START_DIR)/neotest: + git clone --depth 1 https://github.com/nvim-neotest/neotest $@ + +$(START_DIR)/nvim-nio: + git clone --depth 1 https://github.com/nvim-neotest/nvim-nio $@ + +$(START_DIR)/plenary.nvim: + git clone --depth 1 https://github.com/nvim-lua/plenary.nvim $@ + +$(START_DIR)/fixcursorhold: + git clone --depth 1 https://github.com/antoinemadec/FixCursorHold.nvim $@ diff --git a/lua/zen/init.lua b/lua/zen/init.lua index 6b44659..876a3f5 100644 --- a/lua/zen/init.lua +++ b/lua/zen/init.lua @@ -129,7 +129,7 @@ local function is_buff_integration(buf) if filetype == "zen-left" or filetype == "zen-right" then return true end - for _, position in ipairs({ "left", "right" }) do + for _, position in ipairs({ "left", "right", "top", "bottom" }) do for _, integration in ipairs(opts[position] or {}) do ---@diagnostic disable-next-line: undefined-field if type(integration) == "table" and is_filetype(filetype, integration.filetype) then diff --git a/tests/scripts/init_with_zen.lua b/tests/scripts/init_with_zen.lua index 0d079e7..a6f93b1 100644 --- a/tests/scripts/init_with_zen.lua +++ b/tests/scripts/init_with_zen.lua @@ -1,8 +1,24 @@ vim.cmd([[let &rtp.=','.getcwd()]]) -vim.cmd("set rtp+=deps/mini.nvim") +vim.opt.packpath:prepend("deps") vim.o.columns = 240 vim.o.lines = 52 require("mini.test").setup() -require("zen").setup() +require("trouble").setup({ open_no_results = true }) +require("zen").setup({ + top = { + { filetype = "fugitive" }, + }, + bottom = { + { filetype = "trouble" }, + }, + left = { + min_width = 46, + { filetype = "fyler" }, + }, + right = { + min_width = 46, + { filetype = "neotest-summary" }, + }, +}) diff --git a/tests/scripts/minimal_init.lua b/tests/scripts/minimal_init.lua index a550481..b06eb79 100644 --- a/tests/scripts/minimal_init.lua +++ b/tests/scripts/minimal_init.lua @@ -1,4 +1,4 @@ vim.cmd([[let &rtp.=','.getcwd()]]) -vim.cmd("set rtp+=deps/mini.nvim") +vim.opt.packpath:prepend("deps") require("mini.test").setup() diff --git a/tests/test_resizing.lua b/tests/test_resizing.lua new file mode 100644 index 0000000..eb7a30d --- /dev/null +++ b/tests/test_resizing.lua @@ -0,0 +1,146 @@ +local Helpers = dofile("tests/scripts/helpers.lua") +local child = MiniTest.new_child_neovim() + +local T = MiniTest.new_set({ + hooks = { + pre_case = function() + child.restart({ "-u", "tests/scripts/init_with_zen.lua" }) + end, + post_once = child.stop, + }, +}) + +T["resizing below minimum width closes the side buffers"] = function() + child.cmd("set columns-=100") + child.cmd("doautocmd VimResized") + + Helpers.expect.layout(child, { + type = "leaf", + filetype = "", + buftype = "", + width = 140, + height = 50, + }) +end + +T["resizing above minimum width reopens the side buffers"] = function() + child.cmd("set columns-=100") + child.cmd("doautocmd VimResized") + + child.cmd("set columns+=100") + child.cmd("doautocmd VimResized") + + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, + }, + }) +end + +T["with top integration"] = MiniTest.new_set({}) + +T["with top integration"]["resizing below minimum width closes the side buffers"] = function() + child.cmd("Git") + + child.cmd("set columns-=100") + child.cmd("doautocmd VimResized") + + Helpers.expect.layout(child, { + type = "col", + children = { + { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 140, height = 25 }, + { type = "leaf", filetype = "", buftype = "", width = 140, height = 24 }, + }, + }) +end + +T["with top integration"]["resizing above minimum width reopens the side buffers"] = function() + child.cmd("Git") + + child.cmd("set columns-=100") + child.cmd("doautocmd VimResized") + + child.cmd("set columns+=100") + child.cmd("doautocmd VimResized") + + Helpers.expect.layout(child, { + type = "col", + children = { + { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 }, + { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 24 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 }, + }, + }, + }, + }) +end + +T["with bottom integration"] = MiniTest.new_set({}) + +T["with bottom integration"]["resizing below minimum width closes the side buffers"] = function() + child.cmd("Trouble diagnostics") + + child.cmd("set columns-=100") + child.cmd("doautocmd VimResized") + + Helpers.expect.layout(child, { + type = "col", + children = { + { type = "leaf", filetype = "", buftype = "", width = 140, height = 39 }, + { type = "leaf", filetype = "trouble", buftype = "nofile", width = 140, height = 10 }, + }, + }) +end + +T["with bottom integration"]["resizing above minimum width reopens the side buffers"] = function() + child.cmd("Trouble diagnostics") + + child.cmd("set columns-=100") + child.cmd("doautocmd VimResized") + + child.cmd("set columns+=100") + child.cmd("doautocmd VimResized") + + Helpers.expect.layout(child, { + type = "col", + children = { + { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 39 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 }, + }, + }, + { type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 }, + }, + }) +end + +T["with top and bottom integration"] = MiniTest.new_set({}) + +T["with top and bottom integration"]["resizing below minimum width closes the side buffers"] = function() + child.cmd("Git") + child.cmd("Trouble diagnostics") + + child.cmd("set columns-=100") + child.cmd("doautocmd VimResized") + + Helpers.expect.layout(child, { + type = "col", + children = { + { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 140, height = 25 }, + { type = "leaf", filetype = "", buftype = "", width = 140, height = 13 }, + { type = "leaf", filetype = "trouble", buftype = "nofile", width = 140, height = 10 }, + }, + }) +end + +return T