mirror of
https://github.com/neovim/neovim.git
synced 2026-08-30 11:02:01 +00:00
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:
committed by
GitHub
parent
736f914c7b
commit
e9b9426d7d
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user