mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 05:05:00 -07:00
230b0c7f02
PROBLEM: There are several limitations to vim.str_byteindex, vim.str_utfindex: 1. They throw given out-of-range indexes. An invalid (often user/lsp-provided) index doesn't feel exceptional and should be handled by the caller. `:help dev-error-patterns` suggests that `retval, errmsg` is the preferred way to handle this kind of failure. 2. They cannot accept an encoding. So LSP needs wrapper functions. #25272 3. The current signatures are not extensible. * Calling: The function currently uses a fairly opaque boolean value to indicate to identify the encoding. * Returns: The fact it can throw requires wrapping in pcall. 4. The current name doesn't follow suggestions in `:h dev-naming` and I think `get` would be suitable. SOLUTION: - Because these are performance-sensitive, don't introduce `opts`. - Introduce an "overload" that accepts `encoding:string` and `strict_indexing:bool` params. ```lua local col = vim.str_utfindex(line, encoding, [index, [no_out_of_range]]) ``` Support the old versions by dispatching on the type of argument 2, and deprecate that form. ```lua vim.str_utfindex(line) -- (utf-32 length, utf-16 length), deprecated vim.str_utfindex(line, index) -- (utf-32 index, utf-16 index), deprecated vim.str_utfindex(line, 'utf-16') -- utf-16 length vim.str_utfindex(line, 'utf-16', index) -- utf-16 index vim.str_utfindex(line, 'utf-16', math.huge) -- error: index out of range vim.str_utfindex(line, 'utf-16', math.huge, false) -- utf-16 length ``` |
||
---|---|---|
.. | ||
autoload | ||
colors | ||
compiler | ||
doc | ||
ftplugin | ||
indent | ||
keymap | ||
lua | ||
pack/dist/opt | ||
plugin | ||
queries | ||
scripts | ||
spell | ||
syntax | ||
tutor | ||
CMakeLists.txt | ||
delmenu.vim | ||
filetype.lua | ||
ftoff.vim | ||
ftplugin.vim | ||
ftplugof.vim | ||
indent.vim | ||
indoff.vim | ||
makemenu.vim | ||
menu.vim | ||
neovim.ico | ||
nvim.appdata.xml | ||
nvim.desktop | ||
nvim.png | ||
optwin.vim | ||
synmenu.vim | ||
windows_icon.rc |