fix(parser): detect filetype from file content (shebang/modeline)
When a file has no extension but contains a shebang (e.g., `#!/bin/bash`),
filetype detection now reads the first 10 lines from disk and uses
`vim.filetype.match({ filename, contents })` for content-based detection.
This enables syntax highlighting for files like `build` scripts that rely
on shebang detection, even when the file isn't open in a buffer.
Detection order:
1. Existing buffer's filetype (already implemented in #69)
2. File content (shebang/modeline) - NEW
3. Filename extension only
Also adds `filetype on` to test helpers to ensure `vim.g.ft_ignore_pat`
is set, which is required for shell detection.
This commit is contained in:
parent
0e6871b167
commit
0dc8a0ec0f
3 changed files with 94 additions and 0 deletions
|
|
@ -2,6 +2,8 @@ local plugin_dir = vim.fn.getcwd()
|
|||
vim.opt.runtimepath:prepend(plugin_dir)
|
||||
vim.opt.packpath = {}
|
||||
|
||||
vim.cmd('filetype on')
|
||||
|
||||
local function ensure_parser(lang)
|
||||
local ok = pcall(vim.treesitter.language.inspect, lang)
|
||||
if not ok then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue