mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat(vim.diff): allow passing an integer for linematch
This commit is contained in:
parent
e826d09c18
commit
9e7426718b
@ -685,9 +685,10 @@ vim.diff({a}, {b}, {opts}) *vim.diff()*
|
|||||||
• "unified": (default) String in unified format.
|
• "unified": (default) String in unified format.
|
||||||
• "indices": Array of hunk locations.
|
• "indices": Array of hunk locations.
|
||||||
Note: This option is ignored if `on_hunk` is used.
|
Note: This option is ignored if `on_hunk` is used.
|
||||||
• `linematch` (boolean): Run linematch on the resulting hunks
|
• `linematch` (boolean|integer): Run linematch on the resulting hunks
|
||||||
from xdiff. Requires `result_type = indices`, ignored
|
from xdiff. When integer, only hunks upto this size in
|
||||||
otherwise.
|
lines are run through linematch. Requires `result_type = indices`,
|
||||||
|
ignored otherwise.
|
||||||
• `algorithm` (string):
|
• `algorithm` (string):
|
||||||
Diff algorithm to use. Values:
|
Diff algorithm to use. Values:
|
||||||
• "myers" the default algorithm
|
• "myers" the default algorithm
|
||||||
|
@ -32,7 +32,7 @@ typedef struct {
|
|||||||
Error *err;
|
Error *err;
|
||||||
mmfile_t *ma;
|
mmfile_t *ma;
|
||||||
mmfile_t *mb;
|
mmfile_t *mb;
|
||||||
bool linematch;
|
int64_t linematch;
|
||||||
bool iwhite;
|
bool iwhite;
|
||||||
} hunkpriv_t;
|
} hunkpriv_t;
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ static int hunk_locations_cb(long start_a, long count_a, long start_b, long coun
|
|||||||
{
|
{
|
||||||
hunkpriv_t *priv = (hunkpriv_t *)cb_data;
|
hunkpriv_t *priv = (hunkpriv_t *)cb_data;
|
||||||
lua_State *lstate = priv->lstate;
|
lua_State *lstate = priv->lstate;
|
||||||
if (priv->linematch) {
|
if (priv->linematch > 0 && count_a + count_b <= priv->linematch) {
|
||||||
get_linematch_results(lstate, priv->ma, priv->mb, start_a, count_a, start_b, count_b,
|
get_linematch_results(lstate, priv->ma, priv->mb, start_a, count_a, start_b, count_b,
|
||||||
priv->iwhite);
|
priv->iwhite);
|
||||||
} else {
|
} else {
|
||||||
@ -208,7 +208,7 @@ static bool check_xdiff_opt(ObjectType actType, ObjectType expType, const char *
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, xdemitconf_t *cfg, xpparam_t *params,
|
static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, xdemitconf_t *cfg, xpparam_t *params,
|
||||||
bool *linematch, Error *err)
|
int64_t *linematch, Error *err)
|
||||||
{
|
{
|
||||||
const DictionaryOf(LuaRef) opts = nlua_pop_Dictionary(lstate, true, err);
|
const DictionaryOf(LuaRef) opts = nlua_pop_Dictionary(lstate, true, err);
|
||||||
|
|
||||||
@ -265,8 +265,12 @@ static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, xdemitconf_t *cfg,
|
|||||||
}
|
}
|
||||||
cfg->interhunkctxlen = (long)v->data.integer;
|
cfg->interhunkctxlen = (long)v->data.integer;
|
||||||
} else if (strequal("linematch", k.data)) {
|
} else if (strequal("linematch", k.data)) {
|
||||||
*linematch = api_object_to_bool(*v, "linematch", false, err);
|
if (v->type == kObjectTypeBoolean) {
|
||||||
if (ERROR_SET(err)) {
|
*linematch = v->data.boolean ? INT64_MAX : 0;
|
||||||
|
} else if (v->type == kObjectTypeInteger) {
|
||||||
|
*linematch = v->data.integer;
|
||||||
|
} else {
|
||||||
|
api_set_error(err, kErrorTypeValidation, "linematch must be a boolean or integer");
|
||||||
goto exit_1;
|
goto exit_1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -330,7 +334,7 @@ int nlua_xdl_diff(lua_State *lstate)
|
|||||||
xdemitconf_t cfg;
|
xdemitconf_t cfg;
|
||||||
xpparam_t params;
|
xpparam_t params;
|
||||||
xdemitcb_t ecb;
|
xdemitcb_t ecb;
|
||||||
bool linematch = false;
|
int64_t linematch = 0;
|
||||||
|
|
||||||
CLEAR_FIELD(cfg);
|
CLEAR_FIELD(cfg);
|
||||||
CLEAR_FIELD(params);
|
CLEAR_FIELD(params);
|
||||||
|
Loading…
Reference in New Issue
Block a user