Hi, On Fri, Nov 12, 2021 at 5:45 AM Boris Staletic <[email protected]> wrote:
> prop_list_profile.txt > <https://github.com/vim/vim/files/7527900/prop_list_profile.txt> > The problem > > If a plugin wants to grab all of the previously placed text properties > that the same plugin has placed, the current prop_list requires some work: > > 1. Loop over the lines of the buffer. > 2. Grab all the text properties from each line and aggregate in some > list. > 3. Filter out all properties that are not produced by the plugin. A > plugin might need to grab two types of properties, so making vim filter by > type isn't perfect either. > > How are you using the property dict value returned by prop_list()? I see that you cannot modify the value returned by prop_list() and then update the text property by using the prop_add() or the prop_add_list() function. BTW, I have implemented the prop_list_range() function to return the list of text properties placed on a range of lines in a specified buffer: https://github.com/yegappan/vim/tree/textprop But I am trying to understand how the returned value will be used. If you have a text property that spans multiple lines, then you cannot simply modify the value returned by prop_list_range() and place the text properties again. Regards, Yegappan > > > This results in a ton of vimscript API calls and is a similar thing to > what lead to #8675 <https://github.com/vim/vim/issues/8675>. > > Basically, what a plugin is running is this: > > function! g:UpdateMatches() > > let properties = [] > > for line in range( line('$') ) > > call extend(properties, filter(prop_list( line + 1, { 'bufnr': 1 } ), > 'v:val[ "type" ][ :3 ] ==# "Ycm"' )) > > endfor > endfunction > > The profile is here: > https://gist.github.com/bstaletic/84c10b75be93c99f321a27af73278a8d > The neovim API > > I'm not the biggest fan of neovim, but its API here is really nice. > > Each plugin gets a unique namespace ID. Then, when getting (neovim's > equivalent of) all the properties in a buffer, besides the buffer number, > the ID is passed as well. Introducing this namespace ID thing to text > property APIs would be perfect. Vim's sign_foo() family of functions > already has the group thing. > Alternative > > A simpler solution is just introducing something like prop_list_range(), > where not only a single line would be passed, but rather a range of lines. > That way plugins could request all text properties from line N to line M. > It would still leave filtering to the users. > > Note that the two ideas aren't exactly exclusive. > Context > > I'm a maintainer of YouCompleteMe. The way YCM updates text properties for > a specific buffer is basically described in the "problem" section. In more > detail: > > - We define two property types: > > https://github.com/ycm-core/YouCompleteMe/blob/master/autoload/youcompleteme.vim#L418-L433 > - When we update the diagnostics, we do it like this: > - First, we grab all placed properties > > <https://github.com/ycm-core/YouCompleteMe/blob/master/python/ycm/diagnostic_interface.py#L133> > - For each new diagnostic > > <https://github.com/ycm-core/YouCompleteMe/blob/master/python/ycm/diagnostic_interface.py#L137> > - if the exact same has already been placed, just skip > > <https://github.com/ycm-core/YouCompleteMe/blob/master/python/ycm/diagnostic_interface.py#L149> > - else, place a new one > > <https://github.com/ycm-core/YouCompleteMe/blob/master/python/ycm/diagnostic_interface.py#L151-L156> > - Could be optimized with prop_add_list(). In the TODO list. > - Once we have skipped all the ones we want to keep and added the > new ones, what remains is to remove the stale ones > > <https://github.com/ycm-core/YouCompleteMe/blob/master/python/ycm/diagnostic_interface.py#L158-L159> > - There's no batch remove of properties, but *so far* that > hasn't been a problem. > > The algorithm is made that way, because in common cases it's faster than > removing all old and then placing all new - i.e. paying attention to > overlap between the two sets is beneficial. > > > > But I digress. The problem is that call to vimsupport.GetTextProperties( > bufnr ). It's defined here: > > > https://github.com/ycm-core/YouCompleteMe/blob/master/python/ycm/vimsupport.py#L213-L226 > > Doing that on an extra long file is very inefficient. For a file that is > 1'010'000 lines long, with no props either placed, or to place (i.e. all > work is in GetTextProperties()), it takes ~1 minute on my machine. > > > -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/CAAW7x7%3DMWfWmEHRbY9mOt0kHOqyf4rhTjiw7fiq-Ktu5t2a6mg%40mail.gmail.com.
