Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(integrations): support aerial.nvim #360

Merged
merged 4 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ deps:
git clone --depth 1 https://github.com/rcarriga/nvim-dap-ui deps/nvimdapui
git clone --depth 1 https://github.com/hedyhli/outline.nvim deps/outline
git clone --depth 1 https://github.com/b0o/incline.nvim deps/incline
git clone --depth 1 https://github.com/stevearc/aerial.nvim deps/aerial

test-ci: deps test

Expand Down
8 changes: 8 additions & 0 deletions doc/no-neck-pain.txt
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ values:
-- When `true`, if the tree was opened before enabling the plugin, we will reopen it.
reopen = true,
},
-- @link https://github.com/stevearc/aerial.nvim
aerial = {
-- The position of the tree.
--- @type "left"|"right"
position = "right",
-- When `true`, if the tree was opened before enabling the plugin, we will reopen it.
reopen = true,
},
},
}

Expand Down
8 changes: 8 additions & 0 deletions lua/no-neck-pain/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ NoNeckPain.options = {
-- When `true`, if the tree was opened before enabling the plugin, we will reopen it.
reopen = true,
},
-- @link https://github.com/stevearc/aerial.nvim
aerial = {
-- The position of the tree.
--- @type "left"|"right"
position = "right",
-- When `true`, if the tree was opened before enabling the plugin, we will reopen it.
reopen = true,
},
},
}

Expand Down
5 changes: 5 additions & 0 deletions lua/no-neck-pain/util/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ Co.INTEGRATIONS = {
close = "Outline",
open = "Outline",
},
aerial = {
fileTypePattern = "aerial",
close = "AerialToggle",
open = "AerialToggle",
},
}

---Dashboards filetypes that delays the plugin enable step until next buffer entered.
Expand Down
21 changes: 21 additions & 0 deletions scripts/init_with_aerial.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
vim.cmd([[let &rtp.=','.getcwd()]])

vim.cmd("set rtp+=deps/mini.nvim")
vim.cmd("set rtp+=deps/nvim-treesitter")
vim.cmd("set rtp+=deps/nvim-web-devicons")
vim.cmd("set rtp+=deps/aerial")

require("mini.test").setup()
require("no-neck-pain").setup({
width = 20,
minSideBufferWidth = 0,
integrations = { aerial = { reopen = true } },
})
require("aerial").setup({
-- optionally use on_attach to set keymaps when aerial has attached to a buffer
on_attach = function(bufnr)
-- Jump forwards/backwards with '{' and '}'
vim.keymap.set("n", "{", "<cmd>AerialPrev<CR>", { buffer = bufnr })
vim.keymap.set("n", "}", "<cmd>AerialNext<CR>", { buffer = bufnr })
end,
})
2 changes: 1 addition & 1 deletion scripts/init_with_tsplayground.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ require("nvim-treesitter.configs").setup({
},
})
require("mini.test").setup()
require("no-neck-pain").setup({ width = 30 })
require("no-neck-pain").setup({ width = 1 })
4 changes: 4 additions & 0 deletions tests/test_API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ T["setup"]["sets exposed methods and default options value"] = function()
position = "right",
reopen = true,
},
aerial = {
position = "right",
reopen = true,
},
})
end

Expand Down
71 changes: 67 additions & 4 deletions tests/test_integrations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ T["setup"]["overrides default values"] = function()
reopen = false,
position = "left",
},
outline = {
reopen = false,
position = "left",
},
aerial = {
position = "left",
reopen = false,
},
}
})]])

Expand Down Expand Up @@ -68,8 +76,12 @@ T["setup"]["overrides default values"] = function()
reopen = false,
},
outline = {
position = "right",
reopen = true,
position = "left",
reopen = false,
},
aerial = {
position = "left",
reopen = false,
},
})
end
Expand Down Expand Up @@ -311,13 +323,13 @@ T["TSPlayground"]["keeps sides open"] = function()

Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL)

Helpers.expect.equality(child.lua_get("vim.api.nvim_win_get_width(1004)"), 173)
Helpers.expect.equality(child.lua_get("vim.api.nvim_win_get_width(1004)"), 159)
Helpers.expect.state(child, "tabs[1].wins.integrations.TSPlayground", {
close = "TSPlaygroundToggle",
fileTypePattern = "tsplayground",
id = 1004,
open = "TSPlaygroundToggle",
width = 346,
width = 318,
})

Helpers.expect.state(child, "tabs[1].wins.main", {
Expand Down Expand Up @@ -402,4 +414,55 @@ T["TSPlayground"]["reduces `left` side if only active when integration is on `ri
})
end

T["aerial"] = MiniTest.new_set()

T["aerial"]["keeps sides open"] = function()
if child.fn.has("nvim-0.8") == 0 then
MiniTest.skip("aerial doesn't support version below 8")

return
end

child.restart({ "-u", "scripts/init_with_aerial.lua" })
child.set_size(5, 500)

Helpers.toggle(child)

Helpers.expect.equality(Helpers.winsInTab(child), { 1001, 1000, 1002 })

Helpers.expect.state(child, "enabled", true)
Helpers.expect.state(child, "tabs[1].wins.main", {
curr = 1000,
left = 1001,
right = 1002,
})

child.cmd("AerialToggle")

Helpers.expect.state(child, "tabs[1].wins.splits", vim.NIL)

Helpers.expect.equality(child.lua_get("vim.api.nvim_win_get_width(1004)"), 25)
Helpers.expect.state(child, "tabs[1].wins.integrations.aerial.id", 1004)

Helpers.expect.state(child, "tabs[1].wins.main", {
curr = 1000,
left = 1001,
right = 1002,
})

child.cmd("AerialToggle")
vim.loop.sleep(50)

Helpers.expect.state(child, "tabs[1].wins.integrations.aerial", {
close = "AerialToggle",
fileTypePattern = "aerial",
open = "AerialToggle",
})
Helpers.expect.state(child, "tabs[1].wins.main", {
curr = 1000,
left = 1001,
right = 1002,
})
end

return T
5 changes: 5 additions & 0 deletions tests/test_tabs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,11 @@ T["tabnew/tabclose"]["does not pick tab 1 for the first active tab"] = function(
fileTypePattern = "outline",
open = "Outline",
},
aerial = {
close = "AerialToggle",
fileTypePattern = "aerial",
open = "AerialToggle",
},
},
main = {
curr = 1000,
Expand Down
Loading