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

101 lines
3.9 KiB
Lua

return {
{
"nvim-treesitter/nvim-treesitter",
version = false, -- last release is way too old and doesn't work on Windows
build = ":TSUpdate",
init = function(plugin)
-- PERF: add nvim-treesitter queries to the rtp and it's custom query predicates early
-- This is needed because a bunch of plugins no longer `require("nvim-treesitter")`, which
-- no longer trigger the **nvim-treeitter** module to be loaded in time.
-- Luckily, the only thins that those plugins need are the custom queries, which we make available
-- during startup.
require("lazy.core.loader").add_to_rtp(plugin)
require("nvim-treesitter.query_predicates")
end,
dependencies = { "nvim-treesitter/nvim-treesitter-textobjects" },
opts = {
highlight = { enable = true },
indent = { enable = true },
ensure_installed = {
"bash",
"c",
"diff",
"html",
"javascript",
"json",
"lua",
"luadoc",
"luap",
"markdown",
"markdown_inline",
"python",
"toml",
"vim",
"vimdoc",
"yaml",
"dockerfile",
"go",
"haskell",
"rust",
},
textobjects = {
move = {
enable = true,
goto_next_start = { ["]f"] = "@function.outer", ["]c"] = "@class.outer" },
goto_next_end = { ["]F"] = "@function.outer", ["]C"] = "@class.outer" },
goto_previous_start = { ["[f"] = "@function.outer", ["[c"] = "@class.outer" },
goto_previous_end = { ["[F"] = "@function.outer", ["[C"] = "@class.outer" },
},
},
},
config = function(_, opts)
if type(opts.ensure_installed) == "table" then
local added = {}
opts.ensure_installed = vim.tbl_filter(function(lang)
if added[lang] then
return false
end
added[lang] = true
return true
end, opts.ensure_installed)
end
require("nvim-treesitter.configs").setup(opts)
end,
},
{
"romgrk/nvim-treesitter-context",
config = function()
require("treesitter-context").setup({
throttle = true, -- Throttles plugin updates (may improve performance)
max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit.
show_all_context = false,
patterns = { -- Match patterns for TS nodes. These get wrapped to match at word boundaries.
-- For all filetypes
-- Note that setting an entry here replaces all other patterns for this entry.
-- By setting the 'default' entry below, you can control which nodes you want to
-- appear in the context window.
default = {
"function",
"method",
"for",
"while",
"if",
"switch",
"case",
},
rust = {
"loop_expression",
"impl_item",
},
typescript = {
"class_declaration",
"abstract_class_declaration",
"else_clause",
},
},
})
end
}
}