Compare commits
No commits in common. "244cae33bd6ef2a981d391a63e6f1eb450bac1f4" and "d584d816bf1242049ee93788893dd5b3c05d63f7" have entirely different histories.
244cae33bd
...
d584d816bf
5 changed files with 81 additions and 151 deletions
|
|
@ -61,24 +61,16 @@
|
|||
---@field priority integer
|
||||
---@field keymaps diffs.ConflictKeymaps
|
||||
|
||||
---@class diffs.IntegrationsConfig
|
||||
---@field fugitive diffs.FugitiveConfig|false
|
||||
---@field neogit diffs.NeogitConfig|false
|
||||
---@field gitsigns diffs.GitsignsConfig|false
|
||||
---@field committia diffs.CommittiaConfig|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 fugitive diffs.FugitiveConfig|false
|
||||
---@field neogit diffs.NeogitConfig|false
|
||||
---@field gitsigns diffs.GitsignsConfig|false
|
||||
---@field committia diffs.CommittiaConfig|false
|
||||
---@field telescope diffs.TelescopeConfig|false
|
||||
---@field conflict diffs.ConflictConfig
|
||||
|
||||
---@class diffs
|
||||
|
|
@ -156,13 +148,11 @@ local default_config = {
|
|||
char_bg = 201,
|
||||
},
|
||||
},
|
||||
integrations = {
|
||||
fugitive = false,
|
||||
neogit = false,
|
||||
gitsigns = false,
|
||||
committia = false,
|
||||
telescope = false,
|
||||
},
|
||||
fugitive = false,
|
||||
neogit = false,
|
||||
gitsigns = false,
|
||||
committia = false,
|
||||
telescope = false,
|
||||
conflict = {
|
||||
enabled = true,
|
||||
disable_diagnostics = true,
|
||||
|
|
@ -219,18 +209,11 @@ end
|
|||
---@return string[]
|
||||
function M.compute_filetypes(opts)
|
||||
local fts = { 'git', 'gitcommit' }
|
||||
local intg = opts.integrations or {}
|
||||
local fug = intg.fugitive
|
||||
if fug == nil then
|
||||
fug = opts.fugitive
|
||||
end
|
||||
local fug = opts.fugitive
|
||||
if fug == true or type(fug) == 'table' then
|
||||
table.insert(fts, 'fugitive')
|
||||
end
|
||||
local neo = intg.neogit
|
||||
if neo == nil then
|
||||
neo = opts.neogit
|
||||
end
|
||||
local neo = opts.neogit
|
||||
if neo == true or type(neo) == 'table' then
|
||||
table.insert(fts, 'NeogitStatus')
|
||||
table.insert(fts, 'NeogitCommitView')
|
||||
|
|
@ -601,27 +584,6 @@ local function compute_highlight_groups()
|
|||
end
|
||||
end
|
||||
|
||||
local integration_keys = { 'fugitive', 'neogit', 'gitsigns', 'committia', 'telescope' }
|
||||
|
||||
local function migrate_integrations(opts)
|
||||
local has_new = opts.integrations ~= nil
|
||||
opts.integrations = opts.integrations or {}
|
||||
for _, key in ipairs(integration_keys) do
|
||||
if opts[key] ~= nil then
|
||||
if not has_new then
|
||||
vim.deprecate(
|
||||
'vim.g.diffs.' .. key,
|
||||
'vim.g.diffs.integrations.' .. key,
|
||||
'0.3.2',
|
||||
'diffs.nvim'
|
||||
)
|
||||
opts.integrations[key] = opts[key]
|
||||
end
|
||||
opts[key] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function init()
|
||||
if initialized then
|
||||
return
|
||||
|
|
@ -630,45 +592,48 @@ local function init()
|
|||
|
||||
local opts = vim.g.diffs or {}
|
||||
|
||||
migrate_integrations(opts)
|
||||
|
||||
local intg = opts.integrations or {}
|
||||
local fugitive_defaults = { horizontal = 'du', vertical = 'dU' }
|
||||
if intg.fugitive == true then
|
||||
intg.fugitive = vim.deepcopy(fugitive_defaults)
|
||||
elseif type(intg.fugitive) == 'table' then
|
||||
intg.fugitive = vim.tbl_extend('keep', intg.fugitive, fugitive_defaults)
|
||||
if opts.fugitive == true then
|
||||
opts.fugitive = vim.deepcopy(fugitive_defaults)
|
||||
elseif type(opts.fugitive) == 'table' then
|
||||
opts.fugitive = vim.tbl_extend('keep', opts.fugitive, fugitive_defaults)
|
||||
end
|
||||
|
||||
if intg.neogit == true then
|
||||
intg.neogit = {}
|
||||
if opts.neogit == true then
|
||||
opts.neogit = {}
|
||||
end
|
||||
|
||||
if intg.gitsigns == true then
|
||||
intg.gitsigns = {}
|
||||
if opts.gitsigns == true then
|
||||
opts.gitsigns = {}
|
||||
end
|
||||
|
||||
if intg.committia == true then
|
||||
intg.committia = {}
|
||||
if opts.committia == true then
|
||||
opts.committia = {}
|
||||
end
|
||||
|
||||
if intg.telescope == true then
|
||||
intg.telescope = {}
|
||||
if opts.telescope == true then
|
||||
opts.telescope = {}
|
||||
end
|
||||
|
||||
opts.integrations = intg
|
||||
|
||||
vim.validate('debug', opts.debug, function(v)
|
||||
return v == nil or type(v) == 'boolean' or type(v) == 'string'
|
||||
end, 'boolean or string (file path)')
|
||||
vim.validate('hide_prefix', opts.hide_prefix, 'boolean', true)
|
||||
vim.validate('integrations', opts.integrations, 'table', true)
|
||||
local integration_validator = function(v)
|
||||
vim.validate('fugitive', opts.fugitive, function(v)
|
||||
return v == nil or v == false or type(v) == 'table'
|
||||
end
|
||||
for _, key in ipairs(integration_keys) do
|
||||
vim.validate('integrations.' .. key, intg[key], integration_validator, 'table or false')
|
||||
end
|
||||
end, 'table or false')
|
||||
vim.validate('neogit', opts.neogit, function(v)
|
||||
return v == nil or v == false or type(v) == 'table'
|
||||
end, 'table or false')
|
||||
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('highlights', opts.highlights, 'table', true)
|
||||
|
||||
|
|
@ -739,13 +704,13 @@ local function init()
|
|||
end
|
||||
end
|
||||
|
||||
if type(intg.fugitive) == 'table' then
|
||||
if type(opts.fugitive) == 'table' then
|
||||
---@type diffs.FugitiveConfig
|
||||
local fug = intg.fugitive
|
||||
vim.validate('integrations.fugitive.horizontal', fug.horizontal, function(v)
|
||||
local fug = opts.fugitive
|
||||
vim.validate('fugitive.horizontal', fug.horizontal, function(v)
|
||||
return v == nil or v == false or type(v) == 'string'
|
||||
end, 'string or false')
|
||||
vim.validate('integrations.fugitive.vertical', fug.vertical, function(v)
|
||||
vim.validate('fugitive.vertical', fug.vertical, function(v)
|
||||
return v == nil or v == false or type(v) == 'string'
|
||||
end, 'string or false')
|
||||
end
|
||||
|
|
@ -969,7 +934,7 @@ function M.attach(bufnr)
|
|||
attached_buffers[bufnr] = true
|
||||
|
||||
local neogit_augroup = nil
|
||||
if config.integrations.neogit and vim.bo[bufnr].filetype:match('^Neogit') then
|
||||
if config.neogit and vim.bo[bufnr].filetype:match('^Neogit') then
|
||||
vim.b[bufnr].neogit_disable_hunk_highlight = true
|
||||
neogit_augroup = vim.api.nvim_create_augroup('diffs_neogit_' .. bufnr, { clear = true })
|
||||
vim.api.nvim_create_autocmd('User', {
|
||||
|
|
@ -1049,19 +1014,19 @@ end
|
|||
---@return diffs.FugitiveConfig|false
|
||||
function M.get_fugitive_config()
|
||||
init()
|
||||
return config.integrations.fugitive
|
||||
return config.fugitive
|
||||
end
|
||||
|
||||
---@return diffs.CommittiaConfig|false
|
||||
function M.get_committia_config()
|
||||
init()
|
||||
return config.integrations.committia
|
||||
return config.committia
|
||||
end
|
||||
|
||||
---@return diffs.TelescopeConfig|false
|
||||
function M.get_telescope_config()
|
||||
init()
|
||||
return config.integrations.telescope
|
||||
return config.telescope
|
||||
end
|
||||
|
||||
---@return diffs.ConflictConfig
|
||||
|
|
|
|||
|
|
@ -5,17 +5,7 @@ vim.g.loaded_diffs = 1
|
|||
|
||||
require('diffs.commands').setup()
|
||||
|
||||
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')
|
||||
local gs_cfg = (vim.g.diffs or {}).gitsigns
|
||||
if gs_cfg == true or type(gs_cfg) == 'table' then
|
||||
if not require('diffs.gitsigns').setup() then
|
||||
vim.api.nvim_create_autocmd('User', {
|
||||
|
|
@ -28,7 +18,7 @@ if gs_cfg == true or type(gs_cfg) == 'table' then
|
|||
end
|
||||
end
|
||||
|
||||
local tel_cfg = get_raw_integration('telescope')
|
||||
local tel_cfg = (vim.g.diffs or {}).telescope
|
||||
if tel_cfg == true or type(tel_cfg) == 'table' then
|
||||
vim.api.nvim_create_autocmd('User', {
|
||||
pattern = 'TelescopePreviewerLoaded',
|
||||
|
|
|
|||
|
|
@ -1654,7 +1654,7 @@ describe('highlight', function()
|
|||
it('applies DiffsClear to headers for combined diffs', function()
|
||||
local bufnr = create_buffer({
|
||||
'diff --combined lua/merge/target.lua',
|
||||
'index abc1234,def5678..a6b9012',
|
||||
'index abc1234,def5678..ghi9012',
|
||||
'--- a/lua/merge/target.lua',
|
||||
'+++ b/lua/merge/target.lua',
|
||||
'@@@ -1,2 -1,2 +1,3 @@@',
|
||||
|
|
@ -1671,7 +1671,7 @@ describe('highlight', function()
|
|||
header_start_line = 1,
|
||||
header_lines = {
|
||||
'diff --combined lua/merge/target.lua',
|
||||
'index abc1234,def5678..a6b9012',
|
||||
'index abc1234,def5678..ghi9012',
|
||||
'--- a/lua/merge/target.lua',
|
||||
'+++ b/lua/merge/target.lua',
|
||||
},
|
||||
|
|
@ -1755,7 +1755,7 @@ describe('highlight', function()
|
|||
it('applies header diff grammar at syntax priority for combined diffs', function()
|
||||
local bufnr = create_buffer({
|
||||
'diff --combined lua/merge/target.lua',
|
||||
'index abc1234,def5678..a6b9012',
|
||||
'index abc1234,def5678..ghi9012',
|
||||
'--- a/lua/merge/target.lua',
|
||||
'+++ b/lua/merge/target.lua',
|
||||
'@@@ -1,2 -1,2 +1,3 @@@',
|
||||
|
|
@ -1772,7 +1772,7 @@ describe('highlight', function()
|
|||
header_start_line = 1,
|
||||
header_lines = {
|
||||
'diff --combined lua/merge/target.lua',
|
||||
'index abc1234,def5678..a6b9012',
|
||||
'index abc1234,def5678..ghi9012',
|
||||
'--- a/lua/merge/target.lua',
|
||||
'+++ b/lua/merge/target.lua',
|
||||
},
|
||||
|
|
@ -1802,7 +1802,7 @@ describe('highlight', function()
|
|||
it('@diff.minus wins over @punctuation.special on combined diff headers', function()
|
||||
local bufnr = create_buffer({
|
||||
'diff --combined lua/merge/target.lua',
|
||||
'index abc1234,def5678..a6b9012',
|
||||
'index abc1234,def5678..ghi9012',
|
||||
'--- a/lua/merge/target.lua',
|
||||
'+++ b/lua/merge/target.lua',
|
||||
'@@@ -1,2 -1,2 +1,3 @@@',
|
||||
|
|
@ -1819,7 +1819,7 @@ describe('highlight', function()
|
|||
header_start_line = 1,
|
||||
header_lines = {
|
||||
'diff --combined lua/merge/target.lua',
|
||||
'index abc1234,def5678..a6b9012',
|
||||
'index abc1234,def5678..ghi9012',
|
||||
'--- a/lua/merge/target.lua',
|
||||
'+++ b/lua/merge/target.lua',
|
||||
},
|
||||
|
|
@ -1862,7 +1862,7 @@ describe('highlight', function()
|
|||
it('applies @keyword.diff on index word for combined diffs', function()
|
||||
local bufnr = create_buffer({
|
||||
'diff --combined lua/merge/target.lua',
|
||||
'index abc1234,def5678..a6b9012',
|
||||
'index abc1234,def5678..ghi9012',
|
||||
'--- a/lua/merge/target.lua',
|
||||
'+++ b/lua/merge/target.lua',
|
||||
'@@@ -1,2 -1,2 +1,3 @@@',
|
||||
|
|
@ -1879,7 +1879,7 @@ describe('highlight', function()
|
|||
header_start_line = 1,
|
||||
header_lines = {
|
||||
'diff --combined lua/merge/target.lua',
|
||||
'index abc1234,def5678..a6b9012',
|
||||
'index abc1234,def5678..ghi9012',
|
||||
'--- a/lua/merge/target.lua',
|
||||
'+++ b/lua/merge/target.lua',
|
||||
},
|
||||
|
|
@ -1908,7 +1908,7 @@ describe('highlight', function()
|
|||
it('applies @constant.diff on result hash for combined diffs', function()
|
||||
local bufnr = create_buffer({
|
||||
'diff --combined lua/merge/target.lua',
|
||||
'index abc1234,def5678..a6b9012',
|
||||
'index abc1234,def5678..ghi9012',
|
||||
'--- a/lua/merge/target.lua',
|
||||
'+++ b/lua/merge/target.lua',
|
||||
'@@@ -1,2 -1,2 +1,3 @@@',
|
||||
|
|
@ -1925,7 +1925,7 @@ describe('highlight', function()
|
|||
header_start_line = 1,
|
||||
header_lines = {
|
||||
'diff --combined lua/merge/target.lua',
|
||||
'index abc1234,def5678..a6b9012',
|
||||
'index abc1234,def5678..ghi9012',
|
||||
'--- a/lua/merge/target.lua',
|
||||
'+++ b/lua/merge/target.lua',
|
||||
},
|
||||
|
|
@ -1934,21 +1934,14 @@ describe('highlight', function()
|
|||
highlight.highlight_hunk(bufnr, ns, hunk, default_opts())
|
||||
|
||||
local extmarks = get_extmarks(bufnr)
|
||||
local has_result_hash = false
|
||||
local has_constant = false
|
||||
for _, mark in ipairs(extmarks) do
|
||||
local d = mark[4]
|
||||
if
|
||||
mark[2] == 1
|
||||
and mark[3] == 23
|
||||
and d
|
||||
and d.hl_group == '@constant.diff'
|
||||
and d.end_col == 30
|
||||
and (d.priority or 0) >= 199
|
||||
then
|
||||
has_result_hash = true
|
||||
if mark[2] == 1 and d and d.hl_group == '@constant.diff' and (d.priority or 0) >= 199 then
|
||||
has_constant = true
|
||||
end
|
||||
end
|
||||
assert.is_true(has_result_hash, '@constant.diff on result hash at cols 23-30')
|
||||
assert.is_true(has_constant, '@constant.diff on result hash')
|
||||
delete_buffer(bufnr)
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -336,45 +336,45 @@ describe('diffs', function()
|
|||
assert.are.same({ 'git', 'gitcommit' }, fts)
|
||||
end)
|
||||
|
||||
it('includes fugitive when integrations.fugitive = true', function()
|
||||
local fts = compute({ integrations = { fugitive = true } })
|
||||
it('includes fugitive when fugitive = true', function()
|
||||
local fts = compute({ fugitive = true })
|
||||
assert.is_true(vim.tbl_contains(fts, 'fugitive'))
|
||||
end)
|
||||
|
||||
it('includes fugitive when integrations.fugitive is a table', function()
|
||||
local fts = compute({ integrations = { fugitive = { horizontal = 'dd' } } })
|
||||
it('includes fugitive when fugitive is a table', function()
|
||||
local fts = compute({ fugitive = { horizontal = 'dd' } })
|
||||
assert.is_true(vim.tbl_contains(fts, 'fugitive'))
|
||||
end)
|
||||
|
||||
it('excludes fugitive when integrations.fugitive = false', function()
|
||||
local fts = compute({ integrations = { fugitive = false } })
|
||||
it('excludes fugitive when fugitive = false', function()
|
||||
local fts = compute({ fugitive = false })
|
||||
assert.is_false(vim.tbl_contains(fts, 'fugitive'))
|
||||
end)
|
||||
|
||||
it('excludes fugitive when integrations.fugitive is nil', function()
|
||||
local fts = compute({ integrations = {} })
|
||||
it('excludes fugitive when fugitive is nil', function()
|
||||
local fts = compute({})
|
||||
assert.is_false(vim.tbl_contains(fts, 'fugitive'))
|
||||
end)
|
||||
|
||||
it('includes neogit filetypes when integrations.neogit = true', function()
|
||||
local fts = compute({ integrations = { neogit = true } })
|
||||
it('includes neogit filetypes when neogit = true', function()
|
||||
local fts = compute({ neogit = true })
|
||||
assert.is_true(vim.tbl_contains(fts, 'NeogitStatus'))
|
||||
assert.is_true(vim.tbl_contains(fts, 'NeogitCommitView'))
|
||||
assert.is_true(vim.tbl_contains(fts, 'NeogitDiffView'))
|
||||
end)
|
||||
|
||||
it('includes neogit filetypes when integrations.neogit is a table', function()
|
||||
local fts = compute({ integrations = { neogit = {} } })
|
||||
it('includes neogit filetypes when neogit is a table', function()
|
||||
local fts = compute({ neogit = {} })
|
||||
assert.is_true(vim.tbl_contains(fts, 'NeogitStatus'))
|
||||
end)
|
||||
|
||||
it('excludes neogit when integrations.neogit = false', function()
|
||||
local fts = compute({ integrations = { neogit = false } })
|
||||
it('excludes neogit when neogit = false', function()
|
||||
local fts = compute({ neogit = false })
|
||||
assert.is_false(vim.tbl_contains(fts, 'NeogitStatus'))
|
||||
end)
|
||||
|
||||
it('excludes neogit when integrations.neogit is nil', function()
|
||||
local fts = compute({ integrations = {} })
|
||||
it('excludes neogit when neogit is nil', function()
|
||||
local fts = compute({})
|
||||
assert.is_false(vim.tbl_contains(fts, 'NeogitStatus'))
|
||||
end)
|
||||
|
||||
|
|
@ -383,31 +383,13 @@ describe('diffs', function()
|
|||
assert.is_true(vim.tbl_contains(fts, 'diff'))
|
||||
end)
|
||||
|
||||
it('combines integrations and extra_filetypes', function()
|
||||
local fts = compute({
|
||||
integrations = { fugitive = true, neogit = true },
|
||||
extra_filetypes = { 'diff' },
|
||||
})
|
||||
it('combines fugitive, neogit, and extra_filetypes', function()
|
||||
local fts = compute({ fugitive = true, neogit = true, extra_filetypes = { 'diff' } })
|
||||
assert.is_true(vim.tbl_contains(fts, 'git'))
|
||||
assert.is_true(vim.tbl_contains(fts, 'fugitive'))
|
||||
assert.is_true(vim.tbl_contains(fts, 'NeogitStatus'))
|
||||
assert.is_true(vim.tbl_contains(fts, 'diff'))
|
||||
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)
|
||||
|
||||
describe('diff mode', function()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
require('spec.helpers')
|
||||
|
||||
vim.g.diffs = { integrations = { neogit = true } }
|
||||
vim.g.diffs = { neogit = true }
|
||||
|
||||
local diffs = require('diffs')
|
||||
local parser = require('diffs.parser')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue