mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(filetype): make vim.filetype.match() work with contents only (#22181)
Co-authored-by: Gregory Anders <greg@gpanders.com>
This commit is contained in:
parent
24ec0aaa7a
commit
9668c166e8
@ -2449,6 +2449,7 @@ local function match_pattern(name, path, tail, pat)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- If the pattern contains a / match against the full path, otherwise just the tail
|
||||
local fullpat = '^' .. pat .. '$'
|
||||
local matches
|
||||
@ -2526,11 +2527,10 @@ function M.match(args)
|
||||
name = api.nvim_buf_get_name(bufnr)
|
||||
end
|
||||
|
||||
local ft, on_detect
|
||||
|
||||
if name then
|
||||
name = normalize_path(name)
|
||||
end
|
||||
|
||||
local ft, on_detect
|
||||
|
||||
-- First check for the simple case where the full path exists as a key
|
||||
local path = vim.fn.fnamemodify(name, ':p')
|
||||
@ -2587,6 +2587,7 @@ function M.match(args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Finally, check file contents
|
||||
if contents or bufnr then
|
||||
|
@ -94,6 +94,14 @@ describe('vim.filetype', function()
|
||||
return vim.filetype.match({ buf = 0 })
|
||||
]])
|
||||
end)
|
||||
|
||||
it('works with contents #22180', function()
|
||||
eq('sh', exec_lua [[
|
||||
-- Needs to be set so detect#sh doesn't fail
|
||||
vim.g.ft_ignore_pat = "\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$"
|
||||
return vim.filetype.match({ contents = { '#!/usr/bin/env bash' } })
|
||||
]])
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('filetype.lua', function()
|
||||
|
Loading…
Reference in New Issue
Block a user