97 lines
3.0 KiB
Lua
97 lines
3.0 KiB
Lua
-- ~/.config/nvim/lua/custom/plugins/treesitter.lua
|
|
|
|
return {
|
|
{
|
|
'nvim-treesitter/nvim-treesitter',
|
|
version = false, -- last release is way too old and doesn't work on Windows
|
|
build = ':TSUpdate',
|
|
event = { 'BufRead', 'BufNewFile' },
|
|
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
|
|
-- This is needed because a bunch of plugins no longer `require("nvim-treesitter")`, which
|
|
-- no longer triggers the **nvim-treesitter** module to be loaded in time.
|
|
-- Luckily, the only things 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,
|
|
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',
|
|
'diff',
|
|
'html',
|
|
'javascript',
|
|
'jsdoc',
|
|
'json',
|
|
'jsonc',
|
|
'lua',
|
|
'luadoc',
|
|
'luap',
|
|
'markdown',
|
|
'markdown_inline',
|
|
'printf',
|
|
'python',
|
|
'query',
|
|
'regex',
|
|
'toml',
|
|
'tsx',
|
|
'typescript',
|
|
'vim',
|
|
'vimdoc',
|
|
'xml',
|
|
'yaml',
|
|
},
|
|
incremental_selection = {
|
|
enable = true,
|
|
keymaps = {
|
|
init_selection = '<C-space>',
|
|
node_incremental = '<C-space>',
|
|
scope_incremental = false,
|
|
node_decremental = '<bs>',
|
|
},
|
|
},
|
|
textobjects = {
|
|
move = {
|
|
enable = true,
|
|
goto_next_start = { [']f'] = '@function.outer', [']c'] = '@class.outer', [']a'] = '@parameter.inner' },
|
|
goto_next_end = { [']F'] = '@function.outer', [']C'] = '@class.outer', [']A'] = '@parameter.inner' },
|
|
goto_previous_start = { ['[f'] = '@function.outer', ['[c'] = '@class.outer', ['[a'] = '@parameter.inner' },
|
|
goto_previous_end = { ['[F'] = '@function.outer', ['[C'] = '@class.outer', ['[A'] = '@parameter.inner' },
|
|
},
|
|
},
|
|
},
|
|
---@param opts TSConfig
|
|
config = function(_, opts)
|
|
-- Ensure the list is deduplicated manually
|
|
if type(opts.ensure_installed) == 'table' then
|
|
local seen = {}
|
|
local deduped = {}
|
|
for _, item in ipairs(opts.ensure_installed) do
|
|
if not seen[item] then
|
|
table.insert(deduped, item)
|
|
seen[item] = true
|
|
end
|
|
end
|
|
opts.ensure_installed = deduped
|
|
end
|
|
require('nvim-treesitter.configs').setup(opts)
|
|
end,
|
|
},
|
|
{
|
|
'windwp/nvim-ts-autotag',
|
|
after = 'nvim-treesitter',
|
|
},
|
|
}
|