nvim/lua/custom/plugins/tree-sitter.lua
Jeremie Fraeys 02e26b00b7
Some checks are pending
Check Lua Formatting in MyRepo / Stylua Check (push) Waiting to run
chore(nvim): reinitialize with working config
2026-02-07 21:06:45 -05:00

106 lines
2.8 KiB
Lua
Executable file

return {
'nvim-treesitter/nvim-treesitter',
branch = 'master',
version = false, -- last release is too old and doesn't work on Windows
build = ':TSUpdate',
event = { 'VeryLazy' },
lazy = vim.fn.argc(-1) == 0, -- load treesitter early when opening a file from the cmdline
init = function(plugin)
-- PERF: add nvim-treesitter queries to the rtp and its custom query predicates early
require('lazy.core.loader').add_to_rtp(plugin)
require('nvim-treesitter.query_predicates')
end,
cmd = { 'TSUpdateSync', 'TSUpdate', 'TSInstall' },
keys = {
{ '<c-space>', desc = 'Increment Selection' },
{ '<bs>', desc = 'Decrement Selection', mode = 'x' },
},
opts_extend = { 'ensure_installed' },
---@type TSConfig
---@diagnostic disable-next-line: missing-fields
opts = {
highlight = { enable = true },
indent = { enable = true },
ensure_installed = {
'bash',
'c',
'html',
'javascript',
'jsdoc',
'json',
'jsonc',
'lua',
'luadoc',
'markdown',
'markdown_inline',
'python',
'query',
'toml',
'vim',
'vimdoc',
'yaml',
'sql',
'zig',
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = 'gnn',
node_incremental = 'grn',
scope_incremental = 'grc',
node_decremental = 'grm',
},
},
textobjects = {
select = {
enable = true,
lookahead = true,
keymaps = {
['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner',
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
},
},
move = {
enable = true,
set_jumps = true,
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@class.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@class.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@class.outer',
},
},
swap = {
enable = true,
swap_next = {
['<leader>i'] = '@parameter.inner',
},
swap_previous = {
['<leader>I'] = '@parameter.inner',
},
},
},
},
---@param opts TSConfig
config = function(_, opts)
-- Ensure no duplicates in the ensure_installed list
if type(opts.ensure_installed) == 'table' then
opts.ensure_installed = vim.tbl_deep_extend('force', {}, opts.ensure_installed)
end
require('nvim-treesitter.configs').setup(opts)
end,
}