mirror of
https://github.com/neovim/neovim
synced 2025-07-15 16:51:49 +00:00
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:
@ -1317,9 +1317,6 @@ require('vim._options')
|
|||||||
--- Remove at Nvim 1.0
|
--- Remove at Nvim 1.0
|
||||||
---@deprecated
|
---@deprecated
|
||||||
vim.loop = vim.uv
|
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
|
-- Deprecated. Remove at Nvim 2.0
|
||||||
vim.highlight = vim._defer_deprecated_module('vim.highlight', 'vim.hl')
|
vim.highlight = vim._defer_deprecated_module('vim.highlight', 'vim.hl')
|
||||||
|
@ -14,3 +14,11 @@
|
|||||||
--- @param ... any
|
--- @param ... any
|
||||||
--- @return any
|
--- @return any
|
||||||
function vim.call(func, ...) end
|
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
|
||||||
|
@ -73,7 +73,8 @@ local M = {}
|
|||||||
---@param opts? vim.text.diff.Opts
|
---@param opts? vim.text.diff.Opts
|
||||||
---@return string|integer[][]? # See {opts.result_type}. `nil` if {opts.on_hunk} is given.
|
---@return string|integer[][]? # See {opts.result_type}. `nil` if {opts.on_hunk} is given.
|
||||||
function M.diff(...)
|
function M.diff(...)
|
||||||
return vim._diff(...)
|
---@diagnostic disable-next-line: deprecated
|
||||||
|
return vim.diff(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
local alphabet = '0123456789ABCDEF'
|
local alphabet = '0123456789ABCDEF'
|
||||||
|
@ -763,7 +763,8 @@ void nlua_state_add_stdlib(lua_State *const lstate, bool is_thread)
|
|||||||
|
|
||||||
// vim.text.diff
|
// vim.text.diff
|
||||||
lua_pushcfunction(lstate, &nlua_xdl_diff);
|
lua_pushcfunction(lstate, &nlua_xdl_diff);
|
||||||
lua_setfield(lstate, -2, "_diff");
|
// TODO(justinmk): set vim.text.diff here, or rename this to "_diff". goddamnit.
|
||||||
|
lua_setfield(lstate, -2, "diff");
|
||||||
|
|
||||||
// vim.json
|
// vim.json
|
||||||
lua_cjson_new(lstate);
|
lua_cjson_new(lstate);
|
||||||
|
@ -217,7 +217,7 @@ describe('thread', function()
|
|||||||
it('diff', function()
|
it('diff', function()
|
||||||
exec_lua [[
|
exec_lua [[
|
||||||
local entry = function(async)
|
local entry = function(async)
|
||||||
async:send(vim._diff('Hello\n', 'Helli\n'))
|
async:send(vim.diff('Hello\n', 'Helli\n'))
|
||||||
end
|
end
|
||||||
local on_async = function(ret)
|
local on_async = function(ret)
|
||||||
vim.rpcnotify(1, 'result', ret)
|
vim.rpcnotify(1, 'result', ret)
|
||||||
@ -372,7 +372,7 @@ describe('threadpool', function()
|
|||||||
it('work', function()
|
it('work', function()
|
||||||
exec_lua [[
|
exec_lua [[
|
||||||
local work_fn = function()
|
local work_fn = function()
|
||||||
return vim._diff('Hello\n', 'Helli\n')
|
return vim.diff('Hello\n', 'Helli\n')
|
||||||
end
|
end
|
||||||
local after_work_fn = function(ret)
|
local after_work_fn = function(ret)
|
||||||
vim.rpcnotify(1, 'result', ret)
|
vim.rpcnotify(1, 'result', ret)
|
||||||
|
Reference in New Issue
Block a user