fix(lua): vim.diff is nil in uv.new_work() thread #34909

Problem:
The "gitsigns" plugin runs `vim.diff` in a thread (`uv.new_work`), but
`vim.diff` is nil in that context:

    Lua callback:
    …/gitsigns.nvim/lua/gitsigns/diff_int.lua:30: bad argument #1 to 'decode' (string expected, got nil)
    stack traceback:
      [C]: in function 'decode'
      …/gitsigns.nvim/lua/gitsigns/diff_int.lua:30: in function <…/gitsigns.nvim/lua/gitsigns/diff_int.lua:29>
    Luv thread:
    …/gitsigns.nvim/lua/gitsigns/diff_int.lua:63: attempt to call field 'diff' (a nil value)

Solution:
Revert the `stdlib.c` change (set `vim.diff` instead of `vim._diff`).
This commit is contained in:
Justin M. Keyes
2025-07-12 23:54:22 -04:00
committed by GitHub
parent 5c4f9b05fa
commit 89b946aa87
5 changed files with 14 additions and 7 deletions

View File

@ -1317,9 +1317,6 @@ require('vim._options')
--- Remove at Nvim 1.0
---@deprecated
vim.loop = vim.uv
--- Renamed to `vim.text.diff`, remove at Nvim 1.0
---@deprecated
vim.diff = vim._diff ---@type fun(a: string, b: string, opts?: vim.text.diff.Opts): string|integer[][]?
-- Deprecated. Remove at Nvim 2.0
vim.highlight = vim._defer_deprecated_module('vim.highlight', 'vim.hl')

View File

@ -14,3 +14,11 @@
--- @param ... any
--- @return any
function vim.call(func, ...) end
--- Renamed to `vim.text.diff`, remove at Nvim 1.0
---@deprecated
---@param a string First string to compare
---@param b string Second string to compare
---@param opts? vim.text.diff.Opts
---@return string|integer[][]? # See {opts.result_type}. `nil` if {opts.on_hunk} is given.
function vim.diff(a, b, opts) end

View File

@ -73,7 +73,8 @@ local M = {}
---@param opts? vim.text.diff.Opts
---@return string|integer[][]? # See {opts.result_type}. `nil` if {opts.on_hunk} is given.
function M.diff(...)
return vim._diff(...)
---@diagnostic disable-next-line: deprecated
return vim.diff(...)
end
local alphabet = '0123456789ABCDEF'