mirror of
https://github.com/neovim/neovim.git
synced 2026-07-16 14:11:28 +00:00
fix(filetype): false positive when matching directory buffer #40695
Problem: URI buffer names can end with a slash, but slash-ended directory matching should not preempt URI filetype patterns. Solution: Do not use the slash shortcut for names with URI schemes, so those continue through normal filetype matching. Co-authored-by: Adam Karafyllidis <akisarou90@gmail.com>
This commit is contained in:
@@ -3254,7 +3254,7 @@ function M.match(args)
|
||||
end
|
||||
|
||||
if name then
|
||||
if name:sub(-1) == '/' then
|
||||
if name:sub(-1) == '/' and not name:find('^%a[%w+.-]*://') then
|
||||
return 'directory'
|
||||
end
|
||||
name = normalize_path(name)
|
||||
|
||||
@@ -82,6 +82,20 @@ describe('vim.filetype', function()
|
||||
)
|
||||
end)
|
||||
|
||||
it('matches URI buffer patterns ending in slash', function()
|
||||
eq(
|
||||
'example',
|
||||
exec_lua(function()
|
||||
vim.filetype.add({
|
||||
pattern = {
|
||||
['example://.*'] = 'example',
|
||||
},
|
||||
})
|
||||
return vim.filetype.match({ filename = 'example:///tmp/example/' })
|
||||
end)
|
||||
)
|
||||
end)
|
||||
|
||||
it('works without defined g:ft_ignore_pat', function()
|
||||
local match_opts = { filename = 'unknown-ft', buf = api.nvim_create_buf(false, true) }
|
||||
eq(
|
||||
|
||||
Reference in New Issue
Block a user