vim-patch:9.1.1876: pre-inserted text not exposed in complete_info() (#36342)

Problem:  pre-inserted text not exposed in complete_info()
Solution: Add the pre-inserted text to the complete_info() Vim script
          function (Girish Palya)

closes: vim/vim#18571

Feat: expose preinserted text in complete_info()

ef5bf58d8c

Co-authored-by: Girish Palya <girishji@gmail.com>
This commit is contained in:
zeertzjq
2025-10-27 09:34:52 +08:00
committed by GitHub
parent fb6fd17f26
commit 155efabb15
6 changed files with 74 additions and 32 deletions

View File

@@ -1420,10 +1420,8 @@ M.funcs = {
Returns a |Dictionary| with information about Insert mode
completion. See |ins-completion|.
The items are:
mode Current completion mode name string.
See |complete_info_mode| for the values.
pum_visible |TRUE| if popup menu is visible.
See |pumvisible()|.
completed Return a dictionary containing the entries of
the currently selected index item.
items List of all completion candidates. Each item
is a dictionary containing the entries "word",
"abbr", "menu", "kind", "info" and
@@ -1434,13 +1432,18 @@ M.funcs = {
and "items" are in "what", the returned list
will still be named "items", but each item
will have an additional "match" field.
mode Current completion mode name string.
See |complete_info_mode| for the values.
preinserted_text
The actual text that is pre-inserted, see
|preinserted()|.
pum_visible |TRUE| if popup menu is visible.
See |pumvisible()|.
selected Selected item index. First index is zero.
Index is -1 if no item is selected (showing
typed text only, or the last completion after
no item is selected when using the <Up> or
<Down> keys)
completed Return a dictionary containing the entries of
the currently selected index item.
preview_winid Info floating preview window id.
preview_bufnr Info floating preview buffer id.

View File

@@ -3643,13 +3643,14 @@ static void fill_complete_info_dict(dict_T *di, compl_T *match, bool add_match)
/// Get complete information
static void get_complete_info(list_T *what_list, dict_T *retdict)
{
#define CI_WHAT_MODE 0x01
#define CI_WHAT_PUM_VISIBLE 0x02
#define CI_WHAT_ITEMS 0x04
#define CI_WHAT_SELECTED 0x08
#define CI_WHAT_COMPLETED 0x10
#define CI_WHAT_MATCHES 0x20
#define CI_WHAT_ALL 0xff
#define CI_WHAT_MODE 0x01
#define CI_WHAT_PUM_VISIBLE 0x02
#define CI_WHAT_ITEMS 0x04
#define CI_WHAT_SELECTED 0x08
#define CI_WHAT_COMPLETED 0x10
#define CI_WHAT_MATCHES 0x20
#define CI_WHAT_PREINSERTED_TEXT 0x40
#define CI_WHAT_ALL 0xff
int what_flag;
if (what_list == NULL) {
@@ -3671,6 +3672,8 @@ static void get_complete_info(list_T *what_list, dict_T *retdict)
what_flag |= CI_WHAT_SELECTED;
} else if (strcmp(what, "completed") == 0) {
what_flag |= CI_WHAT_COMPLETED;
} else if (strcmp(what, "preinserted_text") == 0) {
what_flag |= CI_WHAT_PREINSERTED_TEXT;
} else if (strcmp(what, "matches") == 0) {
what_flag |= CI_WHAT_MATCHES;
}
@@ -3686,6 +3689,13 @@ static void get_complete_info(list_T *what_list, dict_T *retdict)
ret = tv_dict_add_nr(retdict, S_LEN("pum_visible"), pum_visible());
}
if (ret == OK && (what_flag & CI_WHAT_PREINSERTED_TEXT)) {
char *line = get_cursor_line_ptr();
int len = compl_ins_end_col - curwin->w_cursor.col;
ret = tv_dict_add_str_len(retdict, S_LEN("preinserted_text"),
len > 0 ? line + curwin->w_cursor.col : "", len);
}
if (ret == OK && (what_flag & (CI_WHAT_ITEMS|CI_WHAT_SELECTED
|CI_WHAT_MATCHES|CI_WHAT_COMPLETED))) {
list_T *li = NULL;