From 6d0cbe06cc889a4d4b6955a45a360bc635c147b0 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 10 Dec 2023 11:05:26 +0800 Subject: [PATCH] Update treesitter Signed-off-by: Ryan --- lazy-lock.json | 6 +-- lua/lazy-plugins.lua | 11 ++-- lua/plugins/treesitter.lua | 105 ++++++++++++++++++++++++++++++++++--- 3 files changed, 104 insertions(+), 18 deletions(-) diff --git a/lazy-lock.json b/lazy-lock.json index 0cf2bba..b66d1a8 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -10,7 +10,6 @@ "diffview.nvim": { "branch": "main", "commit": "3dc498c9777fe79156f3d32dddd483b8b3dbd95f" }, "dressing.nvim": { "branch": "master", "commit": "8b7ae53d7f04f33be3439a441db8071c96092d19" }, "friendly-snippets": { "branch": "main", "commit": "53d3df271d031c405255e99410628c26a8f0d2b0" }, - "gitmoji.nvim": { "branch": "main", "commit": "326ddf01cbf3425566a089126ece7e8bd2560601" }, "gitsigns.nvim": { "branch": "main", "commit": "87640f5a877b18bdd49884dbcac220fed924b867" }, "gruvbox-material": { "branch": "master", "commit": "7f56d9f9c4860df528031539d321a61f6e081dee" }, "killersheep.nvim": { "branch": "master", "commit": "506823c47b854df02e78d5fec9468ab0e542dcf5" }, @@ -25,9 +24,10 @@ "nvim-bqf": { "branch": "main", "commit": "bdc2a4e5bb670b3c0e33ada9c0eec636d93a0748" }, "nvim-cmp": { "branch": "main", "commit": "0b751f6beef40fd47375eaf53d3057e0bfa317e4" }, "nvim-colorizer.lua": { "branch": "master", "commit": "dde3084106a70b9a79d48f426f6d6fec6fd203f7" }, - "nvim-lspconfig": { "branch": "master", "commit": "511609ae0311abfcfaed3c398429a147e895ce2c" }, - "nvim-treesitter": { "branch": "master", "commit": "1b5bbb54b385c4eae217113f72df5284bc3cc94b" }, + "nvim-lspconfig": { "branch": "master", "commit": "bd405e45c5fb122c16af8f87fa2dd7ab1981b243" }, + "nvim-treesitter": { "branch": "master", "commit": "7958ff9ec7a2baea2842323d0e7ac67a509da4d2" }, "nvim-treesitter-context": { "branch": "master", "commit": "cfa8ee19ac9bae9b7fb2958eabe2b45b70c56ccb" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "ec1c5bdb3d87ac971749fa6c7dbc2b14884f1f6a" }, "nvim-web-devicons": { "branch": "master", "commit": "8b2e5ef9eb8a717221bd96cb8422686d65a09ed5" }, "plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" }, "rainbow_csv.nvim": { "branch": "main", "commit": "a520dabf1c74d7d7d8341dd3f3570063ef51b3aa" }, diff --git a/lua/lazy-plugins.lua b/lua/lazy-plugins.lua index 5ae4aa0..79fe66c 100644 --- a/lua/lazy-plugins.lua +++ b/lua/lazy-plugins.lua @@ -47,18 +47,15 @@ local plugins = { { "nvim-treesitter/nvim-treesitter", - lazy = true, config = function() require("plugins.treesitter") end, - build = ":TSUpdate" - }, - { - "nvim-treesitter/nvim-treesitter-context", event = { "BufReadPre", "BufNewFile" }, + build = ":TSUpdate", dependencies = { - "nvim-treesitter/nvim-treesitter", - }, + "nvim-treesitter/nvim-treesitter-context", + "nvim-treesitter/nvim-treesitter-textobjects" + } }, { "L3MON4D3/LuaSnip", diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index c78c603..d20a1f8 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -1,13 +1,102 @@ require("nvim-treesitter.configs").setup({ - ensure_installed = { "lua" }, -- one of "all", "maintained" (parsers with maintainers), or a list of languages + ensure_installed = { + "lua", + "gitignore", + "gitattributes", + "gitcommit", + "git_config", + "git_rebase", + "vim", + "vimdoc", + "query" + }, -- one of "all", "maintained" (parsers with maintainers), or a list of languages highlight = { - enable = true, -- false will disable the whole extension - -- Setting this to true will run `:h syntax` and tree-sitter at the same time. - -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). - -- Using this option may slow down your editor, and you may see some duplicate highlights. - -- Instead of true it can also be a list of languages - additional_vim_regex_highlighting = true, - use_languagetree = true, + enable = true, -- false will disable the whole extension + additional_vim_regex_highlighting = true, -- git commit, etc. + disable = function(lang, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, }, indent = { enable = true }, + textobjects = { + select = { + enable = true, + + -- Automatically jump forward to textobj, similar to targets.vim + lookahead = true, + + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@class.outer", + -- You can optionally set descriptions to the mappings (used in the desc parameter of + -- nvim_buf_set_keymap) which plugins like which-key display + ["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" }, + -- You can also use captures from other query groups like `locals.scm` + ["as"] = { query = "@scope", query_group = "locals", desc = "Select language scope" }, + }, + selection_modes = { + ['@parameter.outer'] = 'v', -- charwise + ['@function.outer'] = 'V', -- linewise + ['@class.outer'] = '', -- blockwise + }, + -- If you set this to `true` (default is `false`) then any textobject is + -- extended to include preceding or succeeding whitespace. Succeeding + -- whitespace has priority in order to act similarly to eg the built-in + -- `ap`. + -- + -- Can also be a function which gets passed a table with the keys + -- * query_string: eg '@function.inner' + -- * selection_mode: eg 'v' + -- and should return true of false + include_surrounding_whitespace = true, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + ["]m"] = "@function.outer", + ["]]"] = { query = "@class.outer", desc = "Next class start" }, + ["]o"] = "@loop.*", + ["]z"] = { query = "@fold", query_group = "folds", desc = "Next fold" }, + }, + goto_next_end = { + ["]M"] = "@function.outer", + ["]["] = "@class.outer", + }, + goto_previous_start = { + ["[m"] = "@function.outer", + ["[["] = "@class.outer", + }, + goto_previous_end = { + ["[M"] = "@function.outer", + ["[]"] = "@class.outer", + }, + -- Below will go to either the start or the end, whichever is closer. + -- Use if you want more granular movements + -- Make it even more gradual by adding multiple queries and regex. + goto_next = { + ["]d"] = "@conditional.outer", + }, + goto_previous = { + ["[d"] = "@conditional.outer", + } + }, + }, }) +local ts_repeat_move = require "nvim-treesitter.textobjects.repeatable_move" + +-- Repeat movement with ; and , +-- vim way: ; goes to the direction you were moving. +vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move) +vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_opposite) +-- Optionally, make builtin f, F, t, T also repeatable with ; and , +vim.keymap.set({ "n", "x", "o" }, "f", ts_repeat_move.builtin_f) +vim.keymap.set({ "n", "x", "o" }, "F", ts_repeat_move.builtin_F) +vim.keymap.set({ "n", "x", "o" }, "t", ts_repeat_move.builtin_t) +vim.keymap.set({ "n", "x", "o" }, "T", ts_repeat_move.builtin_T)