Auto install and auto start treesitter
This commit is contained in:
parent
348358bd6f
commit
c248827792
|
@ -33,14 +33,22 @@ vim.api.nvim_create_autocmd({ "InsertEnter", "WinLeave" }, {
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Auto install treesitter parser and start them
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
pattern = require("tools.highlight"),
|
desc = "Enable Treesitter",
|
||||||
callback = function()
|
group = vim.api.nvim_create_augroup("enable_treesitter", {}),
|
||||||
-- syntax highlighting, provided by Neovim
|
callback = function(event)
|
||||||
vim.treesitter.start()
|
local has_treesitter, treesitter = pcall(require, "nvim-treesitter")
|
||||||
-- folds, provided by Neovim
|
if has_treesitter then
|
||||||
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
|
local language = vim.treesitter.language.get_lang(event.match)
|
||||||
-- indentation, provided by nvim-treesitter
|
treesitter.install(language):await(function()
|
||||||
|
if pcall(vim.treesitter.start) then
|
||||||
|
-- Use Treesitter indentation and folds.
|
||||||
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||||
|
vim.wo.foldmethod = "expr"
|
||||||
|
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
@ -11,12 +11,8 @@ return {
|
||||||
branch = "main",
|
branch = "main",
|
||||||
build = ":TSUpdate",
|
build = ":TSUpdate",
|
||||||
opts = {
|
opts = {
|
||||||
-- Add languages to be installed here that you want installed for treesitter
|
|
||||||
ensure_installed = require("tools.highlight"),
|
ensure_installed = require("tools.highlight"),
|
||||||
|
|
||||||
-- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
|
|
||||||
auto_install = true,
|
|
||||||
|
|
||||||
highlight = { enable = true },
|
highlight = { enable = true },
|
||||||
indent = { enable = true },
|
indent = { enable = true },
|
||||||
incremental_selection = {
|
incremental_selection = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user