feat(config): use vim.g over .setup()

This commit is contained in:
Barrett Ruth 2026-02-03 16:18:55 -05:00
parent 75a6bf184c
commit 2b38874699
5 changed files with 262 additions and 199 deletions

View file

@ -32,28 +32,25 @@ describe('highlight', function()
local function default_opts(overrides)
local opts = {
hide_prefix = false,
treesitter = {
enabled = true,
max_lines = 500,
},
vim = {
enabled = false,
max_lines = 200,
},
highlights = {
background = false,
gutter = false,
treesitter = {
enabled = true,
max_lines = 500,
},
vim = {
enabled = false,
max_lines = 200,
},
},
}
if overrides then
for k, v in pairs(overrides) do
if type(v) == 'table' and type(opts[k]) == 'table' then
for sk, sv in pairs(v) do
opts[k][sk] = sv
end
else
opts[k] = v
end
if overrides.highlights then
opts.highlights = vim.tbl_deep_extend('force', opts.highlights, overrides.highlights)
end
if overrides.hide_prefix ~= nil then
opts.hide_prefix = overrides.hide_prefix
end
end
return opts
@ -484,7 +481,7 @@ describe('highlight', function()
bufnr,
ns,
hunk,
default_opts({ treesitter = { enabled = false }, highlights = { background = true } })
default_opts({ highlights = { treesitter = { enabled = false }, background = true } })
)
local extmarks = get_extmarks(bufnr)
@ -517,7 +514,7 @@ describe('highlight', function()
bufnr,
ns,
hunk,
default_opts({ treesitter = { enabled = false }, highlights = { background = true } })
default_opts({ highlights = { treesitter = { enabled = false }, background = true } })
)
local extmarks = get_extmarks(bufnr)
@ -560,7 +557,12 @@ describe('highlight', function()
lines = { ' local x = 1', '+local y = 2' },
}
highlight.highlight_hunk(bufnr, ns, hunk, default_opts({ vim = { enabled = true } }))
highlight.highlight_hunk(
bufnr,
ns,
hunk,
default_opts({ highlights = { vim = { enabled = true } } })
)
vim.fn.synID = orig_synID
vim.fn.synIDtrans = orig_synIDtrans
@ -593,7 +595,12 @@ describe('highlight', function()
lines = { ' local x = 1', '+local y = 2' },
}
highlight.highlight_hunk(bufnr, ns, hunk, default_opts({ vim = { enabled = false } }))
highlight.highlight_hunk(
bufnr,
ns,
hunk,
default_opts({ highlights = { vim = { enabled = false } } })
)
local extmarks = get_extmarks(bufnr)
local has_syntax_hl = false
@ -628,7 +635,7 @@ describe('highlight', function()
bufnr,
ns,
hunk,
default_opts({ vim = { enabled = true, max_lines = 200 } })
default_opts({ highlights = { vim = { enabled = true, max_lines = 200 } } })
)
local extmarks = get_extmarks(bufnr)
@ -655,7 +662,7 @@ describe('highlight', function()
bufnr,
ns,
hunk,
default_opts({ vim = { enabled = true }, highlights = { background = true } })
default_opts({ highlights = { vim = { enabled = true }, background = true } })
)
local extmarks = get_extmarks(bufnr)
@ -698,7 +705,12 @@ describe('highlight', function()
lines = { ' local x = 1', '+local y = 2' },
}
highlight.highlight_hunk(bufnr, ns, hunk, default_opts({ vim = { enabled = true } }))
highlight.highlight_hunk(
bufnr,
ns,
hunk,
default_opts({ highlights = { vim = { enabled = true } } })
)
vim.fn.synID = orig_synID
vim.fn.synIDtrans = orig_synIDtrans

View file

@ -2,26 +2,33 @@ require('spec.helpers')
local diffs = require('diffs')
describe('diffs', function()
describe('setup', function()
it('accepts empty config', function()
assert.has_no.errors(function()
diffs.setup({})
end)
describe('vim.g.diffs config', function()
after_each(function()
vim.g.diffs = nil
end)
it('accepts nil config', function()
vim.g.diffs = nil
assert.has_no.errors(function()
diffs.setup()
diffs.attach()
end)
end)
it('accepts empty config', function()
vim.g.diffs = {}
assert.has_no.errors(function()
diffs.attach()
end)
end)
it('accepts full config', function()
assert.has_no.errors(function()
diffs.setup({
enabled = false,
debug = true,
debounce_ms = 100,
hide_prefix = false,
vim.g.diffs = {
debug = true,
debounce_ms = 100,
hide_prefix = false,
highlights = {
background = true,
gutter = true,
treesitter = {
enabled = true,
max_lines = 1000,
@ -30,19 +37,19 @@ describe('diffs', function()
enabled = false,
max_lines = 200,
},
highlights = {
background = true,
gutter = true,
},
})
},
}
assert.has_no.errors(function()
diffs.attach()
end)
end)
it('accepts partial config', function()
vim.g.diffs = {
debounce_ms = 25,
}
assert.has_no.errors(function()
diffs.setup({
debounce_ms = 25,
})
diffs.attach()
end)
end)
end)
@ -60,10 +67,6 @@ describe('diffs', function()
end
end
before_each(function()
diffs.setup({ enabled = true })
end)
it('does not error on empty buffer', function()
local bufnr = create_buffer({})
assert.has_no.errors(function()
@ -109,10 +112,6 @@ describe('diffs', function()
end
end
before_each(function()
diffs.setup({ enabled = true })
end)
it('does not error on unattached buffer', function()
local bufnr = create_buffer({})
assert.has_no.errors(function()
@ -168,10 +167,6 @@ describe('diffs', function()
end
end
before_each(function()
diffs.setup({ enabled = true })
end)
describe('attach_diff', function()
it('applies winhighlight to diff windows', function()
local win, _ = create_diff_window()