aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Anders <greg@gpanders.com>2022-01-05 11:35:15 -0700
committerGregory Anders <greg@gpanders.com>2022-01-05 12:26:43 -0700
commit6c86079fa07d46ba9627fc312a6d7818f4b7a2ca (patch)
treed347b880b6cea8a2b1dafab70d7ac33aa7f39e52
parentf1590717acbfb33b0192d46b0e89e9d099ac0b16 (diff)
downloadrneovim-6c86079fa07d46ba9627fc312a6d7818f4b7a2ca.tar.gz
rneovim-6c86079fa07d46ba9627fc312a6d7818f4b7a2ca.tar.bz2
rneovim-6c86079fa07d46ba9627fc312a6d7818f4b7a2ca.zip
fix(filetype): normalize slashes in file paths
-rw-r--r--runtime/lua/vim/filetype.lua11
1 files changed, 9 insertions, 2 deletions
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