Allow for aliassing certain file types, to convert to a type with treesitter highlighting.
I chose bash for a replacement for sh, since it seemed to be the closest out of all options. Which makes sence, since it is the bourne again shell.
This commit is contained in:
@@ -6,16 +6,31 @@ return { {
|
|||||||
lazy = false,
|
lazy = false,
|
||||||
config = function()
|
config = function()
|
||||||
-- Pre-install a few languages we're (very) likely going to use
|
-- Pre-install a few languages we're (very) likely going to use
|
||||||
require('nvim-treesitter').install({
|
local ts = require('nvim-treesitter')
|
||||||
|
ts.install({
|
||||||
'c', 'make',
|
'c', 'make',
|
||||||
'bash', 'gitignore', 'editorconfig',
|
'bash', 'gitignore', 'editorconfig',
|
||||||
'ini', 'json', 'yaml',
|
'ini', 'json', 'yaml',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Define aliases for entries that lack an entry, but should have one.
|
||||||
|
local alias = {
|
||||||
|
{ 'sh', 'bash' },
|
||||||
|
}
|
||||||
|
|
||||||
|
local pat = vim.iter(alias):map(function(a) return a[1] end):totable()
|
||||||
|
vim.list_extend(pat, ts.get_available())
|
||||||
Autocmd('FileType', {
|
Autocmd('FileType', {
|
||||||
pattern = require('nvim-treesitter').get_available(),
|
pattern = pat,
|
||||||
callback = function(ft)
|
callback = function(arg)
|
||||||
require('nvim-treesitter').install(ft.match)
|
local a = vim.iter(alias)
|
||||||
|
:find(function(a) return arg.match == a[1] end)
|
||||||
|
if not a then -- Ensure we only install if an alias was found
|
||||||
|
require('nvim-treesitter').install(vim.bo.ft)
|
||||||
pcall(vim.treesitter.start)
|
pcall(vim.treesitter.start)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
vim.bo.ft = a[2] -- Retriggers function
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
|
|||||||
Reference in New Issue
Block a user