-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add complete_info() #3866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add complete_info() #3866
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3866 +/- ##
==========================================
- Coverage 79.22% 79.22% -0.01%
==========================================
Files 105 105
Lines 141158 141166 +8
==========================================
+ Hits 111837 111842 +5
- Misses 29321 29324 +3
Continue to review full report at Codecov.
|
src/edit.c
Outdated
{ | ||
case 0: | ||
// Keyword completion | ||
mode = strdup("keyword"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vim does not use strdup() which is not portable. It uses vim_strsave() instead.
src/testdir/test_popup.vim
Outdated
endfor | ||
call delete('dummy.txt') | ||
|
||
function! s:complTestEval() abort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vim tests no longer uses the exclamation mark in "function!" but uses "func" … "endfunc".
src/testdir/test_popup.vim
Outdated
call complete(1, ['source', 'soundfold']) | ||
return '' | ||
endfunction | ||
inoremap <F6> <c-r>=s:complTestEval()<CR> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test has a side-effect: it leaks this map. We should do iunmap before exiting the test.
src/testdir/test_popup.vim
Outdated
@@ -896,4 +896,48 @@ func Test_menu_only_exists_in_terminal() | |||
endtry | |||
endfunc | |||
|
|||
func Test_popup_complete_mode() | |||
new | |||
inoremap <f5> <c-r>=complete_mode()<cr> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test has a side-effect: it leaks this map. We should do iunmap before exiting the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or put <buffer>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it seems better.
src/testdir/test_popup.vim
Outdated
inoremap <f5> <c-r>=complete_mode()<cr> | ||
call writefile([ | ||
\ '!rm src/testdir/amiga.vim /^cmap !rm !Delete all$/;" m', | ||
\], 'dummy.txt') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, temporary files created by Vim tests start with X presumably because it makes it easier to spot temporary files which were not removed.
runtime/doc/eval.txt
Outdated
*complete_mode()* | ||
complete_mode() | ||
Return a string that indicates the current completion mode. | ||
Note: It does not check popup menu is visible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not check whether popup menu is visible
I have fixed for reviews. |
Totally, char_u* should be used instead of char* ? |
OK. I have changed. |
I have added `complete_mode()` API.
It returns current ctrl_x mode as string.
It is useful for auto completion plugin.
I wonder if other completion state would be useful. I rather have one
function to get the whole state, than a bunch of functions for several
pieces of state.
Unfortunately, the completion state is very complex, it's not easy to
even explain what each state variable means. I've been meaning to
refactor this, but it's a complex thing.
About the implementation: Instead of using a big switch, it would be
much more compact to use a table with the completion types and string.
Something like:
struct {
int mode;
char *name;
} mode_table = {
{0, "keyword"},
{CTRL_X_FILES, "files"},
};
+// complete_mode() implementation.
+char_u *ins_compl_mode(void)
+{
This should use Vim style function header.
…--
'I generally avoid temptation unless I can't resist it."
-- Mae West
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
Thank you for the review. |
Thank you for the review.
I have changed the implementation to use table.
It's a bit simpler this way:
for (i = 0; i < sizeof(table)/ sizeof(struct mode_table); i++)
if (table[i].mode == ctrl_x_mode)
return (char_u *)table[i].name;
return (char_u *)"unknown";
Please use Vim code style.
…--
MORTICIAN: What?
CUSTOMER: Nothing -- here's your nine pence.
DEAD PERSON: I'm not dead!
MORTICIAN: Here -- he says he's not dead!
CUSTOMER: Yes, he is.
DEAD PERSON: I'm not!
The Quest for the Holy Grail (Monty Python)
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
OK. I have fixed it. |
It does not seem to be reflected here. |
Oh, I have not read your response. I have included (and some changed) your patch. |
src/edit.c
Outdated
|
||
return (char_u *)"unknown"; | ||
return (char_u *)mode; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET || compl_started)
return mode_names[ctrl_x_mode & ~CTRL_X_WANT_IDENT];
return (char_u *)"";
It is better to overwrite by my patch as is. I add to the document, add test cases, simplify the test file (Xdummy.txt), add code comment, and move the definition position of the function (ins_compl_mode) to the appropriate place. Or it may be better for Bram to include my patch :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your arrangement is subtle.
So, did you decide that this is unnecessary?
diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt
index 0431043c2..2bb357ef4 100644
--- a/runtime/doc/insert.txt
+++ b/runtime/doc/insert.txt
@@ -642,6 +642,7 @@ and one of the CTRL-X commands. You exit CTRL-X mode by typing a key that is
not a valid CTRL-X mode command. Valid keys are the CTRL-X command itself,
CTRL-N (next), and CTRL-P (previous).
+To get the current completion mode, |complete_mode()| can be used.
Also see the 'infercase' option if you want to adjust the case of the match.
*complete_CTRL-E*
src/edit.c
Outdated
@@ -3589,6 +3590,36 @@ ins_compl_active(void) | |||
return compl_started; | |||
} | |||
|
|||
// Return Insert completion mode name string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/*
* Return Insert completion mode name string
*/
Why do you get worse?
It has already been pointed out by Bram.
See the document.
:h style-examples
/function_name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has already been pointed out by Bram.
Oh, I have not see it in the issue.
It is pointed in ML thread?
runtime/doc/eval.txt
Outdated
"files" File names |i_CTRL-X_CTRL-F| | ||
"tags" Tags |i_CTRL-X_CTRL-]| | ||
"path_defines" | ||
Definition completion |i_CTRL-X_CTRL-D| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change it? The way it does not break is easier to see.
runtime/doc/eval.txt
Outdated
"path_defines" | ||
Definition completion |i_CTRL-X_CTRL-D| | ||
"path_patterns" | ||
Include completion |i_CTRL-X_CTRL-I| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same above.
src/proto/edit.pro
Outdated
@@ -20,6 +20,7 @@ char_u *find_word_end(char_u *ptr); | |||
int ins_compl_active(void); | |||
int ins_compl_add_tv(typval_T *tv, int dir); | |||
void ins_compl_check_keys(int frequency, int in_compl_func); | |||
char_u *ins_compl_mode(void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is after int ins_compl_active(void);
for [key, expected] in [ | ||
\ ["", ''], | ||
\ ["\<C-X>", 'ctrl_x'], | ||
\ ["\<C-X>\<C-N>", 'keyword'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test case is missing.
\ ["\<C-X>\<C-P>", 'keyword'],
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added it.
src/edit.c
Outdated
}; | ||
|
||
if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET || compl_started) | ||
return mode_names[ctrl_x_mode & ~CTRL_X_WANT_IDENT]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a cast (char_u *)
.
I would also be interested in this patch. I do see Bram's comment on
One option would be to have {
"mode": "omni",
"items": [],
"selected": -1, // index of items
"height": 10,
"width": 20
} For start we could only return |
@Shougo -- |
runtime/doc/eval.txt
Outdated
@@ -2267,6 +2267,7 @@ col({expr}) Number column nr of cursor or mark | |||
complete({startcol}, {matches}) none set Insert mode completion | |||
complete_add({expr}) Number add completion match | |||
complete_check() Number check for key typed during completion | |||
complete_info() String get current completion information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type should be changed to dictionary
runtime/doc/eval.txt
Outdated
@@ -3536,6 +3537,36 @@ complete_check() *complete_check()* | |||
Only to be used by the function specified with the | |||
'completefunc' option. | |||
|
|||
*complete_info()* | |||
complete_info() | |||
Return a string that indicates the current completion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dictionary instead of string
I think this is enough to merge. |
Verified that this patch works for asyncomplete v2 to ignore processing autocomplete if it is open due to vim's builtin completions. |
OK. Thank you for your review. But you have said in other place "Your patch implementation is very bad. My patch should be included instead". I will close the PR. Note: He have blocked me in github. So I cannot comment the issue. |
I have added
complete_mode()
API.It returns current ctrl_x mode as string.
It is useful for auto completion plugin.