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.
34 lines
820 B
Lua
34 lines
820 B
Lua
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
|
|
error('Treesitter parser for ' .. lang .. ' not available. Neovim 0.10+ bundles lua parser.')
|
|
end
|
|
end
|
|
|
|
ensure_parser('lua')
|
|
|
|
local M = {}
|
|
|
|
function M.create_buffer(lines)
|
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
|
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines or {})
|
|
return bufnr
|
|
end
|
|
|
|
function M.delete_buffer(bufnr)
|
|
if bufnr and vim.api.nvim_buf_is_valid(bufnr) then
|
|
vim.api.nvim_buf_delete(bufnr, { force = true })
|
|
end
|
|
end
|
|
|
|
function M.get_extmarks(bufnr, ns)
|
|
return vim.api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, { details = true })
|
|
end
|
|
|
|
return M
|