-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[RFC] functions to notify a co-process when the current buffer is modified #5269
Conversation
runtime/doc/msgpack_rpc.txt
Outdated
was replaced and will always be between `1` and `line('$')`. {int2} tells | ||
how many lines were replaced and will always be at least `1`. For most | ||
small changes {int2} will be `1`, meaning only the line mentioned in {int1} | ||
was changed. {int3} tells how many new lines are replacing the lines that |
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.
{int3}
would also be at least 1
?
Interesting work! There is a simpler way than adding vimL functions tough, use api methods. Compare |
When a single channel is watching multiple buffers, is there a way to determine which buffer was modified? |
runtime/doc/msgpack_rpc.txt
Outdated
|
||
Setting Up~ | ||
|
||
Use |rpcstart()| to start up your co-process. This will give you a valid |
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.
no need to repeat this here. It is likely also confusing: I suppose many consumers would be plugins living in a rplugin host, and don't be separate co-processes. (As the notifications are high-throughput we should also add multiplexing logic to e.g. the python-client, so that multiple plugins active in the same buffer can share the same notification stream)
Thank you, I will look into this ... I don't have any experience with writing or using api methods but it sounds like a reasonable approach.
Er, no. I'm embarrassed that I didn't notice this glaring omission myself. I will make sure this is catered for in my next push.
This seems reasonable. |
Also please try to write tests in lua. |
@phodge why close this? |
@justinmk Sorry I think when I deleted my |
OK I've won my battle with |
I've written a simple word highlighting plugin to help with evaluating performance: https://github.com/phodge/vim-hiword |
This would be great for www.github.com/tjdevries/nvim-langserver-shim. There are a couple messages that need to be sent on text changed, text editted, etc. Really cool idea! |
src/nvim/eval.c
Outdated
@@ -10583,6 +10583,7 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr) | |||
"linebreak", | |||
"lispindent", | |||
"listcmds", | |||
"liveupdate", |
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.
Normally we don't add named features for new nvim-specific features, as nvim will always be compiled with all features (with a few exceptions). Instead a plugin should check for the thing the feature adds, an api function in this case. This is possible in principle by inspecting the api metadata, but maybe we should make this simpler by overloading exist()
(exist('+')
does not work as not all api functions are vimL functions, like this won't be).
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've made a new commit to revert this addition.
src/nvim/liveupdate.c
Outdated
} | ||
|
||
// add the buffer to the active array and send the full buffer contents now | ||
uint64_t *newlist = xmalloc((active_size + 2) * sizeof channel_id); |
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.
we should use kvec_t
for this, it implements a resizable array for us. See lib/kvec.h
for implementation, and you can find example i e bufhl_vec_T lineinfo
in buffer.c
(type defined in bufhl_defs.h
)
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've made a new commit that changes buf->liveupdate_channels
to a kvec_t(uint64_t)
.
src/nvim/api/dispatch_deprecated.lua
Outdated
@@ -7,6 +7,7 @@ local deprecated_aliases = { | |||
nvim_buf_get_number="buffer_get_number", | |||
nvim_buf_get_option="buffer_get_option", | |||
nvim_buf_get_var="buffer_get_var", | |||
nvim_buf_live_updates="buffer_live_updates", |
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 you use master version of neovim python-client (release will be made soon) this will not be needed.
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'd prefer to leave this backwards-compatibility in since I'd like to try and have live updates merged soon, and I want it to work with current python clients.
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.
No, this is for older functions that was part of 0.1.5 as 0.1.6 changed the naming convention and this has nothing to be backwards-compatible to. python-client 0.1.11 will be released soon, well before this is merged. But we will need to add helper functions in python-client to make it feasible to use this in rplugins (if different python plugins subscribe to the same 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.
The method names ("LiveUpdate" etc) should be rationalized with other method names used by nvim. See discussion starting at https://gitter.im/neovim/neovim?at=58160c8a482c168b22d0369b
src/nvim/liveupdate.c
Outdated
args.items = xcalloc(sizeof(Object), args.size); | ||
|
||
// the first argument is always the buffer number | ||
args.items[0] = INTEGER_OBJ(buf->handle); |
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.
Buffer should be sent using EXT encoding. See discussion starting at https://gitter.im/neovim/neovim?at=581609f85a1cfa016e61e784
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.
Which means BUFFER_OBJ
should be used instead of INTEGER_OBJ
.
src/nvim/liveupdate.c
Outdated
while (buf->liveupdate_channels[active_size] != LIVEUPDATE_NONE) { | ||
if (buf->liveupdate_channels[active_size] == channel_id) { | ||
size_t size = kv_size(buf->liveupdate_channels); | ||
if (size) { |
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 if
can just be removed
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Thank you for all the work that has been done towards this! This issue is important for https://github.com/Chillee/VSCodeNeovim, and I'm excited to see all the progress that has been made. |
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
Originally written by @phodge in neovim#5269.
This will be addressed by #7917 |
Hello, I have been working on an efficient API for having neovim notify a co-process (channel?) any time a buffer is modified (because doing this with TextChanged autocmds is inefficient and difficult). This feature will make it easier to write plugins which scans the buffers contents and updates the display in real-time (e.g. syntax highlighters, linters).
The first commit in this PR contains the help text for 3 new functions and a mini-tutorial, please refer to that commit if you would like to learn how the new feature would work. The last commit contains some TODO items that I have yet to resolve.
I'm interested in collecting feedback with regards to:
Thank you for your thoughtful consideration.
Peter