From 599d3809ea3bf1ef26c8368bfc74c50c44f39913 Mon Sep 17 00:00:00 2001 From: Daan van der Kallen Date: Wed, 3 Jan 2024 14:15:21 +0100 Subject: [PATCH] feat(api): add conflict_count function (#75) --- README.md | 20 ++++++++++++++++++++ lua/git-conflict.lua | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/README.md b/README.md index aafdb40..32151f4 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,26 @@ vim.keymap.set('n', '[x', '(git-conflict-next-conflict)') +## API + +This plugin exposes an API to extract some of the data it collects for other +purposes. + +
conflict_count({bufnr}) + +```vimdoc + Returns the amount of conflicts in a given buffer. + + + Parameters: + {bufnr} (number) Specify the buffer for which you want to know the + amount of conflicts (default: current buffer). + + Return: + number: The amount of conflicts. +``` +
+ ## Issues **Please read this** — This plugin is not intended to do anything other than provide fancy visuals, and some mappings to handle conflict resolution diff --git a/lua/git-conflict.lua b/lua/git-conflict.lua index 89d1e5a..509ed42 100644 --- a/lua/git-conflict.lua +++ b/lua/git-conflict.lua @@ -775,4 +775,14 @@ end function M.debug_watchers() vim.pretty_print({ watchers = watchers }) end +function M.conflict_count(bufnr) + if bufnr and not api.nvim_buf_is_valid(bufnr) then return 0 end + bufnr = bufnr or 0 + + local name = api.nvim_buf_get_name(bufnr) + if not visited_buffers[name] then return 0 end + + return #visited_buffers[name].positions +end + return M