fix(lua): find length of completion prefix earlier (#29384)

Do the expansion right after setting the expand context, so that the
length of the completion prefix can be set, but don't do that directly
in set_one_cmd_context(), as that's also called by getcmdcompltype().
This commit is contained in:
zeertzjq
2024-06-18 09:47:10 +08:00
committed by GitHub
parent 9d200c78a5
commit 948f2beed4
4 changed files with 89 additions and 26 deletions

View File

@@ -240,6 +240,9 @@ int nextwild(expand_T *xp, int type, int options, bool escape)
if (xp->xp_numfiles == -1) {
set_expand_context(xp);
if (xp->xp_context == EXPAND_LUA) {
nlua_expand_pat(xp, xp->xp_pattern);
}
cmd_showtail = expand_showtail(xp);
}
@@ -287,11 +290,6 @@ int nextwild(expand_T *xp, int type, int options, bool escape)
use_options, type);
xfree(p1);
// xp->xp_pattern might have been modified by ExpandOne (for example,
// in lua completion), so recompute the pattern index and length
i = (int)(xp->xp_pattern - ccline->cmdbuff);
xp->xp_pattern_len = (size_t)ccline->cmdpos - (size_t)i;
// Longest match: make sure it is not shorter, happens with :help.
if (p2 != NULL && type == WILD_LONGEST) {
int j;
@@ -1061,6 +1059,9 @@ int showmatches(expand_T *xp, bool wildmenu)
if (xp->xp_numfiles == -1) {
set_expand_context(xp);
if (xp->xp_context == EXPAND_LUA) {
nlua_expand_pat(xp, xp->xp_pattern);
}
int i = expand_cmdline(xp, ccline->cmdbuff, ccline->cmdpos,
&numMatches, &matches);
showtail = expand_showtail(xp);
@@ -2797,8 +2798,7 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM
}
if (xp->xp_context == EXPAND_LUA) {
ILOG("PAT %s", pat);
return nlua_expand_pat(xp, pat, numMatches, matches);
return nlua_expand_get_matches(numMatches, matches);
}
if (!fuzzy) {
@@ -3610,7 +3610,10 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
theend:
;
if (xpc.xp_context == EXPAND_LUA) {
nlua_expand_pat(&xpc, xpc.xp_pattern);
xpc.xp_pattern_len = strlen(xpc.xp_pattern);
}
char *pat;
if (cmdline_fuzzy_completion_supported(&xpc)) {
// when fuzzy matching, don't modify the search string