30 lines
912 B
Lua
30 lines
912 B
Lua
vim.pack.add({ "https://github.com/nvim-treesitter/nvim-treesitter" })
|
|
|
|
local ts = require("nvim-treesitter")
|
|
|
|
-- Installs treesitter for filetype if available
|
|
-- enables highlighting and indentation
|
|
vim.api.nvim_create_autocmd("FileType", {
|
|
pattern = { "*" },
|
|
callback = function(args)
|
|
local ft = vim.bo[args.buf].filetype
|
|
local lang = vim.treesitter.language.get_lang(ft)
|
|
|
|
if not vim.treesitter.language.add(lang) then
|
|
local available = vim.g.ts_available or ts.get_available()
|
|
if not vim.g.ts_available then
|
|
vim.g.ts_available = available
|
|
end
|
|
if vim.tbl_contains(available, lang) then
|
|
ts.install(lang)
|
|
end
|
|
end
|
|
|
|
if vim.treesitter.language.add(lang) then
|
|
vim.treesitter.start(args.buf, lang)
|
|
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
|
vim.wo[0][0].foldexpr = "v:lua.vim.treesitter.foldexpr()"
|
|
vim.wo[0][0].foldmethod = "expr"
|
|
end
|
|
end,
|
|
})
|