Hi,

On Tue, Jun 20, 2023 at 2:04 PM Yee Cheng Chin <[email protected]>
wrote:

> May I ask what the motivation is for such a change? This seems counter to
> any programming language libraries that I'm aware of. You will end up
> returning an "index" that's clearly out of bounds and seems to actively
> encourage unsafe programming where you now have to check for length *or*
> -1 to tell if the result is invalid. Maybe I'm missing something by it
> seems more like byteidx is the undesired behavior here.
>
>
> A LSP server can return a character position which is at the end of a line
(equal to the number
of characters in the line).  This happens, for example, when doing
insert-mode completion at the
end of a line.  In this case, if charidx() is used to translate the
returned LSP position to a character
position, it returns -1.  So the plugin needs to check for this case and
then use strchars() and use
the return value as the character position:

https://github.com/yegappan/lsp/blob/main/autoload/lsp/offset.vim#L55

With this PR, the charidx() function returns the number of characters in
the line if the supplied index
is equal to the string length and the plugin can directly use the return
value avoid an additional
call to strchars().

Regards,
Yegappan

-- 
-- 
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/CAAW7x7mortzVDGnoVTKD%2B45b%3DX3SXNV-QCtudYfuRHW_6niX9g%40mail.gmail.com.

Raspunde prin e-mail lui