Skip to content

Commit

Permalink
feat(integrations): support alpha.nvim (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Mar 17, 2024
1 parent ec8e69a commit 73b4e17
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
deps
**.DS_Store
.ci
.ci/**
4 changes: 2 additions & 2 deletions lua/no-neck-pain/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ function C.matchAndBlend(colorCode, factor)
)
end

if Co.INTEGRATIONS[colorCode] ~= nil then
colorCode = Co.INTEGRATIONS[colorCode]
if Co.THEMES[colorCode] ~= nil then
colorCode = Co.THEMES[colorCode]
end

local hexPattern = "^#" .. "[abcdef0-9]" .. ("[abcdef0-9]"):rep(5) .. "$"
Expand Down
8 changes: 4 additions & 4 deletions lua/no-neck-pain/state.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local A = require("no-neck-pain.util.api")
local C = require("no-neck-pain.util.constants")
local Co = require("no-neck-pain.util.constants")
local D = require("no-neck-pain.util.debug")

local State = { enabled = false, activeTab = A.getCurrentTab(), tabs = nil }
Expand Down Expand Up @@ -194,7 +194,7 @@ function State:isSupportedIntegration(scope, win)
return self.isSupportedIntegration(self, scope, wins[1])
end

local registeredIntegrations = tab ~= nil and tab.wins.integrations or C.integrations
local registeredIntegrations = tab ~= nil and tab.wins.integrations or Co.INTEGRATIONS

for name, integration in pairs(registeredIntegrations) do
if vim.startswith(string.lower(fileType), integration.fileTypePattern) then
Expand All @@ -218,7 +218,7 @@ end
---@private
function State:scanIntegrations(scope)
local wins = self.getUnregisteredWins(self)
local unregisteredIntegrations = vim.deepcopy(C.integrations)
local unregisteredIntegrations = vim.deepcopy(Co.INTEGRATIONS)

for _, win in pairs(wins) do
local supported, name, integration = self.isSupportedIntegration(self, scope, win)
Expand Down Expand Up @@ -493,7 +493,7 @@ function State:setTab(id)
right = nil,
},
splits = nil,
integrations = vim.deepcopy(C.integrations),
integrations = vim.deepcopy(Co.INTEGRATIONS),
},
}
self.activeTab = id
Expand Down
18 changes: 13 additions & 5 deletions lua/no-neck-pain/util/constants.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
local C = {}
local Co = {}

---Sides where the buffers are created.
---
---@private
C.SIDES = { "left", "right" }
Co.SIDES = { "left", "right" }

---Available color integrations aliases.
---
---@private
C.INTEGRATIONS = {
Co.THEMES = {
["catppuccin-frappe"] = "#303446",
["catppuccin-frappe-dark"] = "#292c3c",
["catppuccin-latte"] = "#eff1f5",
Expand All @@ -33,7 +33,10 @@ C.INTEGRATIONS = {
["tokyonight-storm"] = "#1f2335",
}

C.integrations = {
---Supported integrations in order to properly interact with the buffers.
---
---@private
Co.INTEGRATIONS = {
NvimTree = {
fileTypePattern = "nvimtree",
close = "NvimTreeClose",
Expand Down Expand Up @@ -66,4 +69,9 @@ C.integrations = {
},
}

return C
---Dashboards filetypes that delays the plugin enable step until next buffer entered.
---
---@private
Co.DASHBOARDS = { "dashboard", "alpha" }

return Co
7 changes: 4 additions & 3 deletions lua/no-neck-pain/util/event.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local A = require("no-neck-pain.util.api")
local Co = require("no-neck-pain.util.constants")
local S = require("no-neck-pain.state")

local E = {}
Expand Down Expand Up @@ -52,12 +53,12 @@ function E.skipEnable()
return true
end

local isSupportedIntegration = S.isSupportedIntegration(S, "E.skipEnable", nil)
if isSupportedIntegration or vim.bo.filetype == "dashboard" then
-- dashboards delays the plugin enable step until next buffer entered
if vim.tbl_contains(Co.DASHBOARDS, vim.bo.filetype) then
return true
end

return false
return S.isSupportedIntegration(S, "E.skipEnable", nil)
end

return E
6 changes: 3 additions & 3 deletions tests/test_API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ T["enable"]["(single tab) sets state"] = function()

Helpers.expect.state_type(child, "tabs[1].wins.integrations", "table")

Helpers.expect.state(child, "tabs[1].wins.integrations", Co.integrations)
Helpers.expect.state(child, "tabs[1].wins.integrations", Co.INTEGRATIONS)
end

T["enable"]["(multiple tab) sets state"] = function()
Expand Down Expand Up @@ -264,7 +264,7 @@ T["enable"]["(multiple tab) sets state"] = function()

Helpers.expect.state_type(child, "tabs[1].wins.integrations", "table")

Helpers.expect.state(child, "tabs[1].wins.integrations", Co.integrations)
Helpers.expect.state(child, "tabs[1].wins.integrations", Co.INTEGRATIONS)

-- tab 2
child.cmd("tabnew")
Expand All @@ -288,7 +288,7 @@ T["enable"]["(multiple tab) sets state"] = function()

Helpers.expect.state_type(child, "tabs[2].wins.integrations", "table")

Helpers.expect.state(child, "tabs[2].wins.integrations", Co.integrations)
Helpers.expect.state(child, "tabs[2].wins.integrations", Co.INTEGRATIONS)
end

T["disable"] = MiniTest.new_set()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ end
T["color"] = MiniTest.new_set()

T["color"]["map integration name to a value"] = function()
for integration, value in pairs(Co.INTEGRATIONS) do
for integration, value in pairs(Co.THEMES) do
child.lua(string.format(
[[ require('no-neck-pain').setup({
buffers = {
Expand Down
32 changes: 16 additions & 16 deletions tests/test_tabs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ T["tabnew/tabclose"]["doesn't keep closed tabs in state"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1000,
left = 1001,
Expand All @@ -212,7 +212,7 @@ T["tabnew/tabclose"]["doesn't keep closed tabs in state"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1000,
left = 1001,
Expand All @@ -228,7 +228,7 @@ T["tabnew/tabclose"]["doesn't keep closed tabs in state"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1003,
left = 1004,
Expand All @@ -248,7 +248,7 @@ T["tabnew/tabclose"]["doesn't keep closed tabs in state"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1000,
left = 1001,
Expand All @@ -275,7 +275,7 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1000,
left = 1001,
Expand All @@ -299,7 +299,7 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1000,
left = 1001,
Expand All @@ -315,7 +315,7 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1003,
left = 1004,
Expand All @@ -335,7 +335,7 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1000,
left = 1001,
Expand All @@ -355,7 +355,7 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1000,
left = 1001,
Expand All @@ -371,7 +371,7 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1003,
left = 1006,
Expand All @@ -392,7 +392,7 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1000,
left = 1001,
Expand All @@ -408,7 +408,7 @@ T["tabnew/tabclose"]["keeps state synchronized between tabs"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1003,
left = 1006,
Expand Down Expand Up @@ -449,7 +449,7 @@ T["tabnew/tabclose"]["does not pick tab 1 for the first active tab"] = function(
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1001,
left = 1002,
Expand Down Expand Up @@ -521,7 +521,7 @@ T["tabnew/tabclose"]["does not pick tab 1 for the first active tab"] = function(
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1001,
left = 1002,
Expand Down Expand Up @@ -558,7 +558,7 @@ T["tabnew/tabclose"]["keep state synchronized on second tab"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1001,
left = 1002,
Expand Down Expand Up @@ -588,7 +588,7 @@ T["tabnew/tabclose"]["keep state synchronized on second tab"] = function()
},
scratchPadEnabled = false,
wins = {
integrations = Co.integrations,
integrations = Co.INTEGRATIONS,
main = {
curr = 1001,
left = 1002,
Expand Down

0 comments on commit 73b4e17

Please sign in to comment.