CompleteDone and different types of completion

61 views
Skip to first unread message

Paul Jolly

unread,
Jan 15, 2020, 10:37:20 AM1/15/20
to Vim Dev Mailing List
Hi all,

We are using the CompleteDone event in govim
(https://github.com/govim/govim) in order to add import statements
when a user selects a completion candidate (this happens when
completion candidates result from unimported completions in gopls).

However our handler for CompleteDone needs to know whether the event
has been triggered as part of an omni-complete (<C-x><C-o>) or a
<C-x><C-n> completion (not sure if this has a specific name).

There doesn't appear to be a way to distinguish however from the value
v:completed_item.

Are we missing something obvious here?

Many thanks in advance.


Paul

Bram Moolenaar

unread,
Jan 15, 2020, 4:10:34 PM1/15/20
to vim...@googlegroups.com, Paul Jolly
I don't think there is a direct way to get the type of completion.

You could perhaps use the CompleteChanged event and check for user_data
in the completed item.

--
The Characters and incidents portrayed and the names used are fictitious and
any similarity to the names, characters, or history of any person is entirely
accidental and unintentional.
Signed RICHARD M. NIXON
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@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 ///

Prabir Shrestha

unread,
Jan 15, 2020, 8:55:59 PM1/15/20
to vim_dev
I had this same request before. complete_info() should give this info.

Paul Jolly

unread,
Jan 16, 2020, 1:57:52 AM1/16/20
to Vim Dev Mailing List
> I had this same request before. complete_info() should give this info.

Thank you, Prabir - this is exactly what I'm after.

Paul Jolly

unread,
Jan 16, 2020, 4:58:17 AM1/16/20
to Vim Dev Mailing List
> > I had this same request before. complete_info() should give this info.
>
> Thank you, Prabir - this is exactly what I'm after.

Except that when completion has already finished, which is the
situation we're talking about here because we're handling
CompleteDone, then complete_info() returns a "mode" of "".

I think the simplest thing for now is to follow Bram's suggestion of
using user_data.

Bram Moolenaar

unread,
Jan 16, 2020, 1:01:12 PM1/16/20
to vim...@googlegroups.com, Paul Jolly
Hmm, would there be any harm in triggering CompleteDone before resetting
the complete info? I don't think so. Would anyone using the
autocommand event depend on the completion already being cleared?
If yes, then we would need to introduce another event. I rather keep it
simple and have just one event.

--
This message contains 78% recycled characters.

Paul Jolly

unread,
Jan 16, 2020, 4:30:21 PM1/16/20
to Bram Moolenaar, Vim Dev Mailing List
> > I think the simplest thing for now is to follow Bram's suggestion of
> > using user_data.
>
> Hmm, would there be any harm in triggering CompleteDone before resetting
> the complete info? I don't think so. Would anyone using the
> autocommand event depend on the completion already being cleared?
> If yes, then we would need to introduce another event. I rather keep it
> simple and have just one event.

I'm using this function for the first time so I'm not best placed to
comment. But my gut would say no, there should be no harm because you
can still use v:completed_item to determine whether you are
cancelling/accepting; but complete_info() would still give useful
information like mode.

Prabir? Others?

Bram Moolenaar

unread,
Jan 17, 2020, 12:59:51 PM1/17/20
to vim...@googlegroups.com, Paul Jolly
I suppose it's going to be hard to reach the people affected.
Let me make the change and see if someone complains :-).

--
Computers make very fast, very accurate, mistakes.
Reply all
Reply to author
Forward
0 new messages