Skip to content

Conversation

Shougo
Copy link
Contributor

@Shougo Shougo commented Jan 26, 2019

I have added complete_mode() API.
It returns current ctrl_x mode as string.

It is useful for auto completion plugin.

@codecov-io
Copy link

codecov-io commented Jan 26, 2019

Codecov Report

Merging #3866 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/edit.c 86.18% <100%> (+0.05%) ⬆️
src/evalfunc.c 88.7% <100%> (ø) ⬆️
src/if_xcmdsrv.c 83.48% <0%> (-0.54%) ⬇️
src/ex_cmds.c 81.63% <0%> (-0.1%) ⬇️
src/os_unix.c 58.98% <0%> (-0.1%) ⬇️
src/ui.c 50.14% <0%> (-0.08%) ⬇️
src/gui.c 58.1% <0%> (-0.06%) ⬇️
src/gui_gtk_x11.c 48.37% <0%> (-0.05%) ⬇️
src/terminal.c 79% <0%> (-0.05%) ⬇️
src/ex_docmd.c 80.6% <0%> (+0.01%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cbef8e1...7291887. Read the comment docs.

src/edit.c Outdated
{
case 0:
// Keyword completion
mode = strdup("keyword");
Copy link
Member

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.

endfor
call delete('dummy.txt')

function! s:complTestEval() abort
Copy link
Member

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".

call complete(1, ['source', 'soundfold'])
return ''
endfunction
inoremap <F6> <c-r>=s:complTestEval()<CR>
Copy link
Member

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.

@@ -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>
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or put <buffer>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it seems better.

inoremap <f5> <c-r>=complete_mode()<cr>
call writefile([
\ '!rm src/testdir/amiga.vim /^cmap !rm !Delete all$/;" m',
\], 'dummy.txt')
Copy link
Member

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.

*complete_mode()*
complete_mode()
Return a string that indicates the current completion mode.
Note: It does not check popup menu is visible.
Copy link
Member

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

@Shougo
Copy link
Contributor Author

Shougo commented Jan 26, 2019

I have fixed for reviews.

@mattn
Copy link
Member

mattn commented Jan 26, 2019

Totally, char_u* should be used instead of char* ?

@Shougo
Copy link
Contributor Author

Shougo commented Jan 26, 2019

OK. I have changed.

@brammool
Copy link
Contributor

brammool commented Jan 26, 2019 via email

@Shougo
Copy link
Contributor Author

Shougo commented Jan 27, 2019

Thank you for the review.
I have changed the implementation to use table.

@brammool
Copy link
Contributor

brammool commented Jan 27, 2019 via email

@Shougo
Copy link
Contributor Author

Shougo commented Jan 28, 2019

OK. I have fixed it.

@h-east
Copy link
Member

h-east commented Jan 28, 2019

It does not seem to be reflected here.
https://groups.google.com/d/msg/vim_dev/6utE1ObSYY8/fOaLtsBUGwAJ

@Shougo
Copy link
Contributor Author

Shougo commented Jan 28, 2019

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;
}
Copy link
Member

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 *)"";

@h-east
Copy link
Member

h-east commented Jan 29, 2019

It is better to overwrite by my patch as is.
Check the contents of my patch more.

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 :)

Copy link
Member

@h-east h-east left a 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
Copy link
Member

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

Copy link
Contributor Author

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?

"files" File names |i_CTRL-X_CTRL-F|
"tags" Tags |i_CTRL-X_CTRL-]|
"path_defines"
Definition completion |i_CTRL-X_CTRL-D|
Copy link
Member

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.

"path_defines"
Definition completion |i_CTRL-X_CTRL-D|
"path_patterns"
Include completion |i_CTRL-X_CTRL-I|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same above.

@@ -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);
Copy link
Member

@h-east h-east Feb 2, 2019

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'],
Copy link
Member

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'],

Copy link
Contributor Author

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];
Copy link
Member

@h-east h-east Feb 2, 2019

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 *).

@prabirshrestha
Copy link

I would also be interested in this patch.

I do see Bram's comment on

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.

One option would be to have complete_info() that returns the following. Feel free to suggest better names.

{
    "mode": "omni",
    "items": [],
    "selected": -1, // index of items
    "height": 10,
    "width": 20
}

For start we could only return {"mode": "omni" } and add others as needed. We can add docs that says to check of key before accessing it.

@Shougo
Copy link
Contributor Author

Shougo commented Mar 10, 2019

I have renamed complete_mode() to complete_info().

Patch to add complete_mode(). Shougo - #3866. Alternate patch by Hirohito
Higashi, 2019 Jan 27, included now?

@brammool I have already included Higashi's patch.

@h-east
Copy link
Member

h-east commented Mar 10, 2019

@Shougo
Do NOT use my patch.
I'll Pull Request for a few days

--
Best regards,
Hirohito Higashi (h_east)

@@ -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

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

@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dictionary instead of string

@Shougo Shougo changed the title Add complete_mode() Add complete_info() Mar 10, 2019
@Shougo Shougo changed the title Add complete_info() Add complete_info() Mar 10, 2019
@mattn
Copy link
Member

mattn commented Mar 11, 2019

I think this is enough to merge.

@prabirshrestha
Copy link

Verified that this patch works for asyncomplete v2 to ignore processing autocomplete if it is open due to vim's builtin completions. :shipit:

@Shougo
Copy link
Contributor Author

Shougo commented Mar 18, 2019

#4106 (comment)

I sent a patch that was almost completely rewritten on # 3866.
Despite the reviews I have repeatedly made, he kept subtle.
(and he has never said thanks-word)

OK. Thank you for your review.
I know your patch is better.

But you have said in other place "Your patch implementation is very bad. My patch should be included instead".
So I was stubborn sorry.

I will close the PR.

Note: He have blocked me in github. So I cannot comment the issue.

@Shougo Shougo closed this Mar 18, 2019
@Shougo Shougo deleted the complete_mode branch March 18, 2019 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants