Plugins exposing events to other plugins

40 views
Skip to first unread message

Paul Jolly

unread,
May 26, 2019, 2:49:24 PM5/26/19
to vim...@googlegroups.com
Hi all,

As a brief summary, govim (https://github.com/myitcv/govim) is a
Vim8.1 channel-based plugin, written in Go, that is a Language Server
Protocol (LSP) client
(https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md).
The TL;DR version is that such a plugin can, with the LSP server it
connects to, provide answers on everything from jump-to-definition,
code completion... and much more. This functionality is exposed via
functions, commands and autocmds.

A recent issue raised highlighted the fact that YouCompleteMe (YCM)
does not appear to play well with govim:

https://github.com/myitcv/govim/issues/247

This was effectively tracked down to the fact that both govim and YCM
rely on TextChanged/TextChangedI autocmds to do their work; YCM to
trigger an omnifunc completion when a '.' character is pressed, and
govim to update the LSP server with the latest buffer contents:

https://github.com/Valloric/YouCompleteMe/issues/3408

The issue reported occurs when the YCM TextChangedI autocmd fires
before the govim autocmd; effectively a completion is attempted beyond
the end of a line (in some cases).

Ignoring for one second that there is significant overlap between what
YCM and govim are trying to do here from a completion perspective, it
strikes me that plugins like govim might well want to expose events
that other plugins can hook into. In this case, on such event would be
"post LSP textDocument/didChange" (textDocument/didChange is the LSP
event notified from client -> server when a document loaded in the
editor changes)

Is there a standard means by which plugins like govim should expose such events?

Any pointers would be much appreciated.

Thanks,


Paul

Bram Moolenaar

unread,
May 27, 2019, 7:10:27 AM5/27/19
to vim...@googlegroups.com, Paul Jolly
Not really. It's quite specific and it's hard to imagine what would be
useful. It's one of those things where the one who is first running
into it has to find a solution, and if it works well others will follow.

It probably works best with callbacks. If your plugin has some way for
other plugins to know it exists, and then install callbacks for what
they are interested in, that could work. You probably need to make sure
your plugin is loaded first.

--
He who laughs last, thinks slowest.

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

Paul Jolly

unread,
May 28, 2019, 6:06:50 AM5/28/19
to Bram Moolenaar, vim...@googlegroups.com
Thanks for the thoughts, Bram.

> Not really. It's quite specific and it's hard to imagine what would be
> useful. It's one of those things where the one who is first running
> into it has to find a solution, and if it works well others will follow.

Yep, agreed. Just wanted to see if there was an previous thread/work
in this space that I had missed with my searches.

> It probably works best with callbacks. If your plugin has some way for
> other plugins to know it exists, and then install callbacks for what
> they are interested in, that could work. You probably need to make sure
> your plugin is loaded first.

Agreed again.

I'll post back here as an when I make some progress.



Paul

Lifepillar

unread,
May 28, 2019, 4:25:34 PM5/28/19
to vim...@googlegroups.com, Paul Jolly
On 27 May 2019, at 13:10, Bram Moolenaar <Br...@moolenaar.net> wrote:
>
>
> Paul Jolly wrote:
>
>> Is there a standard means by which plugins like govim should expose such events?
>
> Not really.

I have likely not understood the OP's problem exactly, but wouldn’t

doautocmd User MyEvent

be one such way?

Life.

Paul Jolly

unread,
May 29, 2019, 7:16:24 AM5/29/19
to Lifepillar, vim...@googlegroups.com
> I have likely not understood the OP's problem exactly, but wouldn’t
>
> doautocmd User MyEvent
>
> be one such way?

Thanks. Yes, as I understand it, it would.

My original enquiry was really to understand whether there was an
existing standard/preference amongst the various options.


Paul

Bram Moolenaar

unread,
May 29, 2019, 2:10:38 PM5/29/19
to vim...@googlegroups.com, Paul Jolly, Lifepillar
Using an autocommand still requires the event-listner to know about the
plugin and the event. And there is no good way to pass arguments.
Registering a callback would be a more flexible method. The only
condition is that the registration method is available, thus the plugins
load in a certain sequence.

--
hundred-and-one symptoms of being an internet addict:
40. You tell the cab driver you live at
http://123.elm.street/house/bluetrim.html
41. You actually try that 123.elm.street address.
Reply all
Reply to author
Forward
0 new messages