2 { "nvim-treesitter/nvim-treesitter",
3 -- Treesitter is a new parser generator tool that we can
4 -- use in Neovim to power faster and more accurate
5 -- syntax highlighting.
7 event = { "LazyFile", "VeryLazy" },
8 lazy = vim.fn.argc(-1) == 0, -- load treesitter early when opening a file from the cmdline
9 init = function(plugin)
10 -- PERF: add nvim-treesitter queries to the rtp and it's custom query predicates early
11 -- This is needed because a bunch of plugins no longer `require("nvim-treesitter")`, which
12 -- no longer trigger the **nvim-treesitter** module to be loaded in time.
13 -- Luckily, the only things that those plugins need are the custom queries, which we make available
15 require("lazy.core.loader").add_to_rtp(plugin)
16 require("nvim-treesitter.query_predicates")
18 cmd = { "TSUpdateSync", "TSUpdate", "TSInstall" },
20 { "<c-space>", desc = "Increment Selection" },
21 { "<bs>", desc = "Decrement Selection", mode = "x" },
23 opts_extend = { "ensure_installed" },
25 ---@diagnostic disable-next-line: missing-fields
27 highlight = { enable = true },
28 indent = { enable = true },
55 incremental_selection = {
58 init_selection = "<C-space>",
59 node_incremental = "<C-space>",
60 scope_incremental = false,
61 node_decremental = "<bs>",
67 goto_next_start = { ["]f"] = "@function.outer", ["]c"] = "@class.outer", ["]a"] = "@parameter.inner" },
68 goto_next_end = { ["]F"] = "@function.outer", ["]C"] = "@class.outer", ["]A"] = "@parameter.inner" },
69 goto_previous_start = { ["[f"] = "@function.outer", ["[c"] = "@class.outer", ["[a"] = "@parameter.inner" },
70 goto_previous_end = { ["[F"] = "@function.outer", ["[C"] = "@class.outer", ["[A"] = "@parameter.inner" },
74 ---@param opts TSConfig
75 config = function(_, opts)
76 if type(opts.ensure_installed) == "table" then
77 opts.ensure_installed = LazyVim.dedup(opts.ensure_installed)
79 require("nvim-treesitter.configs").setup(opts)
83 { "nvim-treesitter/nvim-treesitter-textobjects",
87 -- If treesitter is already loaded, we need to run config again for textobjects
88 if LazyVim.is_loaded("nvim-treesitter") then
89 local opts = LazyVim.opts("nvim-treesitter")
90 require("nvim-treesitter.configs").setup({ textobjects = opts.textobjects })
93 -- When in diff mode, we want to use the default
94 -- vim text objects c & C instead of the treesitter ones.
95 local move = require("nvim-treesitter.textobjects.move") ---@type table<string,fun(...)>
96 local configs = require("nvim-treesitter.configs")
97 for name, fn in pairs(move) do
98 if name:find("goto") == 1 then
99 move[name] = function(q, ...)
101 local config = configs.get_module("textobjects.move")[name] ---@type table<string,string>
102 for key, query in pairs(config or {}) do
103 if q == query and key:find("[%]%[][cC]") then
104 vim.cmd("normal! " .. key)
116 -- Automatically add closing tags for HTML and JSX
118 "windwp/nvim-ts-autotag",