dotfiles/nvim/.config/nvim/lua/plugins/treesitter.lua

104 lines
2.7 KiB
Lua

return {
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function()
local rainbow = require("ts-rainbow")
require("nvim-treesitter.configs").setup({
-- one of "all", "maintained" (parsers with maintainers), or a list of languages
ensure_installed = "all",
auto_install = true,
highlight = {
enable = true,
language_tree = true,
disable = function(_, bufnr)
if
vim.api.nvim_buf_line_count(bufnr) > 1000
or vim.fn.strwidth(vim.fn.getline(".")) > 300
or vim.fn.getfsize(vim.fn.expand("%")) > 1024 * 1024
then
return true
end
return false
end,
additional_vim_regex_highlighting = false,
},
incremental_selection = { enable = true },
textobjects = { enable = true },
indent = { enable = true },
autotag = { enable = true },
-- enable rainbow brackets, needs p00f/nvim-ts-rainbow
rainbow = {
enable = true,
strategy = { rainbow.strategy.global },
},
-- allows using . and ; to target treesitter branches
textsubjects = {
enable = true,
keymaps = {
["."] = "textsubjects-smart",
[";"] = "textsubjects-container-outer",
},
},
endwise = {
enable = true
}
})
-- for improved commentstrings, needs corresponding plugin
require("ts_context_commentstring").setup({
enable = true,
enable_autocmd = false, -- since we run it as a hook from the mini.comment plugin
languages = {
nu = "# %s",
},
})
-- treesitter parser for nushell. To fully get e.g. syntax highlight
-- working you need a highlight file too. For now I installed manually, see:
-- https://github.com/nushell/tree-sitter-nu/blob/main/installation/neovim.md
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.nu = {
install_info = {
url = "https://github.com/nushell/tree-sitter-nu",
files = { "src/parser.c" },
branch = "main",
},
filetype = "nu",
}
end,
event = "BufReadPost",
cmd = {
"TSBufDisable",
"TSBufEnable",
"TSBufToggle",
"TSDisable",
"TSEnable",
"TSToggle",
"TSInstall",
"TSInstallInfo",
"TSInstallSync",
"TSModuleInfo",
"TSUninstall",
"TSUpdate",
"TSUpdateSync",
},
-- rainbow brackets using treesitter
-- show current cursor context at top of buffer
-- improves commenting plugin above by using ts
dependencies = {
"https://gitlab.com/HiPhish/nvim-ts-rainbow2.git",
{ "romgrk/nvim-treesitter-context", config = true },
"JoosepAlviste/nvim-ts-context-commentstring",
"RRethy/nvim-treesitter-textsubjects",
"windwp/nvim-ts-autotag",
"RRethy/nvim-treesitter-endwise",
},
},
}