aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/filetype.lua
diff options
context:
space:
mode:
authorJonas Strittmatter <40792180+smjonas@users.noreply.github.com>2023-02-14 00:04:16 +0100
committerGitHub <noreply@github.com>2023-02-13 16:04:16 -0700
commitb518aceaa8f738e581e58aacae93514699b5ff8e (patch)
treeecf570a92d612d10fc3b442cd1f0c7af7c30ceb5 /runtime/lua/vim/filetype.lua
parent1d6bb0892b58e5a4183e74c0fbd2dc20204e33a4 (diff)
downloadrneovim-b518aceaa8f738e581e58aacae93514699b5ff8e.tar.gz
rneovim-b518aceaa8f738e581e58aacae93514699b5ff8e.tar.bz2
rneovim-b518aceaa8f738e581e58aacae93514699b5ff8e.zip
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.
Diffstat (limited to 'runtime/lua/vim/filetype.lua')
-rw-r--r--runtime/lua/vim/filetype.lua4
1 files changed, 3 insertions, 1 deletions
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index ec568b5b82..ca91f3f402 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -2604,7 +2604,9 @@ function M.match(args)
-- If the function tries to use the filename that is nil then it will fail,
-- but this enables checks which do not need a filename to still work.
local ok
- ok, ft = pcall(require('vim.filetype.detect').match_contents, contents, name)
+ ok, ft = pcall(require('vim.filetype.detect').match_contents, contents, name, function(ext)
+ return dispatch(extension[ext], name, bufnr)
+ end)
if ok and ft then
return ft
end