Skip to content

Commit

Permalink
feat(api): add lua C bindings for xdiff (neovim#14536)
Browse files Browse the repository at this point in the history
* feat(api): add lua C bindings for xdiff

* chore: opt.hunk_lines -> opt.result_type

opt.on_hunk now takes precedence over opt.result_type

* chore: fix indents

Fix indents

* chore: change how priv is managed

Assign priv NULL and unconditionally apply XFREE_CLEAR to it when
finished.
  • Loading branch information
lewis6991 committed Dec 12, 2021
1 parent 06e7124 commit ce01f7c
Show file tree
Hide file tree
Showing 5 changed files with 530 additions and 0 deletions.
67 changes: 67 additions & 0 deletions runtime/doc/lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1581,4 1581,71 @@ uri_to_fname({uri}) *vim.uri_to_fname()*
Return: ~
Filename

==============================================================================
Lua module: diff *lua-diff*

diff({a}, {b}, {opts}) *vim.diff()*
Run diff on strings {a} and {b}. Any indices returned by this
function, either directly or via callback arguments, are
1-based.

Examples: >
vim.diff('a\n', 'b\nc\n')
-->
@@ -1 1,2 @@
-a
b
c
vim.diff('a\n', 'b\nc\n', {hunk_lines = true})
-->
{
{1, 1, 1, 2}
}
<
Parameters: ~
{a} First string to compare
{b} Second string to compare
{opts} Optional parameters:
`on_hunk` (callback):
Invoked for each hunk in the diff. Return a
negative number to cancel the callback for any
remaining hunks.
Args:
`start_a` (integer): Start line of hunk in {a}.
`count_a` (integer): Hunk size in {a}.
`start_b` (integer): Start line of hunk in {b}.
`count_b` (integer): Hunk size in {b}.
`result_type` (string): Form of the returned diff:
• "unified": (default) String in unified format.
• "indices": Array of hunk locations.
Note this option is ignored if `on_hunk` is
used.
`algorithm` (string):
Diff algorithm to use. Values:
• "myers" the default algorithm
• "minimal" spend extra time to generate the
smallest possible diff
• "patience" patience diff algorithm
• "histogram" histogram diff algorithm
`ctxlen` (integer): Context length
`interhunkctxlen` (integer):
Inter hunk context length
`ignore_whitespace` (boolean):
Ignore whitespace
`ignore_whitespace_change` (boolean):
Ignore whitespace change
`ignore_whitespace_change_at_eol` (boolean)
Ignore whitespace change at end-of-line.
`ignore_cr_at_eol` (boolean)
Ignore carriage return at end-of-line
`ignore_blank_lines` (boolean)
Ignore blank lines
`indent_heuristic` (boolean):
Use the indent heuristic for the internal
diff library.

Return: ~
See {opts.result_type}. nil if {opts.on_hunk} is given.

vim:tw=78:ts=8:ft=help:norl:
5 changes: 5 additions & 0 deletions src/nvim/lua/executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 40,7 @@
#include "nvim/lua/converter.h"
#include "nvim/lua/executor.h"
#include "nvim/lua/treesitter.h"
#include "nvim/lua/xdiff.h"

#include "luv/luv.h"

Expand Down Expand Up @@ -517,6 518,10 @@ static int nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
// internal vim._treesitter... API
nlua_add_treesitter(lstate);

// vim.diff
lua_pushcfunction(lstate, &nlua_xdl_diff);
lua_setfield(lstate, -2, "diff");

lua_setglobal(lstate, "vim");

{
Expand Down
Loading

0 comments on commit ce01f7c

Please sign in to comment.