mirror of
https://github.com/neovim/neovim.git
synced 2026-07-19 15:41:32 +00:00
fix(filetype): move fallback logic to vim.filetype.match() #30141
Problem: Previously, the fallback logic to ".conf" was located outside of `vim.filetype.match()` and directly within the AutoCmd definition. As a result, `vim.filetype.match()` would return nil instead of ".conf" for fallback cases (#30100). Solution: Added a boolean return value to `vim.filetype.match()` that indicates whether the match was the result of fallback. If true, the filetype will be set using `setf FALLBACK <ft>` instead of `setf <ft>`.
This commit is contained in:
@@ -210,6 +210,25 @@ describe('vim.filetype', function()
|
||||
)
|
||||
rmdir('Xfiletype')
|
||||
end)
|
||||
|
||||
it('fallback to conf if any of the first five lines start with a #', function()
|
||||
eq(
|
||||
{ 'conf', true },
|
||||
exec_lua(function()
|
||||
local bufnr = vim.api.nvim_create_buf(true, false)
|
||||
local lines = {
|
||||
'# foo',
|
||||
}
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
|
||||
-- Needs to be set so detect.conf() doesn't fail
|
||||
vim.g.ft_ignore_pat = '\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$'
|
||||
|
||||
local ft, _, fallback = vim.filetype.match({ buf = bufnr })
|
||||
return { ft, fallback }
|
||||
end)
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('filetype.lua', function()
|
||||
|
||||
Reference in New Issue
Block a user