Skip to content

Commit

Permalink
refactor TS
Browse files Browse the repository at this point in the history
  • Loading branch information
mosheavni committed May 5, 2024
1 parent 3ae618e commit c620ddb
Showing 1 changed file with 118 additions and 116 deletions.
234 changes: 118 additions & 116 deletions .config/nvim/lua/plugins/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,137 +28,139 @@ local M = {
event = 'BufReadPost',
}

M.config = function()
require('user.menu').add_actions('TreeSitter', actions())
local configs = require 'nvim-treesitter.configs'
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()
---@diagnostic disable-next-line: inject-field
parser_config.gotmpl = {
install_info = {
url = 'https://github.com/ngalaiko/tree-sitter-go-template',
files = { 'src/parser.c' },
},
filetype = 'gotmpl',
used_by = { 'gohtmltmpl', 'gotexttmpl', 'gotmpl' },
}
M.opts = {
ensure_installed = {
'awk',
'bash',
'comment',
'dockerfile',
'embedded_template',
'git_config',
'gitcommit',
'gitignore',
'go',
'graphql',
'groovy',
'hcl',
'hjson',
'html',
'http',
'java',
'javascript',
'json',
'jsonc',
'lua',
'make',
'markdown',
'markdown_inline',
'python',
'query',
'regex',
'scss',
'ssh_config',
'terraform',
'toml',
'tsx',
'typescript',
'vim',
'vimdoc',
'xml',
'yaml',
},

---@diagnostic disable-next-line: missing-fields
configs.setup {
ensure_installed = {
'awk',
'bash',
'comment',
'dockerfile',
'embedded_template',
'git_config',
'gitcommit',
'gitignore',
'go',
'graphql',
'groovy',
'hcl',
'hjson',
'html',
'http',
'java',
'javascript',
'json',
'jsonc',
'lua',
'make',
'markdown',
'markdown_inline',
'python',
'query',
'regex',
'scss',
'ssh_config',
'terraform',
'toml',
'tsx',
'typescript',
'vim',
'vimdoc',
'xml',
'yaml',
incremental_selection = {
enable = true,
keymaps = {
init_selection = 'vn',
node_incremental = '<CR>',
scope_incremental = '<S-CR>',
node_decremental = '<BS>',
},
incremental_selection = {
},
matchup = {
enable = true,
},
endwise = {
enable = true,
},
autotag = {
enable = true,
},
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
indent = {
enable = true,
disable = { 'yaml' },
},
textobjects = {
select = {
enable = true,
lookahead = true,
keymaps = {
init_selection = 'vn',
node_incremental = '<CR>',
scope_incremental = '<S-CR>',
node_decremental = '<BS>',
['ab'] = '@block.outer',
['ib'] = '@block.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
['af'] = '@function.outer',
['if'] = '@function.inner',
['ao'] = '@object.outer',
['io'] = '@object.inner',
},
},
matchup = {
enable = true,
},
endwise = {
enable = true,
},
autotag = {
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@block.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@block.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@block.outer',
},
},
highlight = {
},
refactor = {
highlight_current_scope = { enable = false },
smart_rename = {
enable = true,
additional_vim_regex_highlighting = false,
keymaps = {
smart_rename = 'grr',
},
},
indent = {
highlight_definitions = {
enable = true,
disable = { 'yaml' },
},
textobjects = {
select = {
enable = true,
lookahead = true,
keymaps = {
['ab'] = '@block.outer',
['ib'] = '@block.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
['af'] = '@function.outer',
['if'] = '@function.inner',
['ao'] = '@object.outer',
['io'] = '@object.inner',
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@block.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@block.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@block.outer',
},
},
clear_on_cursor_move = true,
},
refactor = {
highlight_current_scope = { enable = false },
smart_rename = {
enable = true,
keymaps = {
smart_rename = 'grr',
},
},
highlight_definitions = {
enable = true,
clear_on_cursor_move = true,
},
},
}

M.config = function(_, opts)
require('user.menu').add_actions('TreeSitter', actions())
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()
---@diagnostic disable-next-line: inject-field
parser_config.gotmpl = {
install_info = {
url = 'https://github.com/ngalaiko/tree-sitter-go-template',
files = { 'src/parser.c' },
},
filetype = 'gotmpl',
used_by = { 'gohtmltmpl', 'gotexttmpl', 'gotmpl' },
}

---@diagnostic disable-next-line: missing-fields
require('nvim-treesitter.configs').setup(opts)

vim.opt.foldmethod = 'expr'
vim.opt.foldexpr = 'nvim_treesitter#foldexpr()'
local function get_custom_foldtxt_suffix(foldstart)
Expand Down

0 comments on commit c620ddb

Please sign in to comment.