summary refs log tree commit diff
path: root/.vim/lua/internal/plugins/treesitter.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.vim/lua/internal/plugins/treesitter.lua124
1 files changed, 124 insertions, 0 deletions
diff --git a/.vim/lua/internal/plugins/treesitter.lua b/.vim/lua/internal/plugins/treesitter.lua
new file mode 100644
index 0000000..b8b1d56
--- /dev/null
+++ b/.vim/lua/internal/plugins/treesitter.lua
@@ -0,0 +1,124 @@
+return {
+  {
+    'nvim-treesitter/nvim-treesitter',
+    dependencies = {
+      -- TODO: https://github.com/nvim-treesitter/nvim-treesitter-context
+      { 'nvim-treesitter/nvim-treesitter-refactor', lazy = false },
+      { 'nvim-treesitter/nvim-treesitter-textobjects', lazy = false },
+      { 'nvim-treesitter/playground', cmd = { 'TSPlayground' } },
+    },
+    lazy = false,
+    build = ':TSUpdate',
+    config = function(_, opts)
+      -- TODO: overwrite parser configs, insert gotmpl
+
+      require('nvim-treesitter.configs').setup(opts)
+
+      -- use bash parser for gentoo ebuilds
+      vim.treesitter.language.register('bash', 'ebuild')
+
+      -- register mediawiki parser
+      -- local parser_configs = require('nvim-treesitter.parsers').get_parser_configs()
+      -- parser_configs.mediawiki = {
+      --   install_info = {
+      --     url = 'github.com/Ordoviz/tree-sitter-mediawiki',
+      --     files = { 'src/parser.c' },
+      --     branch = 'main',
+      --     generate_requires_npm = false,
+      --     requires_generate_from_grammar = false,
+      --   },
+      --   filetype = 'mediawiki',
+      -- }
+    end,
+    opts = {
+      ensure_installed = {
+        'bash',
+        'bibtex',
+        'c',
+        'c_sharp',
+        'cmake',
+        'comment',
+        'cpp',
+        'css',
+        'dockerfile',
+        'go',
+        'gomod',
+        'gotmpl',
+        'gowork',
+        'hare',
+        'hcl',
+        'html',
+        'java',
+        'javascript',
+        'json',
+        'jsonc',
+        'kotlin',
+        'latex',
+        'ledger',
+        'lua',
+        'make',
+        'markdown',
+        'markdown_inline',
+        'ninja',
+        'norg',
+        'python',
+        'query',
+        'regex',
+        'rust',
+        'scss',
+        'sql',
+        'toml',
+        'typescript',
+        'vim',
+        'vimdoc',
+        'yaml',
+        'zig',
+
+        -- external parsers
+        -- 'mediawiki', -- TODO: missing queries
+      },
+      highlight = {
+        enable = true,
+        additional_vim_regex_highlighting = { 'markdown' },
+      },
+      indent = {
+        enable = true,
+      },
+      refactor = {
+        navigation = {
+          enable = true,
+          keymaps = {
+            goto_definition = 'gd',
+          },
+        },
+        smart_rename = {
+          enable = true,
+          keymaps = {
+            smart_rename = 'grr',
+          },
+        },
+      },
+      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.outer',
+          },
+          selection_mode = {
+            ['@comment.outer'] = 'V',
+          },
+        },
+      },
+    },
+  },
+}