nVim/lua/core/treesitter.lua
Robert Morrison 8d30935771 fix(treesitter): Make Treesitter install on start
Recent changes to treesitter have made it so that it cannot
automatically install the languages you want. As such I have cobbled
together this script to make it work right for me.
2025-12-21 20:40:41 +00:00

72 lines
1.7 KiB
Lua

-- Due to the complete infrastructure change in nvim-tressiter
-- this file exists to install all the languages I want
-- and then make sure that treesitter support is enabled for them
--- This is a mapping of parsers to filetypes
--- where the parser name and filetype is the same we leave the filetype blank
--- otherwise the filetype is the filetype(s) that the parser should be used in
local languages = {
["bash"] = "",
["c"] = "",
["cpp"] = "",
["css"] = "",
["c_sharp"] = "",
["diff"] = "",
["git_config"] = "gitconfig",
["git_rebase"] = "",
["gitcommit"] = "",
["gitignore"] = "",
["go"] = "",
["gomod"] = "",
["html"] = "",
["ini"] = "",
["javascript"] = "",
["jsonnet"] = "",
["latex"] = "",
["lua"] = "",
["luadoc"] = "",
["luap"] = "",
["make"] = "",
["markdown"] = "",
["markdown_inline"] = "markdown",
["python"] = "",
["query"] = "",
["regex"] = "",
["rust"] = "",
["scss"] = "",
["toml"] = "",
["vim"] = "",
["vimdoc"] = "",
["yuck"] = "",
["yaml"] = "",
["zig"] = "",
}
local parsers = {}
local filetypes = {}
local TS = require("nvim-treesitter")
for parser, filetype in pairs(languages) do
if filetype == "" then
table.insert(filetypes, parser)
else
table.insert(filetypes, parser)
end
table.insert(parsers, parser)
end
TS.install(parsers, { summary = true })
local all_parsers = TS.get_installed()
local alltype = vim.tbl_extend("force", filetypes, all_parsers)
vim.api.nvim_create_augroup("ts-augroup", {})
vim.api.nvim_create_autocmd("FileType", {
pattern = alltype,
callback = function()
vim.treesitter.start()
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
require("treesitter-context").enable()
end,
})