summary refs log tree commit diff
path: root/.config/nvim/lua/plugins/treesitter.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/plugins/treesitter.lua')
-rw-r--r--.config/nvim/lua/plugins/treesitter.lua65
1 files changed, 17 insertions, 48 deletions
diff --git a/.config/nvim/lua/plugins/treesitter.lua b/.config/nvim/lua/plugins/treesitter.lua
index e064a8b..0978eb7 100644
--- a/.config/nvim/lua/plugins/treesitter.lua
+++ b/.config/nvim/lua/plugins/treesitter.lua
@@ -1,19 +1,26 @@
 return {
   {
     'nvim-treesitter/nvim-treesitter',
-    branch = 'master',
+    branch = 'main',
     lazy = false,
-    dependencies = {
-      { 'nvim-treesitter/nvim-treesitter-refactor', lazy = false },
-      { 'nvim-treesitter/nvim-treesitter-textobjects', lazy = false },
-      -- { 'nvim-treesitter/playground', cmd = { 'TSPlayground' } },
-    },
     build = ':TSUpdate',
     config = function(_, opts)
-      require('nvim-treesitter.configs').setup(opts)
-
-      -- use bash parser for gentoo ebuilds
-      vim.treesitter.language.register('bash', 'ebuild')
+      -- enable indent
+      vim.api.nvim_create_autocmd('FileType', {
+        callback = function()
+          pcall(vim.treesitter.start)
+          vim.bo.indentexpr = [[v:lua.require'nvim-treesitter'.indentexpr()]]
+        end,
+      })
+      -- auto-install
+      local already_installed = require('nvim-treesitter').get_installed()
+      local parsers_installable = vim
+        .iter(opts.ensure_installed)
+        :filter(function(parser)
+          return not vim.tbl_contains(already_installed, parser)
+        end)
+        :totable()
+      require('nvim-treesitter').install(parsers_installable)
     end,
     opts = {
       ensure_installed = {
@@ -31,7 +38,6 @@ return {
         'html',
         'javascript',
         'json',
-        'jsonc',
         'lua',
         'make',
         'markdown',
@@ -51,43 +57,6 @@ return {
         'yaml',
         'zig',
       },
-      highlight = {
-        enable = true,
-        additional_vim_regex_highlighting = { 'markdown' },
-      },
-      indent = {
-        enable = true,
-      },
-      refactor = {
-        navigation = {
-          enable = true,
-        },
-        smart_rename = {
-          enable = true,
-        },
-      },
-      textobjects = {
-        select = {
-          enable = true,
-          keymaps = {
-            ['ib'] = '@block.inner',
-            ['ab'] = '@block.outer',
-            -- ['ic'] = '@conditional.inner',
-            -- ['ac'] = '@conditional.outer',
-            ['if'] = '@function.inner',
-            ['af'] = '@function.outer',
-            ['il'] = '@loop.inner',
-            ['al'] = '@loop.outer',
-            ['is'] = '@scopename.inner',
-            ['as'] = '@scopename.outer',
-            ['ic'] = '@comment.inner',
-            ['ac'] = '@comment.outer',
-          },
-          selection_mode = {
-            ['@comment.outer'] = 'V',
-          },
-        },
-      },
     },
   },
 }