Skip to content

Conversation

h-east
Copy link
Member

@h-east h-east commented Mar 12, 2019

Once the specification is decided, refactor, update the document and add more tests.

complete_info([{what}])
		Returns a Dictionary with information about insert mode
		completion.  see |ins-completion|.
		The items are:
		   mode		current completion mode name string.
				See |completion_info_mode| for the values.
		   pum_visible	|TRUE| if popup menu is visible.
				See |pumvisible()|.
		   items	List of completion matches.  Each item is a
				dictionary containing the entries "word",
				"abbr", "menu", "kind", "info" and "user_data".
				See |complete-items|.
		   selected	Selected item index.  First index is zero.
				Set -1 if not selected.
		   inserted	Inserted string. [NOT IMPLEMENT YET]

							*complete_info_mode*
		mode values are:
		   ""		Not in completion mode
		   "keyword"	Keyword completion |i_CTRL-X_CTRL-N|
		   "ctrl_x"	Just press |i_CTRL-X|
		   "whole_line"	Whole lines |i_CTRL-X_CTRL-L|
		   "files"	File names |i_CTRL-X_CTRL-F|
		   "tags"	Tags |i_CTRL-X_CTRL-]|
		   "path_defines"    Definition completion |i_CTRL-X_CTRL-D|
		   "path_patterns"   Include completion |i_CTRL-X_CTRL-I|
		   "dictionary"	Dictionary |i_CTRL-X_CTRL-K|
		   "thesaurus"	Thesaurus |i_CTRL-X_CTRL-T|
		   "cmdline"	Vim Command line completion |i_CTRL-X_CTRL-V|
		   "function"	User defined completion |i_CTRL-X_CTRL-U|
		   "omni"	Omni completion |i_CTRL-X_CTRL-O|
		   "spell"	Spelling suggestions |i_CTRL-X_s|
		   "eval"	|complete()| completion
		   "unknown"	Other internal modes

		If the optional {what} dictionary argument is supplied, then
		only the items listed in {what} are returned.
		Unsupported keys in {what} are ignored.

Related Issue/Thread

#3866
https://groups.google.com/d/msg/vim_dev/6utE1ObSYY8/fOaLtsBUGwAJ

--
Best regards,
Hirohito Higashi (h_east)

@brammool
Copy link
Contributor

brammool commented Mar 13, 2019 via email

@h-east
Copy link
Member Author

h-east commented Mar 14, 2019

@brammool

Is this really useful? In some cases this list can be very long,
slowing down the operation.

I consider this point.
It is possible to avoid it by specifying only the entry you want to get in the argument {what}.

"Index is -1 if no item is selected (showing typed text only)"

Thanks. I'll reflect later.

@prabirshrestha
Copy link

@h-east What is an example of what argument. Do we use it like this? let info = complete_info({ 'mode': v:true })? I think it would be good to have an example of this in docs.

@brammool I think getting items is useful as this would allow plugin authors to enable fuzzy search on it though I have no plans to support this in asyncomplete anytime soon.

@h-east
Copy link
Member Author

h-east commented Mar 16, 2019

@prabirshrestha
Thank you for the suggestion.
I added an example in the document.

                Examples:
                        " Get all items
                        call complete_info()
                        " Get only 'mode'
                        call complete_info({'mode': ''})
                        " Get only 'mode' and 'pum_visible'
                        call complete_info({'mode': '', 'pum_visible': ''})

@codecov-io
Copy link

codecov-io commented Mar 16, 2019

Codecov Report

Merging #4106 into master will decrease coverage by <.01%.
The diff coverage is 88.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4106      +/-   ##
==========================================
- Coverage   79.25%   79.25%   -0.01%     
==========================================
  Files         105      105              
  Lines      141171   141231      +60     
==========================================
+ Hits       111892   111933      +41     
- Misses      29279    29298      +19
Impacted Files Coverage Δ
src/evalfunc.c 88.69% <87.5%> (-0.01%) ⬇️
src/edit.c 86.24% <88.46%> (+0.11%) ⬆️
src/gui.c 58.2% <0%> (-0.37%) ⬇️
src/netbeans.c 27.21% <0%> (-0.3%) ⬇️
src/gui_gtk_x11.c 48.32% <0%> (-0.25%) ⬇️
src/sign.c 93.38% <0%> (-0.13%) ⬇️
src/screen.c 80.34% <0%> (-0.03%) ⬇️
src/ex_docmd.c 80.6% <0%> (+0.01%) ⬆️
src/getchar.c 75.41% <0%> (+0.04%) ⬆️

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 2ba4238...0a14dc6. Read the comment docs.

@andymass
Copy link

@prabirshrestha, can you explain further how having the items field would allow a plugin to implement fuzzy search?

@prabirshrestha
Copy link

@h-east using empty string seems a bit weird because it is mostly falsy empty('') == v:true. I would except something like this instead where 1 or v:true returns the object and 0 or v:false ignores it.

let info = complete_info({ 'items': 1, mode: 0 }) " { items }
let info = complete_info({ 'items': v:true, mode: v:false }) " { items, mode }

