From 047e19de0421a6c3f2c0954b950cf8f53728c4c4 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Thu, 1 Dec 2022 08:37:54 -0800 Subject: [PATCH] fix: do not open_automatic in unsupported buffers (#185) --- lua/aerial/util.lua | 3 +++ lua/aerial/window.lua | 3 ++- tests/attach_and_events_spec.lua | 24 ++++++++++++++++++++++++ tests/open_spec.lua | 2 +- tests/window_spec.lua | 2 +- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lua/aerial/util.lua b/lua/aerial/util.lua index 81512ad..9647452 100644 --- a/lua/aerial/util.lua +++ b/lua/aerial/util.lua @@ -225,6 +225,9 @@ end ---@return boolean M.is_ignored_buf = function(bufnr) bufnr = bufnr or 0 + if not vim.api.nvim_buf_is_valid(bufnr) then + return true + end local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype") -- Never ignore aerial buffers if filetype == "aerial" then diff --git a/lua/aerial/window.lua b/lua/aerial/window.lua index 3aee9bc..353c921 100644 --- a/lua/aerial/window.lua +++ b/lua/aerial/window.lua @@ -269,7 +269,8 @@ end ---@param bufnr? integer ---@return boolean M.maybe_open_automatic = function(bufnr) - if config.open_automatic(bufnr or 0) then + bufnr = bufnr or 0 + if config.open_automatic(bufnr) and backends.get(bufnr) then M.open(false) return true else diff --git a/tests/attach_and_events_spec.lua b/tests/attach_and_events_spec.lua index 9295ce0..d371ffc 100644 --- a/tests/attach_and_events_spec.lua +++ b/tests/attach_and_events_spec.lua @@ -239,4 +239,28 @@ a.describe("config attach_mode = 'global'", function() assert.falsy(vim.api.nvim_win_is_valid(aerial_win)) end ) + + a.it("open_automatic = true opens aerial when entering supported buffer", function() + aerial.setup({ + lazy_load = false, + attach_mode = "global", + open_automatic = true, + }) + vim.cmd.edit({ args = { "README.md" } }) + sleep(30) + local aerial_win = util.get_aerial_win(0) + assert.truthy(vim.api.nvim_win_is_valid(aerial_win)) + end) + + a.it("open_automatic = true does not open aerial when entering unsupported buffer", function() + aerial.setup({ + lazy_load = false, + attach_mode = "global", + open_automatic = true, + }) + vim.cmd.edit({ args = { "LICENSE" } }) + sleep(30) + local aerial_win = util.get_aerial_win(0) + assert.is_nil(aerial_win) + end) end) diff --git a/tests/open_spec.lua b/tests/open_spec.lua index f3a6c44..2aedaa7 100644 --- a/tests/open_spec.lua +++ b/tests/open_spec.lua @@ -2,7 +2,7 @@ require("plenary.async").tests.add_to_env() local aerial = require("aerial") local test_util = require("tests.test_util") -a.describe("config", function() +a.describe("layout", function() after_each(function() test_util.reset_editor() end) diff --git a/tests/window_spec.lua b/tests/window_spec.lua index 07ad2aa..6154193 100644 --- a/tests/window_spec.lua +++ b/tests/window_spec.lua @@ -2,7 +2,7 @@ local config = require("aerial.config") local data = require("aerial.data") local window = require("aerial.window") -describe("config", function() +describe("symbol positions", function() before_each(function() config.setup() end)