fix(filetype): vim.filetype.match fails if CWD goes missing #40190

Problem: Running `vim.filetype.match()` when current working directory
  was removed from disk throws a `vim.fs.abspath` assertion error.
  However, the matching might still be possible without trying to match
  against full path (like if it is a known extension).

Solution: Safely compute absolute path and ignore it if it errors.
This commit is contained in:
Evgeni Chasnovski
2026-06-13 20:20:45 +03:00
committed by GitHub
parent 736f914c7b
commit e9b9426d7d
2 changed files with 7 additions and 3 deletions

View File

@@ -3238,16 +3238,17 @@ function M.match(args)
if name then
name = normalize_path(name)
local path = vim.fs.abspath(name)
do -- First check for the simple case where the full path exists as a key
local ok_abspath, path = pcall(vim.fs.abspath, name)
if ok_abspath then -- First check for the simple case where the full path exists as a key
local ft, on_detect = dispatch(filename[path], path, bufnr)
if ft then
return ft, on_detect
end
else
path = name
end
local tail = vim.fs.basename(name)
do -- Next check against just the file name
local ft, on_detect = dispatch(filename[tail], path, bufnr)
if ft then