Update treesitter vor nvim 0.12
This commit is contained in:
parent
8831bbe952
commit
af39061406
5 changed files with 157 additions and 172 deletions
|
|
@ -1,122 +1,7 @@
|
|||
local function ts_disable(_, bufnr)
|
||||
return vim.api.nvim_buf_line_count(bufnr) > 5000
|
||||
end
|
||||
|
||||
return {
|
||||
{
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
version = false,
|
||||
build = ":TSUpdate",
|
||||
event = { "BufReadPost", "BufNewFile" },
|
||||
dependencies = {
|
||||
{
|
||||
"nvim-treesitter/nvim-treesitter-textobjects",
|
||||
init = function()
|
||||
-- PERF: no need to load the plugin, if we only need its queries for mini.ai
|
||||
local plugin = require("lazy.core.config").spec.plugins["nvim-treesitter"]
|
||||
local opts = require("lazy.core.plugin").values(plugin, "opts", false)
|
||||
local enabled = false
|
||||
if opts.textobjects then
|
||||
for _, mod in ipairs({ "move", "select", "swap", "lsp_interop" }) do
|
||||
if opts.textobjects[mod] and opts.textobjects[mod].enable then
|
||||
enabled = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not enabled then
|
||||
require("lazy.core.loader").disable_rtp_plugin("nvim-treesitter-textobjects")
|
||||
end
|
||||
end,
|
||||
},
|
||||
},
|
||||
keys = {
|
||||
{ "<c-space>", desc = "Increment selection" },
|
||||
{ "<bs>", desc = "Decrement selection", mode = "x" },
|
||||
},
|
||||
opts = {
|
||||
auto_install = true,
|
||||
ignore_install = {},
|
||||
highlight = { enable = true, disable = ts_disable },
|
||||
indent = { enable = true },
|
||||
ensure_installed = {
|
||||
"bash",
|
||||
"gitignore",
|
||||
"html",
|
||||
"java",
|
||||
"json",
|
||||
"lua",
|
||||
"luadoc",
|
||||
"luap",
|
||||
"markdown",
|
||||
"markdown_inline",
|
||||
"python",
|
||||
"query",
|
||||
"regex",
|
||||
"scala",
|
||||
"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 = {
|
||||
select = {
|
||||
enable = true,
|
||||
lookahead = true,
|
||||
keymaps = {
|
||||
-- stylua: ignore start
|
||||
["af"] = { query = "@function.outer", desc = "outer function" },
|
||||
["if"] = { query = "@function.inner", desc = "inner function" },
|
||||
["ac"] = { query = "@class.outer", desc = "outer class" },
|
||||
["ic"] = { query = "@class.inner", desc = "inner class" },
|
||||
["ap"] = { query = "@parameter.outer", desc = "outer parameter" },
|
||||
["ip"] = { query = "@parameter.inner", desc = "inner parameter" },
|
||||
["ar"] = { query = "@return_type.outer", desc = "outer return type" },
|
||||
["ir"] = { query = "@return_type.inner", desc = "inner return type" },
|
||||
-- stylua: ignore end
|
||||
},
|
||||
selection_modes = {
|
||||
["@parameter.outer"] = "v", -- charwise
|
||||
["@function.outer"] = "V", -- linewise
|
||||
["@class.outer"] = "V",
|
||||
},
|
||||
},
|
||||
swap = {
|
||||
enable = true,
|
||||
swap_next = {
|
||||
["<leader>a"] = "@parameter.inner",
|
||||
},
|
||||
swap_previous = {
|
||||
["<leader>A"] = "@parameter.inner",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
---@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 --[[@as string[] ]])
|
||||
end
|
||||
require("nvim-treesitter.configs").setup(opts)
|
||||
end,
|
||||
},
|
||||
{
|
||||
"nvim-treesitter/playground",
|
||||
|
|
@ -145,4 +30,61 @@ return {
|
|||
vim.api.nvim_set_hl(0, "TreesitterContextLineNumber", { link = "Special" })
|
||||
end,
|
||||
},
|
||||
{
|
||||
"nvim-treesitter/nvim-treesitter-textobjects",
|
||||
branch = "main",
|
||||
dependencies = { "nvim-treesitter/nvim-treesitter" },
|
||||
init = function()
|
||||
-- Disable entire built-in ftplugin mappings to avoid conflicts.
|
||||
-- See https://github.com/neovim/neovim/tree/master/runtime/ftplugin for built-in ftplugins.
|
||||
vim.g.no_plugin_maps = true
|
||||
end,
|
||||
config = function()
|
||||
require("nvim-treesitter-textobjects").setup({
|
||||
select = {
|
||||
lookahead = true,
|
||||
selection_modes = {
|
||||
["@parameter.outer"] = "v", -- charwise
|
||||
["@function.outer"] = "V", -- linewise
|
||||
["@class.outer"] = "V",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
vim.keymap.set("n", "<leader>a", function()
|
||||
require("nvim-treesitter-textobjects.swap").swap_next("@parameter.inner")
|
||||
end)
|
||||
vim.keymap.set("n", "<leader>A", function()
|
||||
require("nvim-treesitter-textobjects.swap").swap_previous("@parameter.outer")
|
||||
end)
|
||||
vim.keymap.set({ "x", "o" }, "af", function()
|
||||
require("nvim-treesitter-textobjects.select").select_textobject("@function.outer", "textobjects")
|
||||
end)
|
||||
vim.keymap.set({ "x", "o" }, "if", function()
|
||||
require("nvim-treesitter-textobjects.select").select_textobject("@function.inner", "textobjects")
|
||||
end)
|
||||
vim.keymap.set({ "x", "o" }, "ac", function()
|
||||
require("nvim-treesitter-textobjects.select").select_textobject("@class.outer", "textobjects")
|
||||
end)
|
||||
vim.keymap.set({ "x", "o" }, "ic", function()
|
||||
require("nvim-treesitter-textobjects.select").select_textobject("@class.inner", "textobjects")
|
||||
end)
|
||||
vim.keymap.set({ "x", "o" }, "ap", function()
|
||||
require("nvim-treesitter-textobjects.select").select_textobject("@parameter.outer", "textobjects")
|
||||
end)
|
||||
vim.keymap.set({ "x", "o" }, "ip", function()
|
||||
require("nvim-treesitter-textobjects.select").select_textobject("@parameter.inner", "textobjects")
|
||||
end)
|
||||
vim.keymap.set({ "x", "o" }, "ar", function()
|
||||
require("nvim-treesitter-textobjects.select").select_textobject("@return_type.outer", "textobjects")
|
||||
end)
|
||||
vim.keymap.set({ "x", "o" }, "ir", function()
|
||||
require("nvim-treesitter-textobjects.select").select_textobject("@return_type.inner", "textobjects")
|
||||
end)
|
||||
-- You can also use captures from other query groups like `locals.scm`
|
||||
vim.keymap.set({ "x", "o" }, "as", function()
|
||||
require("nvim-treesitter-textobjects.select").select_textobject("@local.scope", "locals")
|
||||
end)
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue