From 6c86079fa07d46ba9627fc312a6d7818f4b7a2ca Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Wed, 5 Jan 2022 11:35:15 -0700 Subject: fix(filetype): normalize slashes in file paths --- runtime/lua/vim/filetype.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'runtime') diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index e36a466897..54b20f7391 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -1357,6 +1357,11 @@ end local pattern_sorted = sort_by_priority(pattern) +---@private +local function normalize_path(path) + return (path:gsub("\\", "/")) +end + --- Add new filetype mappings. --- --- Filetype mappings can be added either by extension or by filename (either @@ -1419,11 +1424,11 @@ function M.add(filetypes) end for k, v in pairs(filetypes.filename or {}) do - filename[k] = v + filename[normalize_path(k)] = v end for k, v in pairs(filetypes.pattern or {}) do - pattern[k] = v + pattern[normalize_path(k)] = v end if filetypes.pattern then @@ -1455,6 +1460,8 @@ function M.match(name, bufnr) -- wish to perform filetype detection on buffers other than the current one. bufnr = bufnr or api.nvim_get_current_buf() + name = normalize_path(name) + -- First check for the simple case where the full path exists as a key local path = vim.fn.resolve(vim.fn.fnamemodify(name, ":p")) if dispatch(filename[path], path, bufnr) then -- cgit