Skip to content

Commit

Permalink
feat(api): add conflict_count function (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
daanvdk committed Jan 3, 2024
1 parent 8962619 commit 599d380
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ vim.keymap.set('n', '[x', '<Plug>(git-conflict-next-conflict)')

</details>

## API

This plugin exposes an API to extract some of the data it collects for other
purposes.

<details><summary>conflict_count({bufnr})</summary>

```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.
```
</details>

## Issues

**Please read this** — This plugin is not intended to do anything other than provide fancy visuals, and some mappings to handle conflict resolution
Expand Down
10 changes: 10 additions & 0 deletions lua/git-conflict.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 599d380

Please sign in to comment.