From 36ea0ce27982e61b42ef108e27be5741cbec4f12 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Sat, 1 Jun 2024 17:10:52 +0200 Subject: [PATCH] autocommand to disable diagnostics on git conflict --- lua/custom/plugins/conflictmarker.lua | 30 ++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lua/custom/plugins/conflictmarker.lua b/lua/custom/plugins/conflictmarker.lua index ecb212a..4f083ce 100644 --- a/lua/custom/plugins/conflictmarker.lua +++ b/lua/custom/plugins/conflictmarker.lua @@ -12,4 +12,32 @@ vim.cmd 'highlight ConflictMarkerTheirs guibg=#344f69' vim.cmd 'highlight ConflictMarkerEnd guibg=#2f628e' vim.cmd 'highlight ConflictMarkerCommonAncestorsHunk guibg=#754a81' -return { 'rhysd/conflict-marker.vim' } +-- Git conflict marker management plugin +return { + 'rhysd/conflict-marker.vim', + config = function() + -- Read all lines in buffer, check if there is any conflict marker + function git_conflict_detection() + local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) + -- Check if strict regex is contained in any line + local beginning = vim.fn.match(lines, vim.g.conflict_marker_begin) + local ending = vim.fn.match(lines, vim.g.conflict_marker_end) + if beginning > -1 or ending > -1 then + vim.diagnostic.enable(false) + else + vim.diagnostic.enable(true) + end + end + + -- Autocommand to disable diagnostics on buffer enter + vim.api.nvim_create_autocmd('BufRead', { + group = vim.api.nvim_create_augroup('git-conflict-lsp-disable', { clear = true }), + callback = git_conflict_detection, + }) + -- Autocommand to disable diagnostics on save + vim.api.nvim_create_autocmd('BufWritePre', { + group = vim.api.nvim_create_augroup('git-conflict-lsp-disable', { clear = false }), + callback = git_conflict_detection, + }) + end, +}