Files
nvimconfig/lua/plugins/native/treesitter.lua
T

110 lines
3.0 KiB
Lua

local M = {}
function M.setup()
local ok_ts, ts = pcall(require, "nvim-treesitter")
if not ok_ts then
vim.schedule(function()
vim.notify("nvim-treesitter is not ready yet. Wait for background plugin install and restart Neovim.",
vim.log.levels.WARN)
end)
return
end
local move_config = {
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",
},
}
ts.setup({
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",
},
highlight = { enable = true },
indent = { enable = true },
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 = move_config.goto_next_start,
goto_next_end = move_config.goto_next_end,
goto_previous_start = move_config.goto_previous_start,
goto_previous_end = move_config.goto_previous_end,
},
},
})
local ok_move, move = pcall(require, "nvim-treesitter.textobjects.move")
if not ok_move then
return
end
for name, fn in pairs(move) do
if name:find("goto") == 1 then
move[name] = function(query, ...)
if vim.wo.diff then
local config = move_config[name]
for key, textobject in pairs(config or {}) do
if query == textobject and key:find("[%]%[][cC]") then
vim.cmd("normal! " .. key)
return
end
end
end
return fn(query, ...)
end
end
end
end
return M