93 lines
2.6 KiB
Lua
93 lines
2.6 KiB
Lua
return {
|
|
-- Treesitter is a new parser generator tool that we can
|
|
-- use in Neovim to power faster and more accurate
|
|
-- syntax highlighting.
|
|
{
|
|
"nvim-treesitter/nvim-treesitter",
|
|
version = false, -- last release is way too old and doesn't work on Windows
|
|
build = ":TSUpdate",
|
|
event = { "LazyFile", "VeryLazy" },
|
|
dependencies = {
|
|
{
|
|
"nvim-treesitter/nvim-treesitter-textobjects",
|
|
config = function()
|
|
-- Disable class keymaps in diff mode
|
|
vim.api.nvim_create_autocmd("BufReadPost", {
|
|
callback = function(event)
|
|
if vim.wo.diff then
|
|
for _, key in ipairs({ "[c", "]c", "[C", "]C" }) do
|
|
pcall(vim.keymap.del, "n", key, { buffer = event.buf })
|
|
end
|
|
end
|
|
end,
|
|
})
|
|
end,
|
|
},
|
|
},
|
|
cmd = { "TSUpdateSync" },
|
|
keys = {
|
|
{ "<c-space>", desc = "Increment selection" },
|
|
{ "<bs>", desc = "Decrement selection", mode = "x" },
|
|
},
|
|
---@type TSConfig
|
|
opts = {
|
|
highlight = { enable = true },
|
|
indent = { enable = true },
|
|
ensure_installed = {
|
|
"bash",
|
|
"c",
|
|
"html",
|
|
"javascript",
|
|
"jsdoc",
|
|
"json",
|
|
"lua",
|
|
"luadoc",
|
|
"luap",
|
|
"markdown",
|
|
"markdown_inline",
|
|
"python",
|
|
"query",
|
|
"regex",
|
|
"tsx",
|
|
"typescript",
|
|
"vim",
|
|
"vimdoc",
|
|
"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" },
|
|
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" },
|
|
},
|
|
},
|
|
},
|
|
---@param opts TSConfig
|
|
config = function(_, opts)
|
|
if type(opts.ensure_installed) == "table" then
|
|
---@type table<string, boolean>
|
|
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,
|
|
},
|
|
}
|