refactor(config): nest integration toggles under integrations namespace
Problem: integration keys (`fugitive`, `neogit`, `gitsigns`, `committia`, `telescope`) live at the top level of `vim.g.diffs`, cluttering the config alongside unrelated options like `highlights` and `conflict`. Solution: move them under `vim.g.diffs.integrations.*`. Old top-level keys are migrated automatically with a `vim.deprecate` warning targeting v0.3.2. `compute_filetypes` and `plugin/diffs.lua` fall back to legacy keys for pre-`init()` callers.
This commit is contained in:
parent
83c17aca67
commit
1b4d933148
4 changed files with 129 additions and 67 deletions
|
|
@ -61,16 +61,24 @@
|
||||||
---@field priority integer
|
---@field priority integer
|
||||||
---@field keymaps diffs.ConflictKeymaps
|
---@field keymaps diffs.ConflictKeymaps
|
||||||
|
|
||||||
---@class diffs.Config
|
---@class diffs.IntegrationsConfig
|
||||||
---@field debug boolean|string
|
|
||||||
---@field hide_prefix boolean
|
|
||||||
---@field extra_filetypes string[]
|
|
||||||
---@field highlights diffs.Highlights
|
|
||||||
---@field fugitive diffs.FugitiveConfig|false
|
---@field fugitive diffs.FugitiveConfig|false
|
||||||
---@field neogit diffs.NeogitConfig|false
|
---@field neogit diffs.NeogitConfig|false
|
||||||
---@field gitsigns diffs.GitsignsConfig|false
|
---@field gitsigns diffs.GitsignsConfig|false
|
||||||
---@field committia diffs.CommittiaConfig|false
|
---@field committia diffs.CommittiaConfig|false
|
||||||
---@field telescope diffs.TelescopeConfig|false
|
---@field telescope diffs.TelescopeConfig|false
|
||||||
|
|
||||||
|
---@class diffs.Config
|
||||||
|
---@field debug boolean|string
|
||||||
|
---@field hide_prefix boolean
|
||||||
|
---@field extra_filetypes string[]
|
||||||
|
---@field highlights diffs.Highlights
|
||||||
|
---@field integrations diffs.IntegrationsConfig
|
||||||
|
---@field fugitive diffs.FugitiveConfig|false deprecated: use integrations.fugitive
|
||||||
|
---@field neogit diffs.NeogitConfig|false deprecated: use integrations.neogit
|
||||||
|
---@field gitsigns diffs.GitsignsConfig|false deprecated: use integrations.gitsigns
|
||||||
|
---@field committia diffs.CommittiaConfig|false deprecated: use integrations.committia
|
||||||
|
---@field telescope diffs.TelescopeConfig|false deprecated: use integrations.telescope
|
||||||
---@field conflict diffs.ConflictConfig
|
---@field conflict diffs.ConflictConfig
|
||||||
|
|
||||||
---@class diffs
|
---@class diffs
|
||||||
|
|
@ -148,11 +156,13 @@ local default_config = {
|
||||||
char_bg = 201,
|
char_bg = 201,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fugitive = false,
|
integrations = {
|
||||||
neogit = false,
|
fugitive = false,
|
||||||
gitsigns = false,
|
neogit = false,
|
||||||
committia = false,
|
gitsigns = false,
|
||||||
telescope = false,
|
committia = false,
|
||||||
|
telescope = false,
|
||||||
|
},
|
||||||
conflict = {
|
conflict = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
disable_diagnostics = true,
|
disable_diagnostics = true,
|
||||||
|
|
@ -209,11 +219,18 @@ end
|
||||||
---@return string[]
|
---@return string[]
|
||||||
function M.compute_filetypes(opts)
|
function M.compute_filetypes(opts)
|
||||||
local fts = { 'git', 'gitcommit' }
|
local fts = { 'git', 'gitcommit' }
|
||||||
local fug = opts.fugitive
|
local intg = opts.integrations or {}
|
||||||
|
local fug = intg.fugitive
|
||||||
|
if fug == nil then
|
||||||
|
fug = opts.fugitive
|
||||||
|
end
|
||||||
if fug == true or type(fug) == 'table' then
|
if fug == true or type(fug) == 'table' then
|
||||||
table.insert(fts, 'fugitive')
|
table.insert(fts, 'fugitive')
|
||||||
end
|
end
|
||||||
local neo = opts.neogit
|
local neo = intg.neogit
|
||||||
|
if neo == nil then
|
||||||
|
neo = opts.neogit
|
||||||
|
end
|
||||||
if neo == true or type(neo) == 'table' then
|
if neo == true or type(neo) == 'table' then
|
||||||
table.insert(fts, 'NeogitStatus')
|
table.insert(fts, 'NeogitStatus')
|
||||||
table.insert(fts, 'NeogitCommitView')
|
table.insert(fts, 'NeogitCommitView')
|
||||||
|
|
@ -584,6 +601,26 @@ local function compute_highlight_groups()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local integration_keys = { 'fugitive', 'neogit', 'gitsigns', 'committia', 'telescope' }
|
||||||
|
|
||||||
|
local function migrate_integrations(opts)
|
||||||
|
opts.integrations = opts.integrations or {}
|
||||||
|
for _, key in ipairs(integration_keys) do
|
||||||
|
if opts[key] ~= nil then
|
||||||
|
vim.deprecate(
|
||||||
|
'vim.g.diffs.' .. key,
|
||||||
|
'vim.g.diffs.integrations.' .. key,
|
||||||
|
'0.3.2',
|
||||||
|
'diffs.nvim'
|
||||||
|
)
|
||||||
|
if opts.integrations[key] == nil then
|
||||||
|
opts.integrations[key] = opts[key]
|
||||||
|
end
|
||||||
|
opts[key] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function init()
|
local function init()
|
||||||
if initialized then
|
if initialized then
|
||||||
return
|
return
|
||||||
|
|
@ -592,48 +629,45 @@ local function init()
|
||||||
|
|
||||||
local opts = vim.g.diffs or {}
|
local opts = vim.g.diffs or {}
|
||||||
|
|
||||||
|
migrate_integrations(opts)
|
||||||
|
|
||||||
|
local intg = opts.integrations or {}
|
||||||
local fugitive_defaults = { horizontal = 'du', vertical = 'dU' }
|
local fugitive_defaults = { horizontal = 'du', vertical = 'dU' }
|
||||||
if opts.fugitive == true then
|
if intg.fugitive == true then
|
||||||
opts.fugitive = vim.deepcopy(fugitive_defaults)
|
intg.fugitive = vim.deepcopy(fugitive_defaults)
|
||||||
elseif type(opts.fugitive) == 'table' then
|
elseif type(intg.fugitive) == 'table' then
|
||||||
opts.fugitive = vim.tbl_extend('keep', opts.fugitive, fugitive_defaults)
|
intg.fugitive = vim.tbl_extend('keep', intg.fugitive, fugitive_defaults)
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts.neogit == true then
|
if intg.neogit == true then
|
||||||
opts.neogit = {}
|
intg.neogit = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts.gitsigns == true then
|
if intg.gitsigns == true then
|
||||||
opts.gitsigns = {}
|
intg.gitsigns = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts.committia == true then
|
if intg.committia == true then
|
||||||
opts.committia = {}
|
intg.committia = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts.telescope == true then
|
if intg.telescope == true then
|
||||||
opts.telescope = {}
|
intg.telescope = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.integrations = intg
|
||||||
|
|
||||||
vim.validate('debug', opts.debug, function(v)
|
vim.validate('debug', opts.debug, function(v)
|
||||||
return v == nil or type(v) == 'boolean' or type(v) == 'string'
|
return v == nil or type(v) == 'boolean' or type(v) == 'string'
|
||||||
end, 'boolean or string (file path)')
|
end, 'boolean or string (file path)')
|
||||||
vim.validate('hide_prefix', opts.hide_prefix, 'boolean', true)
|
vim.validate('hide_prefix', opts.hide_prefix, 'boolean', true)
|
||||||
vim.validate('fugitive', opts.fugitive, function(v)
|
vim.validate('integrations', opts.integrations, 'table', true)
|
||||||
|
local integration_validator = function(v)
|
||||||
return v == nil or v == false or type(v) == 'table'
|
return v == nil or v == false or type(v) == 'table'
|
||||||
end, 'table or false')
|
end
|
||||||
vim.validate('neogit', opts.neogit, function(v)
|
for _, key in ipairs(integration_keys) do
|
||||||
return v == nil or v == false or type(v) == 'table'
|
vim.validate('integrations.' .. key, intg[key], integration_validator, 'table or false')
|
||||||
end, 'table or false')
|
end
|
||||||
vim.validate('gitsigns', opts.gitsigns, function(v)
|
|
||||||
return v == nil or v == false or type(v) == 'table'
|
|
||||||
end, 'table or false')
|
|
||||||
vim.validate('committia', opts.committia, function(v)
|
|
||||||
return v == nil or v == false or type(v) == 'table'
|
|
||||||
end, 'table or false')
|
|
||||||
vim.validate('telescope', opts.telescope, function(v)
|
|
||||||
return v == nil or v == false or type(v) == 'table'
|
|
||||||
end, 'table or false')
|
|
||||||
vim.validate('extra_filetypes', opts.extra_filetypes, 'table', true)
|
vim.validate('extra_filetypes', opts.extra_filetypes, 'table', true)
|
||||||
vim.validate('highlights', opts.highlights, 'table', true)
|
vim.validate('highlights', opts.highlights, 'table', true)
|
||||||
|
|
||||||
|
|
@ -704,13 +738,13 @@ local function init()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(opts.fugitive) == 'table' then
|
if type(intg.fugitive) == 'table' then
|
||||||
---@type diffs.FugitiveConfig
|
---@type diffs.FugitiveConfig
|
||||||
local fug = opts.fugitive
|
local fug = intg.fugitive
|
||||||
vim.validate('fugitive.horizontal', fug.horizontal, function(v)
|
vim.validate('integrations.fugitive.horizontal', fug.horizontal, function(v)
|
||||||
return v == nil or v == false or type(v) == 'string'
|
return v == nil or v == false or type(v) == 'string'
|
||||||
end, 'string or false')
|
end, 'string or false')
|
||||||
vim.validate('fugitive.vertical', fug.vertical, function(v)
|
vim.validate('integrations.fugitive.vertical', fug.vertical, function(v)
|
||||||
return v == nil or v == false or type(v) == 'string'
|
return v == nil or v == false or type(v) == 'string'
|
||||||
end, 'string or false')
|
end, 'string or false')
|
||||||
end
|
end
|
||||||
|
|
@ -934,7 +968,7 @@ function M.attach(bufnr)
|
||||||
attached_buffers[bufnr] = true
|
attached_buffers[bufnr] = true
|
||||||
|
|
||||||
local neogit_augroup = nil
|
local neogit_augroup = nil
|
||||||
if config.neogit and vim.bo[bufnr].filetype:match('^Neogit') then
|
if config.integrations.neogit and vim.bo[bufnr].filetype:match('^Neogit') then
|
||||||
vim.b[bufnr].neogit_disable_hunk_highlight = true
|
vim.b[bufnr].neogit_disable_hunk_highlight = true
|
||||||
neogit_augroup = vim.api.nvim_create_augroup('diffs_neogit_' .. bufnr, { clear = true })
|
neogit_augroup = vim.api.nvim_create_augroup('diffs_neogit_' .. bufnr, { clear = true })
|
||||||
vim.api.nvim_create_autocmd('User', {
|
vim.api.nvim_create_autocmd('User', {
|
||||||
|
|
@ -1014,19 +1048,19 @@ end
|
||||||
---@return diffs.FugitiveConfig|false
|
---@return diffs.FugitiveConfig|false
|
||||||
function M.get_fugitive_config()
|
function M.get_fugitive_config()
|
||||||
init()
|
init()
|
||||||
return config.fugitive
|
return config.integrations.fugitive
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return diffs.CommittiaConfig|false
|
---@return diffs.CommittiaConfig|false
|
||||||
function M.get_committia_config()
|
function M.get_committia_config()
|
||||||
init()
|
init()
|
||||||
return config.committia
|
return config.integrations.committia
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return diffs.TelescopeConfig|false
|
---@return diffs.TelescopeConfig|false
|
||||||
function M.get_telescope_config()
|
function M.get_telescope_config()
|
||||||
init()
|
init()
|
||||||
return config.telescope
|
return config.integrations.telescope
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return diffs.ConflictConfig
|
---@return diffs.ConflictConfig
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,17 @@ vim.g.loaded_diffs = 1
|
||||||
|
|
||||||
require('diffs.commands').setup()
|
require('diffs.commands').setup()
|
||||||
|
|
||||||
local gs_cfg = (vim.g.diffs or {}).gitsigns
|
local function get_raw_integration(key)
|
||||||
|
local user = vim.g.diffs or {}
|
||||||
|
local intg = user.integrations or {}
|
||||||
|
local v = intg[key]
|
||||||
|
if v ~= nil then
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
return user[key]
|
||||||
|
end
|
||||||
|
|
||||||
|
local gs_cfg = get_raw_integration('gitsigns')
|
||||||
if gs_cfg == true or type(gs_cfg) == 'table' then
|
if gs_cfg == true or type(gs_cfg) == 'table' then
|
||||||
if not require('diffs.gitsigns').setup() then
|
if not require('diffs.gitsigns').setup() then
|
||||||
vim.api.nvim_create_autocmd('User', {
|
vim.api.nvim_create_autocmd('User', {
|
||||||
|
|
@ -18,7 +28,7 @@ if gs_cfg == true or type(gs_cfg) == 'table' then
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local tel_cfg = (vim.g.diffs or {}).telescope
|
local tel_cfg = get_raw_integration('telescope')
|
||||||
if tel_cfg == true or type(tel_cfg) == 'table' then
|
if tel_cfg == true or type(tel_cfg) == 'table' then
|
||||||
vim.api.nvim_create_autocmd('User', {
|
vim.api.nvim_create_autocmd('User', {
|
||||||
pattern = 'TelescopePreviewerLoaded',
|
pattern = 'TelescopePreviewerLoaded',
|
||||||
|
|
|
||||||
|
|
@ -336,45 +336,45 @@ describe('diffs', function()
|
||||||
assert.are.same({ 'git', 'gitcommit' }, fts)
|
assert.are.same({ 'git', 'gitcommit' }, fts)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('includes fugitive when fugitive = true', function()
|
it('includes fugitive when integrations.fugitive = true', function()
|
||||||
local fts = compute({ fugitive = true })
|
local fts = compute({ integrations = { fugitive = true } })
|
||||||
assert.is_true(vim.tbl_contains(fts, 'fugitive'))
|
assert.is_true(vim.tbl_contains(fts, 'fugitive'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('includes fugitive when fugitive is a table', function()
|
it('includes fugitive when integrations.fugitive is a table', function()
|
||||||
local fts = compute({ fugitive = { horizontal = 'dd' } })
|
local fts = compute({ integrations = { fugitive = { horizontal = 'dd' } } })
|
||||||
assert.is_true(vim.tbl_contains(fts, 'fugitive'))
|
assert.is_true(vim.tbl_contains(fts, 'fugitive'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('excludes fugitive when fugitive = false', function()
|
it('excludes fugitive when integrations.fugitive = false', function()
|
||||||
local fts = compute({ fugitive = false })
|
local fts = compute({ integrations = { fugitive = false } })
|
||||||
assert.is_false(vim.tbl_contains(fts, 'fugitive'))
|
assert.is_false(vim.tbl_contains(fts, 'fugitive'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('excludes fugitive when fugitive is nil', function()
|
it('excludes fugitive when integrations.fugitive is nil', function()
|
||||||
local fts = compute({})
|
local fts = compute({ integrations = {} })
|
||||||
assert.is_false(vim.tbl_contains(fts, 'fugitive'))
|
assert.is_false(vim.tbl_contains(fts, 'fugitive'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('includes neogit filetypes when neogit = true', function()
|
it('includes neogit filetypes when integrations.neogit = true', function()
|
||||||
local fts = compute({ neogit = true })
|
local fts = compute({ integrations = { neogit = true } })
|
||||||
assert.is_true(vim.tbl_contains(fts, 'NeogitStatus'))
|
assert.is_true(vim.tbl_contains(fts, 'NeogitStatus'))
|
||||||
assert.is_true(vim.tbl_contains(fts, 'NeogitCommitView'))
|
assert.is_true(vim.tbl_contains(fts, 'NeogitCommitView'))
|
||||||
assert.is_true(vim.tbl_contains(fts, 'NeogitDiffView'))
|
assert.is_true(vim.tbl_contains(fts, 'NeogitDiffView'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('includes neogit filetypes when neogit is a table', function()
|
it('includes neogit filetypes when integrations.neogit is a table', function()
|
||||||
local fts = compute({ neogit = {} })
|
local fts = compute({ integrations = { neogit = {} } })
|
||||||
assert.is_true(vim.tbl_contains(fts, 'NeogitStatus'))
|
assert.is_true(vim.tbl_contains(fts, 'NeogitStatus'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('excludes neogit when neogit = false', function()
|
it('excludes neogit when integrations.neogit = false', function()
|
||||||
local fts = compute({ neogit = false })
|
local fts = compute({ integrations = { neogit = false } })
|
||||||
assert.is_false(vim.tbl_contains(fts, 'NeogitStatus'))
|
assert.is_false(vim.tbl_contains(fts, 'NeogitStatus'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('excludes neogit when neogit is nil', function()
|
it('excludes neogit when integrations.neogit is nil', function()
|
||||||
local fts = compute({})
|
local fts = compute({ integrations = {} })
|
||||||
assert.is_false(vim.tbl_contains(fts, 'NeogitStatus'))
|
assert.is_false(vim.tbl_contains(fts, 'NeogitStatus'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
@ -383,13 +383,31 @@ describe('diffs', function()
|
||||||
assert.is_true(vim.tbl_contains(fts, 'diff'))
|
assert.is_true(vim.tbl_contains(fts, 'diff'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('combines fugitive, neogit, and extra_filetypes', function()
|
it('combines integrations and extra_filetypes', function()
|
||||||
local fts = compute({ fugitive = true, neogit = true, extra_filetypes = { 'diff' } })
|
local fts = compute({
|
||||||
|
integrations = { fugitive = true, neogit = true },
|
||||||
|
extra_filetypes = { 'diff' },
|
||||||
|
})
|
||||||
assert.is_true(vim.tbl_contains(fts, 'git'))
|
assert.is_true(vim.tbl_contains(fts, 'git'))
|
||||||
assert.is_true(vim.tbl_contains(fts, 'fugitive'))
|
assert.is_true(vim.tbl_contains(fts, 'fugitive'))
|
||||||
assert.is_true(vim.tbl_contains(fts, 'NeogitStatus'))
|
assert.is_true(vim.tbl_contains(fts, 'NeogitStatus'))
|
||||||
assert.is_true(vim.tbl_contains(fts, 'diff'))
|
assert.is_true(vim.tbl_contains(fts, 'diff'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('falls back to legacy top-level fugitive key', function()
|
||||||
|
local fts = compute({ fugitive = true })
|
||||||
|
assert.is_true(vim.tbl_contains(fts, 'fugitive'))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('falls back to legacy top-level neogit key', function()
|
||||||
|
local fts = compute({ neogit = true })
|
||||||
|
assert.is_true(vim.tbl_contains(fts, 'NeogitStatus'))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('prefers integrations key over legacy top-level key', function()
|
||||||
|
local fts = compute({ integrations = { fugitive = false }, fugitive = true })
|
||||||
|
assert.is_false(vim.tbl_contains(fts, 'fugitive'))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('diff mode', function()
|
describe('diff mode', function()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
require('spec.helpers')
|
require('spec.helpers')
|
||||||
|
|
||||||
vim.g.diffs = { neogit = true }
|
vim.g.diffs = { integrations = { neogit = true } }
|
||||||
|
|
||||||
local diffs = require('diffs')
|
local diffs = require('diffs')
|
||||||
local parser = require('diffs.parser')
|
local parser = require('diffs.parser')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue