diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-07-06 22:25:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-06 22:25:35 +0800 |
commit | bdc6e38781321895331057cbcfb099f8ad31e6db (patch) | |
tree | 94df4cf7cae8e7b347f798e7435fc55845d66d03 /src/nvim/lua/executor.c | |
parent | 34fa54355a50baefe443a00ec4b0d60188445b36 (diff) | |
download | rneovim-bdc6e38781321895331057cbcfb099f8ad31e6db.tar.gz rneovim-bdc6e38781321895331057cbcfb099f8ad31e6db.tar.bz2 rneovim-bdc6e38781321895331057cbcfb099f8ad31e6db.zip |
fix(lua): don't include text after cursor in completion pattern (#29587)
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r-- | src/nvim/lua/executor.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index bac6f4ca9a..c29e670c33 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1928,7 +1928,7 @@ static garray_T expand_result_array = GA_EMPTY_INIT_VALUE; /// Finds matches for Lua cmdline completion and advances xp->xp_pattern after prefix. /// This should be called before xp->xp_pattern is first used. -void nlua_expand_pat(expand_T *xp, const char *pat) +void nlua_expand_pat(expand_T *xp) { lua_State *const lstate = global_lstate; int status = FAIL; @@ -1941,7 +1941,10 @@ void nlua_expand_pat(expand_T *xp, const char *pat) luaL_checktype(lstate, -1, LUA_TFUNCTION); // [ vim, vim._expand_pat, pat ] - lua_pushstring(lstate, pat); + const char *pat = xp->xp_pattern; + assert(xp->xp_line + xp->xp_col >= pat); + ptrdiff_t patlen = xp->xp_line + xp->xp_col - pat; + lua_pushlstring(lstate, pat, (size_t)patlen); if (nlua_pcall(lstate, 1, 2) != 0) { nlua_error(lstate, _("Error executing vim._expand_pat: %.*s")); @@ -1951,8 +1954,8 @@ void nlua_expand_pat(expand_T *xp, const char *pat) Error err = ERROR_INIT; Arena arena = ARENA_EMPTY; - int prefix_len = (int)nlua_pop_Integer(lstate, &arena, &err); - if (ERROR_SET(&err)) { + ptrdiff_t prefix_len = nlua_pop_Integer(lstate, &arena, &err); + if (ERROR_SET(&err) || prefix_len > patlen) { goto cleanup; } |