@andymass
I haven't tried it but for v2 branch of asyncomplete.vim you could do something like this.

function! s:omni_completor(opt, ctx) abort
    let mode = complete_info({ 'mode': '' })['mode']
    if mode == 'omni'
        let items = complete_info({ 'items': '' })['items']
        let startcol = col('.')
        call asyncomplete#complete(a:opt['name'], a:ctx, startcol, items)
    endif
endfunction

call asyncomplete#register_source({
    \ 'name': 'omnifunc',
    \ 'whitelist': ['*'],
    \ 'completor': function('s:omni_completor'),
    \ })

function! s:myfuzzy_asyncomplete_preprocessor(ctx, matches) abort
    " implement sorting/ranking and fuzzy match on a:matches
    " this function is called before asyncomplete.vim shows the popup
    call asyncomplete#preprocess_complete(a:ctx, l:items)
endfunction

let g:asyncomplete_preprocessor = [function('s:myfuzzy_asyncomplete_preprocessor')]

You would also like to handle pum open autocmd and call asyncomplete#complete if mode is omni but that autocmd doesn't exist yet - #4083. In asyncomplete.vim you can call that as many time as you want anytime.

v2 also now supports preprocessor which runs right before it shows the menu so you can modify the items. https://github.com/prabirshrestha/asyncomplete.vim/blob/f1cc9e3c9e952c666652152c38089c89471f4e18/doc/asyncomplete.txt#L55-L87 This pre-processor runs in every keystroke so you can easily implement fuzzy find. Asyncomplete also caches the sources based on startcol you don't have to worry about checking complete mode all the time. preprocess api is designed to be future compatible which mean you can call asyncomplete#preprocess_complete multiple times as well as asynchronously. You could create a preprocessor that run's in python thread so it doesn't block the UI. This is also why I have been very interested in builtin ducktype ecmascript support with webworkers support. It opens a lot of possibilities like these very easily. Because this preprocessor can now run without changing the core asyncomplete vim plugin it will be interesting to see how others write their own and share. Fuzzy finding is just one piece of the better autocomplete, to make it really shine one needs to implement MRU and ranking for autocomplete.

@brammool
Copy link
Contributor

brammool commented Mar 16, 2019 via email

@prabirshrestha
Copy link

I had thought of array of string but since I would call this function in every keystroke it would need to be fast.

Having said that arrays are still better interms if api.

@wsdjeg
Copy link

wsdjeg commented Mar 17, 2019

Why use new pr? what is the different #4106 and #3866

@h-east
Copy link
Member Author

h-east commented Mar 17, 2019

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

I do not want to waste time with me and Vim developers any more.

@h-east
Copy link
Member Author

h-east commented Mar 17, 2019

@brammool

I don't think it is needed to use a dictionary argument. We can use a
list of strings, that is simpler:
[...]

I made it a dictionary because I referred to {what} of getqflist(), but the list is good for this API.

@brammool
Copy link
Contributor

brammool commented Mar 17, 2019 via email

@vim-ml
Copy link

vim-ml commented Mar 17, 2019 via email

@prabirshrestha
Copy link

prabirshrestha commented Mar 17, 2019

Updated asyncomplete v2 to use the new apis and it works great. prabirshrestha/asyncomplete.vim@623c744

Any chance we can get this PR merged to master soon?

@Shougo Shougo mentioned this pull request Mar 18, 2019
@h-east
Copy link
Member Author

h-east commented Mar 18, 2019

@brammool (cc: @prabirshrestha )
I am busy for about a week, so I can not do this PR's work.
if possible, import as it is or improve.

--
Best regards,
Hirohito Higashi (h_east)

@mattn
Copy link
Member

mattn commented Mar 18, 2019

@prabirshrestha @brammool If you have opinion about this patch, pleaes let me known. I'll take over the work.

@prabirshrestha
Copy link

It is ready to be merged from my side.

@prabirshrestha
Copy link

@brammool Any update on this? Any concerns blocking the merge to master?

@brammool brammool closed this in fd13332 Mar 29, 2019
Shougo added a commit to Shougo/neovim that referenced this pull request Mar 30, 2019
…letion

Problem:    Cannot get all the information about current completion.
Solution:   Add complete_info(). (Shougo, Hirohito Higashi, closes vim/vim#4106)
vim/vim@fd13332
Shougo added a commit to Shougo/neovim that referenced this pull request Mar 30, 2019
…letion

Problem:    Cannot get all the information about current completion.
Solution:   Add complete_info(). (Shougo, Hirohito Higashi, closes vim/vim#4106)
vim/vim@fd13332
Shougo added a commit to Shougo/neovim that referenced this pull request Mar 30, 2019
…letion

Problem:    Cannot get all the information about current completion.
Solution:   Add complete_info(). (Shougo, Hirohito Higashi, closes vim/vim#4106)
vim/vim@fd13332
@h-east h-east deleted the add_complete_info branch March 30, 2019 15:44
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.

8 participants