Skip to content

Improve usage of vim.str_utfindex and vim.str_byteindex #1901

@sneha-afk

Description

@sneha-afk

Contributing guidelines

Module(s)

mini.map, mini.surround

Neovim version

0.11.x

Description

When running :checkhealth, the following warning is present:

- ⚠️ WARNING vim.str_utfindex is deprecated. Feature will be removed in Nvim 1.0
  - ADVICE:
    - use vim.str_utfindex(s, encoding, index, strict_indexing) instead.
    - stack traceback:
        .../mini.map/lua/mini/map.lua:1687
        .../mini.map/lua/mini/map.lua:600
        .../mini.map/lua/mini/map.lua:576

According to the latest docs in 0.11.x, the second parameter into this function is expected to be the desired encoding explicitly set. The full discussion on why this was made is from neovim/neovim#30735

In the context of its usage in mini.map, this could be guarded by a version check and then call the function with "utf-32" as the encoding to use.

local res = vim.fn.has('nvim-0.11') == 1 and vim.str_utfindex(x, 'utf-32') or vim.str_utfindex(x)

I can put in a PR to implement this change as the comment above the call makes it clear the UTF-32 value is the desired one. If this is the same across other uses of the function, we can do a similar pattern until mini.nvim drops support for < 0.11. Thank you for all the work you put in!

Reproduction

  1. Update mini.map (or any other module using this function which includes: diff, pick, align, surround, etc.) to the latest main.

  2. Run :checkhealth

  3. There will be many stack traces in the vim.deprecated section pointing to mini.map/lua/mini/map.lua:1687:
    https://github.com/echasnovski/mini.nvim/blob/5495dd5480843148b0e9ed57b42d32ea47ac2b52/lua/mini/map.lua#L1685-L1689

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions