Yegappan wrote:

> On Sat, May 6, 2023 at 4:44 AM rickhowe <vim-dev-git...@256bit.org> wrote:
> 
> > I am interested in this builtin function as I have developed some plugins
> > to support word/character level diff in lines (this
> > <https://github.com/rickhowe/diffchar.vim>) and range/area selectable
> > diff in buffers (this <https://github.com/rickhowe/spotdiff.vim>). I
> > implemented the O(NP) comparison algorithm in vim script, but I have been
> > looking for a builtin function like yours. Several month ago, I noticed
> > that neovim has vim.diff() function so I switched to use it for neovim in
> > my script.
> >
> > Honestly, I am confused about a return value of your function. vim.diff()
> > actually returns diff in a unified format as default, from which is very
> > easy to generate a shortest edit script (SES).
> >
> >
> > The Neovim vim.diff() function (
> https://neovim.io/doc/user/lua.html#lua-diff) returns the
> diff between two strings.  It returns either a String or a List depending
> on the "result_type"
> option value.  If "result_type" is set to "unified" (which is the default),
> then this function returns
> a String which is the unified diff output between the two string
> arguments.  If the "result_type"
> option is set to "indices", then vim.diff() returns a List with 4 numbers
> (starting line number in
> the first string, line count, starting line number in the second string,
> line count).
> 
> The return value of vim.diff() is not fully suitable for getting the change
> information needed for
> the LSP DidChangeTextDocument notification (
> https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentContentChangeEvent
> ).
> For this notification, we need the range of characters in the old text
> (starting and ending
> text position) and the new text that replaces the old text.
> 
> I can modify the new diff() function to return a value similar to that
> returned by the
> Neovim vim.diff() function.  i.e. either a string with the unified diff or
> a List with the indices.
> We can then add an additional option ("range" or "extended" or "position")
> to return
> the starting and ending position of the change in the old and the new text.
> 
> Bram: What do you think about this approach?

The unified diff will contain less information, it only shows
added/removed/modified lines, not column information.  This then needs
to be parsed, thus a sequence of digits converted to a number.  For just
getting the information this adds overhead, thus it would only be useful
if a unified diff is actually needed.

Also being able to make a diff between two string with NL characters
seems hardly useful.  I would not know where such a string comes from.
When using buffer lines we have a list of strings.  If needed split()
can be used before passing the text to diff().

-- 
How To Keep A Healthy Level Of Insanity:
13. Go to a poetry recital and ask why the poems don't rhyme.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230511150818.7D0721C1B27%40moolenaar.net.

Reply via email to