refactor: remove redundant Git conflict handling logic

This commit is contained in:
2024-10-11 12:48:14 -04:00
parent 8a36aa3602
commit 7ef39df68f
+64 -56
View File
@@ -9,50 +9,50 @@ local autocmd = vim.api.nvim_create_autocmd
-- GIT CONFLICT MARKERS -- GIT CONFLICT MARKERS
-- if there are conflicts, jump to first conflict, highlight conflict markers, -- if there are conflicts, jump to first conflict, highlight conflict markers,
-- and disable diagnostics (simplified version of `git-conflict.nvim`) -- and disable diagnostics (simplified version of `git-conflict.nvim`)
autogrp("GitConflictMarkers", { clear = true }) -- autogrp("GitConflictMarkers", { clear = true })
autocmd({ "BufEnter", "FocusGained" }, { -- autocmd({ "BufEnter", "FocusGained" }, {
group = "GitConflictMarkers", -- group = "GitConflictMarkers",
callback = function(ctx) -- callback = function(ctx)
local hlgroup = "DiagnosticVirtualTextInfo" -- CONFIG -- local hlgroup = "DiagnosticVirtualTextInfo" -- CONFIG
--
if not vim.api.nvim_buf_is_valid(ctx.buf) then -- if not vim.api.nvim_buf_is_valid(ctx.buf) then
return -- return
end -- end
vim.system( -- vim.system(
{ "git", "diff", "--check", "--", vim.api.nvim_buf_get_name(ctx.buf) }, -- { "git", "diff", "--check", "--", vim.api.nvim_buf_get_name(ctx.buf) },
{}, -- {},
vim.schedule_wrap(function(out) -- vim.schedule_wrap(function(out)
local noConflicts = out.code == 0 -- local noConflicts = out.code == 0
local noGitRepo = -- local noGitRepo =
vim.startswith(out.stdout, "warning: Not a git repository") -- vim.startswith(out.stdout, "warning: Not a git repository")
if noConflicts or noGitRepo then -- if noConflicts or noGitRepo then
return -- return
end -- end
--
local ns = vim.api.nvim_create_namespace("conflictMarkers") -- local ns = vim.api.nvim_create_namespace("conflictMarkers")
local firstConflict -- local firstConflict
for conflictLnum in out.stdout:gmatch("(%d+): leftover conflict marker") do -- for conflictLnum in out.stdout:gmatch("(%d+): leftover conflict marker") do
local lnum = tonumber(conflictLnum) -- local lnum = tonumber(conflictLnum)
vim.api.nvim_buf_add_highlight(ctx.buf, ns, hlgroup, lnum - 1, 0, -1) -- vim.api.nvim_buf_add_highlight(ctx.buf, ns, hlgroup, lnum - 1, 0, -1)
if not firstConflict then -- if not firstConflict then
firstConflict = lnum -- firstConflict = lnum
end -- end
end -- end
if not firstConflict then -- if not firstConflict then
return -- return
end -- end
--
vim.api.nvim_win_set_cursor(0, { firstConflict, 0 }) -- vim.api.nvim_win_set_cursor(0, { firstConflict, 0 })
vim.diagnostic.enable(false, { bufnr = ctx.buf }) -- vim.diagnostic.enable(false, { bufnr = ctx.buf })
vim.notify_once( -- vim.notify_once(
"Conflict markers found.", -- "Conflict markers found.",
nil, -- nil,
{ title = "Git Conflicts" } -- { title = "Git Conflicts" }
) -- )
end) -- end)
) -- )
end, -- end,
}) -- })
-- LazyGit root detection -- LazyGit root detection
if pcall(require, "lazygit.utils") then if pcall(require, "lazygit.utils") then
@@ -64,18 +64,6 @@ if pcall(require, "lazygit.utils") then
}) })
end end
-- TodoFzfLua command override to use Telescope
-- when fzf-lua is not installed
autogrp("TodoFzfLua", { clear = true })
autocmd({ "BufEnter" }, {
group = "TodoFzfLua",
callback = function()
if not pcall(require, "fzf-lua") then
vim.cmd([[command! -nargs=* TodoFzfLua :TodoTelescope]])
end
end,
})
-- ━━━━━━━━━━━━━━━━━━━━━━━ Set up Qalc keymappings ━━━━━━━━━━━━━━━━━━━━━━━ -- ━━━━━━━━━━━━━━━━━━━━━━━ Set up Qalc keymappings ━━━━━━━━━━━━━━━━━━━━━━━
if pcall(require, "qalc") then if pcall(require, "qalc") then
-- Create a group for filetype-specific mappings -- Create a group for filetype-specific mappings
@@ -119,3 +107,23 @@ end
local load_highlight = require("utils.highlight") local load_highlight = require("utils.highlight")
load_highlight.setup_autocommands() load_highlight.setup_autocommands()
load_highlight.setup_dashboard_highlight() load_highlight.setup_dashboard_highlight()
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━ Set up nvim_exec ━━━━━━━━━━━━━━━━━━━━━━━
-- Function to check and execute the NVIM_EXEC environment variable
local function execute_nvim_exec()
local exec_command = os.getenv("NVIM_EXEC")
-- If NVIM_EXEC is set, execute the command
if exec_command then
vim.cmd(exec_command)
end
end
-- Define an autogroup for the autocmd
vim.api.nvim_create_augroup("NvimExec", { clear = true })
-- Define an autocmd to run the function at startup
vim.api.nvim_create_autocmd("VimEnter", {
group = "NvimExec",
callback = execute_nvim_exec,
})