68 lines
1.4 KiB
Lua
68 lines
1.4 KiB
Lua
local log = require("log")
|
|
|
|
local languages = {
|
|
"bash",
|
|
"zsh",
|
|
"python",
|
|
"c",
|
|
"cpp",
|
|
"lua",
|
|
"luadoc",
|
|
"vim",
|
|
"vimdoc",
|
|
"php",
|
|
"rust",
|
|
"comment",
|
|
"gitcommit",
|
|
"xml",
|
|
"sql",
|
|
"html",
|
|
"json",
|
|
"gotmpl",
|
|
"markdown",
|
|
"go",
|
|
"svelte",
|
|
"scss",
|
|
"tsx",
|
|
"typescript",
|
|
"yaml",
|
|
}
|
|
|
|
local ts = require("nvim-treesitter")
|
|
ts.setup({
|
|
install_dir = string.format("%s/nvim-treesitter", vim.fn.stdpath("data"))
|
|
})
|
|
ts.install(languages):await(function(err)
|
|
if err then
|
|
log.error("Error: %s", err)
|
|
return
|
|
end
|
|
|
|
---@diagnostic disable-next-line: redefined-local
|
|
ts.update():await(function(err)
|
|
if err then
|
|
log.error("Error: %s", err)
|
|
return
|
|
end
|
|
|
|
local filetypes = {}
|
|
for _, lang in ipairs(languages) do
|
|
for _, ft in ipairs(vim.treesitter.language.get_filetypes(lang)) do
|
|
if not vim.list_contains(filetypes, ft) then
|
|
table.insert(filetypes, ft)
|
|
end
|
|
end
|
|
end
|
|
|
|
vim.api.nvim_create_autocmd("FileType", {
|
|
pattern = filetypes,
|
|
callback = function()
|
|
vim.treesitter.start()
|
|
vim.wo.foldmethod = "expr"
|
|
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
|
|
end,
|
|
})
|
|
end
|
|
)
|
|
end)
|