mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 03:15:39 +00:00
feat(filetype): fall back to file extension when matching from hashbang (#22140)
If nothing matched in match_from_hashbang, also check the file extension table. For a hashbang like '#!/bin/env foo', this will set the filetype to 'fooscript' assuming the filetype for the 'foo' extension is 'fooscript' in the extension table.
This commit is contained in:
committed by
GitHub
parent
1d6bb0892b
commit
b518aceaa8
@@ -98,10 +98,22 @@ describe('vim.filetype', function()
|
||||
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\\)$"
|
||||
vim.g.ft_ignore_pat = '\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$'
|
||||
return vim.filetype.match({ contents = { '#!/usr/bin/env bash' } })
|
||||
]])
|
||||
end)
|
||||
|
||||
it('considers extension mappings when matching from hashbang', function()
|
||||
eq('fooscript', exec_lua [[
|
||||
vim.filetype.add({
|
||||
extension = {
|
||||
foo = 'fooscript',
|
||||
}
|
||||
})
|
||||
return vim.filetype.match({ contents = { '#!/usr/bin/env foo' } })
|
||||
]])
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
describe('filetype.lua', function()
|
||||
|
||||
Reference in New Issue
Block a user