fix(difftool): fully resolve symlinks when comparing paths #36147

Fixes issue on mac where it was constantly reloading buffers as paths
were not being normalized and resolved correctly (in relation to buffer
name).

Quickfix entry:
/var/folders/pt/2s7dzyw12v36tsslrghfgpkr0000gn/T/git-difftool.m95lj8/right/app.vue

Buffer name:
/private/var/folders/pt/2s7dzyw12v36tsslrghfgpkr0000gn/T/git-difftool.m95lj8/right/app.vue

/var was synlinked to /private/var and this was not being properly
handled.

Also added lazy redraw to avoid too many redraws when this happens in
future and added test for symlink handling.

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2025-10-12 20:25:14 +02:00
committed by GitHub
parent 638d44ded8
commit c6113da5a9
3 changed files with 52 additions and 10 deletions

View File

@@ -5,12 +5,20 @@ local M = {}
--- @param file string
--- @return number buffer number of the edited buffer
M.edit_in = function(winnr, file)
local function resolved_path(path)
if not path or path == '' then
return ''
end
return vim.fn.resolve(vim.fs.abspath(path))
end
return vim.api.nvim_win_call(winnr, function()
local current = vim.fs.abspath(vim.api.nvim_buf_get_name(vim.api.nvim_win_get_buf(winnr)))
local current_buf = vim.api.nvim_win_get_buf(winnr)
local current = resolved_path(vim.api.nvim_buf_get_name(current_buf))
-- Check if the current buffer is already the target file
if current == (file and vim.fs.abspath(file) or '') then
return vim.api.nvim_get_current_buf()
if current == resolved_path(file) then
return current_buf
end
-- Read the file into the buffer