comparison src/edit.c @ 16127:0375e54f0adc v8.1.1068

patch 8.1.1068: cannot get all the information about current completion commit https://github.com/vim/vim/commit/fd133323d4e1cc9c0e61c0ce357df4d36ea148e3 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Mar 29 12:20:27 2019 +0100 patch 8.1.1068: cannot get all the information about current completion Problem: Cannot get all the information about current completion. Solution: Add complete_info(). (Shougo, Hirohito Higashi, closes https://github.com/vim/vim/issues/4106)
author Bram Moolenaar <Bram@vim.org>
date Fri, 29 Mar 2019 12:30:06 +0100
parents 5c5d211bd5a8
children 570a296aa0b4
comparison
equal deleted inserted replaced
16126:b792e47f7a2d 16127:0375e54f0adc
13 13
14 #include "vim.h" 14 #include "vim.h"
15 15
16 #ifdef FEAT_INS_EXPAND 16 #ifdef FEAT_INS_EXPAND
17 /* 17 /*
18 * definitions used for CTRL-X submode 18 * Definitions used for CTRL-X submode.
19 * Note: If you change CTRL-X submode, you must also maintain ctrl_x_msgs[] and
20 * ctrl_x_mode_names[].
19 */ 21 */
20 # define CTRL_X_WANT_IDENT 0x100 22 # define CTRL_X_WANT_IDENT 0x100
21 23
22 # define CTRL_X_NORMAL 0 /* CTRL-N CTRL-P completion, default */ 24 # define CTRL_X_NORMAL 0 /* CTRL-N CTRL-P completion, default */
23 # define CTRL_X_NOT_DEFINED_YET 1 25 # define CTRL_X_NOT_DEFINED_YET 1
38 # define CTRL_X_EVAL 16 /* for builtin function complete() */ 40 # define CTRL_X_EVAL 16 /* for builtin function complete() */
39 41
40 # define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT] 42 # define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
41 # define CTRL_X_MODE_LINE_OR_EVAL(m) ((m) == CTRL_X_WHOLE_LINE || (m) == CTRL_X_EVAL) 43 # define CTRL_X_MODE_LINE_OR_EVAL(m) ((m) == CTRL_X_WHOLE_LINE || (m) == CTRL_X_EVAL)
42 44
43 /* Message for CTRL-X mode, index is ctrl_x_mode. */ 45 // Message for CTRL-X mode, index is ctrl_x_mode.
44 static char *ctrl_x_msgs[] = 46 static char *ctrl_x_msgs[] =
45 { 47 {
46 N_(" Keyword completion (^N^P)"), /* CTRL_X_NORMAL, ^P/^N compl. */ 48 N_(" Keyword completion (^N^P)"), // CTRL_X_NORMAL, ^P/^N compl.
47 N_(" ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)"), 49 N_(" ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)"),
48 NULL, /* CTRL_X_SCROLL: depends on state */ 50 NULL, // CTRL_X_SCROLL: depends on state
49 N_(" Whole line completion (^L^N^P)"), 51 N_(" Whole line completion (^L^N^P)"),
50 N_(" File name completion (^F^N^P)"), 52 N_(" File name completion (^F^N^P)"),
51 N_(" Tag completion (^]^N^P)"), 53 N_(" Tag completion (^]^N^P)"),
52 N_(" Path pattern completion (^N^P)"), 54 N_(" Path pattern completion (^N^P)"),
53 N_(" Definition completion (^D^N^P)"), 55 N_(" Definition completion (^D^N^P)"),
54 NULL, /* CTRL_X_FINISHED */ 56 NULL, // CTRL_X_FINISHED
55 N_(" Dictionary completion (^K^N^P)"), 57 N_(" Dictionary completion (^K^N^P)"),
56 N_(" Thesaurus completion (^T^N^P)"), 58 N_(" Thesaurus completion (^T^N^P)"),
57 N_(" Command-line completion (^V^N^P)"), 59 N_(" Command-line completion (^V^N^P)"),
58 N_(" User defined completion (^U^N^P)"), 60 N_(" User defined completion (^U^N^P)"),
59 N_(" Omni completion (^O^N^P)"), 61 N_(" Omni completion (^O^N^P)"),
60 N_(" Spelling suggestion (s^N^P)"), 62 N_(" Spelling suggestion (s^N^P)"),
61 N_(" Keyword Local completion (^N^P)"), 63 N_(" Keyword Local completion (^N^P)"),
62 NULL, /* CTRL_X_EVAL doesn't use msg. */ 64 NULL, // CTRL_X_EVAL doesn't use msg.
63 }; 65 };
66
67 static char *ctrl_x_mode_names[] = {
68 "keyword",
69 "ctrl_x",
70 "unknown", // CTRL_X_SCROLL
71 "whole_line",
72 "files",
73 "tags",
74 "path_patterns",
75 "path_defines",
76 "unknown", // CTRL_X_FINISHED
77 "dictionary",
78 "thesaurus",
79 "cmdline",
80 "function",
81 "omni",
82 "spell",
83 NULL, // CTRL_X_LOCAL_MSG only used in "ctrl_x_msgs"
84 "eval"
85 };
86
64 87
65 static char e_hitend[] = N_("Hit end of paragraph"); 88 static char e_hitend[] = N_("Hit end of paragraph");
66 # ifdef FEAT_COMPL_FUNC 89 # ifdef FEAT_COMPL_FUNC
67 static char e_complwin[] = N_("E839: Completion function changed window"); 90 static char e_complwin[] = N_("E839: Completion function changed window");
68 static char e_compldel[] = N_("E840: Completion function deleted text"); 91 static char e_compldel[] = N_("E840: Completion function deleted text");
161 static int pum_wanted(void); 184 static int pum_wanted(void);
162 static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir); 185 static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir);
163 static char_u *find_line_end(char_u *ptr); 186 static char_u *find_line_end(char_u *ptr);
164 static void ins_compl_free(void); 187 static void ins_compl_free(void);
165 static void ins_compl_clear(void); 188 static void ins_compl_clear(void);
189 static char_u *ins_compl_mode(void);
166 static int ins_compl_bs(void); 190 static int ins_compl_bs(void);
167 static int ins_compl_need_restart(void); 191 static int ins_compl_need_restart(void);
168 static void ins_compl_new_leader(void); 192 static void ins_compl_new_leader(void);
169 static void ins_compl_addleader(int c); 193 static void ins_compl_addleader(int c);
170 static int ins_compl_len(void); 194 static int ins_compl_len(void);
3521 */ 3545 */
3522 int 3546 int
3523 ins_compl_active(void) 3547 ins_compl_active(void)
3524 { 3548 {
3525 return compl_started; 3549 return compl_started;
3550 }
3551
3552
3553 /*
3554 * Get complete information
3555 */
3556 void
3557 get_complete_info(list_T *what_list, dict_T *retdict)
3558 {
3559 int ret = OK;
3560 listitem_T *item;
3561 #define CI_WHAT_MODE 0x01
3562 #define CI_WHAT_PUM_VISIBLE 0x02
3563 #define CI_WHAT_ITEMS 0x04
3564 #define CI_WHAT_SELECTED 0x08
3565 #define CI_WHAT_INSERTED 0x10
3566 #define CI_WHAT_ALL 0xff
3567 int what_flag;
3568
3569 if (what_list == NULL)
3570 what_flag = CI_WHAT_ALL;
3571 else
3572 {
3573 what_flag = 0;
3574 for (item = what_list->lv_first; item != NULL; item = item->li_next)
3575 {
3576 char_u *what = tv_get_string(&item->li_tv);
3577
3578 if (STRCMP(what, "mode") == 0)
3579 what_flag |= CI_WHAT_MODE;
3580 else if (STRCMP(what, "pum_visible") == 0)
3581 what_flag |= CI_WHAT_PUM_VISIBLE;
3582 else if (STRCMP(what, "items") == 0)
3583 what_flag |= CI_WHAT_ITEMS;
3584 else if (STRCMP(what, "selected") == 0)
3585 what_flag |= CI_WHAT_SELECTED;
3586 else if (STRCMP(what, "inserted") == 0)
3587 what_flag |= CI_WHAT_INSERTED;
3588 }
3589 }
3590
3591 if (ret == OK && (what_flag & CI_WHAT_MODE))
3592 ret = dict_add_string(retdict, "mode", ins_compl_mode());
3593
3594 if (ret == OK && (what_flag & CI_WHAT_PUM_VISIBLE))
3595 ret = dict_add_number(retdict, "pum_visible", pum_visible());
3596
3597 if (ret == OK && (what_flag & CI_WHAT_ITEMS))
3598 {
3599 list_T *li;
3600 dict_T *di;
3601 compl_T *match;
3602
3603 li = list_alloc();
3604 if (li == NULL)
3605 return;
3606 ret = dict_add_list(retdict, "items", li);
3607 if (ret == OK && compl_first_match != NULL)
3608 {
3609 match = compl_first_match;
3610 do
3611 {
3612 if (!(match->cp_flags & ORIGINAL_TEXT))
3613 {
3614 di = dict_alloc();
3615 if (di == NULL)
3616 return;
3617 ret = list_append_dict(li, di);
3618 if (ret != OK)
3619 return;
3620 dict_add_string(di, "word", match->cp_str);
3621 dict_add_string(di, "abbr", match->cp_text[CPT_ABBR]);
3622 dict_add_string(di, "menu", match->cp_text[CPT_MENU]);
3623 dict_add_string(di, "kind", match->cp_text[CPT_KIND]);
3624 dict_add_string(di, "info", match->cp_text[CPT_INFO]);
3625 dict_add_string(di, "user_data",
3626 match->cp_text[CPT_USER_DATA]);
3627 }
3628 match = match->cp_next;
3629 }
3630 while (match != NULL && match != compl_first_match);
3631 }
3632 }
3633
3634 if (ret == OK && (what_flag & CI_WHAT_SELECTED))
3635 ret = dict_add_number(retdict, "selected", (compl_curr_match != NULL) ?
3636 compl_curr_match->cp_number - 1 : -1);
3637
3638 // TODO
3639 // if (ret == OK && (what_flag & CI_WHAT_INSERTED))
3640 }
3641
3642 /*
3643 * Return Insert completion mode name string
3644 */
3645 static char_u *
3646 ins_compl_mode(void)
3647 {
3648 if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET || compl_started)
3649 return (char_u *)ctrl_x_mode_names[ctrl_x_mode & ~CTRL_X_WANT_IDENT];
3650
3651 return (char_u *)"";
3526 } 3652 }
3527 3653
3528 /* 3654 /*
3529 * Delete one character before the cursor and show the subset of the matches 3655 * Delete one character before the cursor and show the subset of the matches
3530 * that match the word that is now before the cursor. 3656 * that match the word that is now before the cursor.