From 523730efdb737006941f4aea27196a51b3e72fe3 Mon Sep 17 00:00:00 2001 From: Jose Carvajal Date: Tue, 10 Jun 2025 15:33:05 -0600 Subject: [PATCH] Update treesitter branch from master to main; added treesitter-textbjects --- lazy-lock.json | 19 ++++---- lua/kickstart/plugins/treesitter.lua | 72 +++++++++++++++++++++------- 2 files changed, 65 insertions(+), 26 deletions(-) diff --git a/lazy-lock.json b/lazy-lock.json index 400a9cb4..cc2c796a 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,27 +1,28 @@ { "LuaSnip": { "branch": "master", "commit": "458560534a73f7f8d7a11a146c801db00b081df0" }, "blink.cmp": { "branch": "main", "commit": "022521a8910a5543b0251b21c9e1a1e989745796" }, - "catppuccin": { "branch": "main", "commit": "a0c769bc7cd04bbbf258b3d5f01e2bdce744108d" }, - "conform.nvim": { "branch": "master", "commit": "0e93e0d12d2f7ebdea9e3e444dfaff0050cefbe6" }, + "catppuccin": { "branch": "main", "commit": "fa42eb5e26819ef58884257d5ae95dd0552b9a66" }, + "conform.nvim": { "branch": "master", "commit": "8132ec733eed3bf415b97b76797ca41b59f51d7d" }, "fidget.nvim": { "branch": "main", "commit": "d9ba6b7bfe29b3119a610892af67602641da778e" }, "flash.nvim": { "branch": "main", "commit": "3c942666f115e2811e959eabbdd361a025db8b63" }, - "fzf-lua": { "branch": "main", "commit": "6d1d81a5c7936d82a47a41a521958e482e499fde" }, + "fzf-lua": { "branch": "main", "commit": "1977a7648a264fabf453ee082e2398e38cc3b588" }, "gitsigns.nvim": { "branch": "main", "commit": "d0f90ef51d4be86b824b012ec52ed715b5622e51" }, "guess-indent.nvim": { "branch": "main", "commit": "84a4987ff36798c2fc1169cbaff67960aed9776f" }, "harpoon": { "branch": "harpoon2", "commit": "ed1f853847ffd04b2b61c314865665e1dadf22c7" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, "lazydev.nvim": { "branch": "main", "commit": "2367a6c0a01eb9edb0464731cc0fb61ed9ab9d2c" }, - "lualine.nvim": { "branch": "master", "commit": "0c6cca9f2c63dadeb9225c45bc92bb95a151d4af" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "c2682b0d9732bf52cbc34862056f143e71dc4a6d" }, + "lualine.nvim": { "branch": "master", "commit": "a94fc68960665e54408fe37dcf573193c4ce82c9" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "bef29b653ba71d442816bf56286c2a686210be04" }, "mason-tool-installer.nvim": { "branch": "main", "commit": "93a9ff9b34c91c0cb0f7de8d5f7e4abce51d8903" }, "mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" }, "mini.icons": { "branch": "main", "commit": "397ed3807e96b59709ef3292f0a3e253d5c1dc0a" }, - "mini.nvim": { "branch": "main", "commit": "5a10dfb3ab49b3ee2425bc2c215b5067ccce1c79" }, + "mini.nvim": { "branch": "main", "commit": "35e1767f4cd7dde51256eabae7349a5283a43cba" }, "noice.nvim": { "branch": "main", "commit": "0427460c2d7f673ad60eb02b35f5e9926cf67c59" }, - "nui.nvim": { "branch": "main", "commit": "7cd18e73cfbd70e1546931b7268b3eebaeff9391" }, - "nvim-lspconfig": { "branch": "master", "commit": "036885e8e5456d3907626b634693234f628afef6" }, + "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, + "nvim-lspconfig": { "branch": "master", "commit": "77d3fdfb3554632c7a3b101ded643d422de7626f" }, "nvim-notify": { "branch": "master", "commit": "b5825cf9ee881dd8e43309c93374ed5b87b7a896" }, - "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, + "nvim-treesitter": { "branch": "main", "commit": "0fb1c6e92e6a03374d578b362301dbd22abd3840" }, + "nvim-treesitter-textobjects": { "branch": "main", "commit": "fa32a45fdbab9c9c3bda9ecec9b12dddb221b927" }, "nvim-web-devicons": { "branch": "master", "commit": "1fb58cca9aebbc4fd32b086cb413548ce132c127" }, "oil.nvim": { "branch": "master", "commit": "08c2bce8b00fd780fb7999dbffdf7cd174e896fb" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, diff --git a/lua/kickstart/plugins/treesitter.lua b/lua/kickstart/plugins/treesitter.lua index e7a1c676..f9e0e9eb 100644 --- a/lua/kickstart/plugins/treesitter.lua +++ b/lua/kickstart/plugins/treesitter.lua @@ -2,34 +2,72 @@ return { { -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', lazy = false, - branch = 'master', + branch = 'main', build = ':TSUpdate', + opts = {}, -- main = 'nvim-treesitter.configs', -- Sets main module to use for opts -- [[ Configure Treesitter ]] See `:help nvim-treesitter` config = function() - local configs = require 'nvim-treesitter.configs' + local ensureInstalled = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' } + local alreadyInstalled = require('nvim-treesitter').get_installed 'parsers' + local parsersToInstall = vim + .iter(ensureInstalled) + :filter(function(parser) + return not vim.tbl_contains(alreadyInstalled, parser) + end) + :totable() + print(parsersToInstall) + if #parsersToInstall > 0 then + require('nvim-treesitter').install(parsersToInstall) + end - configs.setup { - ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, - -- Autoinstall languages that are not installed - auto_install = true, - highlight = { - enable = true, - -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules. - -- If you are experiencing weird indenting issues, add the language to - -- the list of additional_vim_regex_highlighting and disabled languages for indent. - additional_vim_regex_highlighting = { 'ruby' }, - }, - indent = { enable = true, disable = { 'ruby' } }, - } + local parsersInstalled = require('nvim-treesitter').get_installed 'parsers' + for _, parser in pairs(parsersInstalled) do + local filetypes = vim.treesitter.language.get_filetypes(parser) + vim.api.nvim_create_autocmd({ 'FileType' }, { + group = vim.api.nvim_create_augroup('EnableTreesitterHighlighting', { clear = true }), + pattern = filetypes, + callback = function(event) + print(event.buf) + local parser_installed = pcall(vim.treesitter.get_parser, event.buf, parser) + if parser_installed then + pcall(vim.treesitter.start, event.buf, parser) + end + end, + }) + end end, - opts = {}, -- There are additional nvim-treesitter modules that you can use to interact -- with nvim-treesitter. You should go explore a few and see what interests you: -- -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod` -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context - -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects + }, + { + 'nvim-treesitter/nvim-treesitter-textobjects', + opts = {}, + branch = 'main', + config = function() + require('nvim-treesitter-textobjects').setup { + select = { + -- Automatically jump forward to textobj, similar to targets.vim + lookahead = true, + }, + } + + vim.keymap.set({ 'x', 'o' }, 'af', function() + require('nvim-treesitter-textobjects.select').select_textobject('@function.outer', 'textobjects') + end, { desc = 'Select outer function' }) + vim.keymap.set({ 'x', 'o' }, 'if', function() + require('nvim-treesitter-textobjects.select').select_textobject('@function.inner', 'textobjects') + end, { desc = 'Select inside function' }) + vim.keymap.set({ 'x', 'o' }, 'ac', function() + require('nvim-treesitter-textobjects.select').select_textobject('@class.outer', 'textobjects') + end, { desc = 'Select outer class' }) + vim.keymap.set({ 'x', 'o' }, 'ic', function() + require('nvim-treesitter-textobjects.select').select_textobject('@class.inner', 'textobjects') + end, { desc = 'Select outer class' }) + end, }, } -- vim: ts=2 sts=2 sw=2 et