mirror of
https://github.com/neovim/neovim.git
synced 2026-04-28 02:04:10 +00:00
fix(filetype): normalize full path before matching #32227
Problem: On Windows, treesitter query files are not recognized as such when opened from inside their directory, because the full path returned from fnamemodify(_, ':p') contains backslashes, while the filetype patterns expect forward slashes. Solution: Normalize the result of fnamemodify(_, ':p') before trying to match it to filetype patterns. Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
@@ -2565,6 +2565,15 @@ local function normalize_path(path, as_pattern)
|
||||
return normal
|
||||
end
|
||||
|
||||
local abspath = function(x)
|
||||
return fn.fnamemodify(x, ':p')
|
||||
end
|
||||
if fn.has('win32') == 1 then
|
||||
abspath = function(x)
|
||||
return (fn.fnamemodify(x, ':p'):gsub('\\', '/'))
|
||||
end
|
||||
end
|
||||
|
||||
--- @class vim.filetype.add.filetypes
|
||||
--- @inlinedoc
|
||||
--- @field pattern? vim.filetype.mapping
|
||||
@@ -2873,7 +2882,7 @@ function M.match(args)
|
||||
name = normalize_path(name)
|
||||
|
||||
-- First check for the simple case where the full path exists as a key
|
||||
local path = fn.fnamemodify(name, ':p')
|
||||
local path = abspath(name)
|
||||
ft, on_detect = dispatch(filename[path], path, bufnr)
|
||||
if ft then
|
||||
return ft, on_detect
|
||||
|
||||
Reference in New Issue
Block a user