Skip to content

Conversation

IIIHSUAN
Copy link
Contributor

This PR addresses #1405 and #1388, which are caused by the incompatible function signature vim.str_utfindex in Neovim v0.11.

  • vim.str_utfindex before 0.11:
    --- @param str string
    --- @param index? integer
    --- @return integer UTF-32 index
    --- @return integer UTF-16 index
    function vim.str_utfindex(str, index) end
  • vim.str_utfindex since 0.11:
    --- Parameters:
    --- {s} (string)
    --- {encoding} ("utf-8"|"utf-16"|"utf-32")
    --- {index} (integer)
    --- {strict_indexing} (boolean?) default: true
    --- Return:
    --- (integer)
    vim.str_byteindex(s, encoding, index, strict_indexing)

At first, I considered simply using a helper function to wrap the incompatible functions, but that felt too tedious for such a common task. Then I found the vimscript API function vim.fn.strdisplaywidth, which seems to do the job and makes more sense in this context.

You can find these implementations in the two separate commits. Both commits work fine.

Vim functions: strchars vs strwidth vs strlen vs strdisplaywidth for reference.

Also, many thanks to Lewis. Gitsigns is awesome!

@lewis6991 lewis6991 force-pushed the fix/blame-incompatible-nvim-function branch from e517570 to 4cdaa9d Compare September 30, 2025 10:54
@lewis6991 lewis6991 merged commit 400cfab into lewis6991:main Sep 30, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants