Treesitter update
This commit is contained in:
@@ -30,7 +30,7 @@ vim.api.nvim_create_autocmd('SwapExists', {
|
||||
desc = 'Always choose to delete the swap file, files are saved automatically',
|
||||
group = vim.api.nvim_create_augroup('NoSwaps', { clear = true }),
|
||||
callback = function(args)
|
||||
vim.cmd("let v:swapchoice = 'd'")
|
||||
vim.cmd "let v:swapchoice = 'd'"
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -116,4 +116,33 @@ vim.api.nvim_create_autocmd('BufWritePost', {
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = {
|
||||
'bash',
|
||||
'c',
|
||||
'diff',
|
||||
'html',
|
||||
'lua',
|
||||
'luadoc',
|
||||
'markdown',
|
||||
'markdown_inline',
|
||||
'query',
|
||||
'vim',
|
||||
'vimdoc',
|
||||
'php',
|
||||
'javascript',
|
||||
'typescript',
|
||||
'json',
|
||||
},
|
||||
callback = function()
|
||||
-- syntax highlighting, provided by Neovim
|
||||
vim.treesitter.start()
|
||||
-- folds, provided by Neovim
|
||||
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
|
||||
vim.wo.foldmethod = 'expr'
|
||||
-- indentation, provided by nvim-treesitter
|
||||
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||
end,
|
||||
})
|
||||
|
||||
require('helpers').edit_cf('a', '/lua/autocmd.lua')
|
||||
|
||||
@@ -30,13 +30,13 @@ vim.keymap.set('n', '<Leader>c', function()
|
||||
vim.treesitter.inspect_tree()
|
||||
end, { desc = 'Treesitter' })
|
||||
|
||||
vim.keymap.set('n', '<C-S-D>', function()
|
||||
local node = vim.treesitter.get_node {}
|
||||
local range = { vim.treesitter.get_node_range(node) }
|
||||
vim.api.nvim_win_set_cursor(0, { range[3] + 1, range[4] - 1 })
|
||||
vim.fn.setpos("'x", { 0, range[1] + 1, range[2] + 1, 0 })
|
||||
vim.cmd.normal 'v`x'
|
||||
end, { desc = 'Select surrounding treesitter node' })
|
||||
-- vim.keymap.set('n', '<C-S-D>', function()
|
||||
-- local node = vim.treesitter.get_node {}
|
||||
-- local range = { vim.treesitter.get_node_range(node) }
|
||||
-- vim.api.nvim_win_set_cursor(0, { range[3] + 1, range[4] - 1 })
|
||||
-- vim.fn.setpos("'x", { 0, range[1] + 1, range[2] + 1, 0 })
|
||||
-- vim.cmd.normal 'v`x'
|
||||
-- end, { desc = 'Select surrounding treesitter node' })
|
||||
|
||||
vim.keymap.set('v', '<C-S-D>', function()
|
||||
local start = vim.api.nvim_win_get_cursor(0)
|
||||
@@ -258,7 +258,6 @@ vim.keymap.set('n', '<Leader>]', '<CMD>cnext<CR>', { desc = 'Next item in quickf
|
||||
vim.keymap.set('n', '<Leader>[', '<CMD>cprevious<CR>', { desc = 'Previous item in quickfix list' })
|
||||
vim.keymap.set('n', 'gd', '<CMD>Telescope lsp_definitions<CR>', { desc = 'Go to definition' })
|
||||
|
||||
|
||||
local function open_test()
|
||||
require('neotest').summary.open()
|
||||
require('neotest').output_panel.open()
|
||||
|
||||
@@ -1,86 +1,153 @@
|
||||
-- Highlight, edit, and navigate code
|
||||
return {
|
||||
'nvim-treesitter/nvim-treesitter-textobjects',
|
||||
dependencies = {
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
},
|
||||
lazy = false,
|
||||
enabled = true,
|
||||
config = function()
|
||||
require('nvim-treesitter.configs').setup {
|
||||
incremental_selection = {
|
||||
enable = true,
|
||||
keymaps = {
|
||||
-- mappings for incremental selection (visual mappings)
|
||||
init_selection = 'gnn', -- maps in normal mode to init the node/scope selection
|
||||
node_incremental = 'grn', -- increment to the upper named parent
|
||||
scope_incremental = 'grc', -- increment to the upper scope (as defined in locals.scm)
|
||||
node_decremental = 'grm', -- decrement to the previous node
|
||||
},
|
||||
},
|
||||
-- 'nvim-treesitter/nvim-treesitter-textobjects',
|
||||
-- lazy = true,
|
||||
-- branch = 'main',
|
||||
-- dependencies = {
|
||||
-- 'nvim-treesitter/nvim-treesitter',
|
||||
-- },
|
||||
-- config = function()
|
||||
-- -- configuration
|
||||
-- require('nvim-treesitter-textobjects').setup {
|
||||
-- select = {
|
||||
-- lookahead = true,
|
||||
-- selection_modes = {
|
||||
-- ['@parameter.outer'] = 'v', -- charwise
|
||||
-- ['@function.outer'] = 'V', -- linewise
|
||||
-- ['@class.outer'] = 'V', -- blockwise
|
||||
-- },
|
||||
-- include_surrounding_whitespace = false,
|
||||
-- },
|
||||
-- move = {
|
||||
-- set_jumps = true,
|
||||
-- },
|
||||
-- }
|
||||
|
||||
textobjects = {
|
||||
-- syntax-aware textobjects
|
||||
enable = true,
|
||||
keymaps = {
|
||||
['iL'] = {
|
||||
-- you can define your own textobjects directly here
|
||||
go = '(function_definition) @function',
|
||||
},
|
||||
-- or you use the queries from supported languages with textobjects.scm
|
||||
['af'] = '@function.outer',
|
||||
['if'] = '@function.inner',
|
||||
['aC'] = '@class.outer',
|
||||
['iC'] = '@class.inner',
|
||||
['ay'] = '@conditional.outer',
|
||||
['iy'] = '@conditional.inner',
|
||||
['aj'] = '@loop.outer',
|
||||
['ij'] = '@loop.inner',
|
||||
['is'] = '@statement.inner',
|
||||
['as'] = '@statement.outer',
|
||||
['ac'] = '@comment.outer',
|
||||
['ic'] = '@comment.inner',
|
||||
['ap'] = '@comment.parameter',
|
||||
['ip'] = '@comment.parameter',
|
||||
},
|
||||
move = {
|
||||
enable = true,
|
||||
set_jumps = true, -- whether to set jumps in the jumplist
|
||||
goto_next_start = {
|
||||
[']m'] = '@function.outer',
|
||||
[']]'] = '@class.outer',
|
||||
},
|
||||
goto_next_end = {
|
||||
[']M'] = '@function.outer',
|
||||
[']['] = '@class.outer',
|
||||
},
|
||||
goto_previous_start = {
|
||||
['[m'] = '@function.outer',
|
||||
['[['] = '@class.outer',
|
||||
},
|
||||
goto_previous_end = {
|
||||
['[M'] = '@function.outer',
|
||||
['[]'] = '@class.outer',
|
||||
},
|
||||
},
|
||||
select = {
|
||||
enable = true,
|
||||
keymaps = {
|
||||
-- You can use the capture groups defined in textobjects.scm
|
||||
['af'] = '@function.outer',
|
||||
['if'] = '@function.inner',
|
||||
['ac'] = '@class.outer',
|
||||
['ic'] = '@class.inner',
|
||||
-- Or you can define your own textobjects like this
|
||||
['iF'] = {
|
||||
python = '(function_definition) @function',
|
||||
cpp = '(function_definition) @function',
|
||||
c = '(function_definition) @function',
|
||||
java = '(method_declaration) @function',
|
||||
go = '(method_declaration) @function',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
end,
|
||||
-- for keys, query in
|
||||
-- {
|
||||
-- -- or you use the queries from supported languages with textobjects.scm
|
||||
-- ['af'] = '@function.outer',
|
||||
-- ['if'] = '@function.inner',
|
||||
-- ['aC'] = '@class.outer',
|
||||
-- ['iC'] = '@class.inner',
|
||||
-- ['ay'] = '@conditional.outer',
|
||||
-- ['iy'] = '@conditional.inner',
|
||||
-- ['aj'] = '@loop.outer',
|
||||
-- ['ij'] = '@loop.inner',
|
||||
-- ['is'] = '@statement.inner',
|
||||
-- ['as'] = '@statement.outer',
|
||||
-- ['ac'] = '@comment.outer',
|
||||
-- ['ic'] = '@comment.inner',
|
||||
-- ['ap'] = '@comment.parameter',
|
||||
-- ['ip'] = '@comment.parameter',
|
||||
-- ['an'] = '@local.scope',
|
||||
-- }
|
||||
-- do
|
||||
-- vim.keymap.set({ 'n', 'x', 'o' }, keys, function()
|
||||
-- require('nvim-treesitter-textobjects.select').select_textobject(query, 'textobjects')
|
||||
-- end)
|
||||
-- end
|
||||
|
||||
-- for keys, query in
|
||||
-- {
|
||||
-- -- or you use the queries from supported languages with textobjects.scm
|
||||
-- [']'] = '@function.outer',
|
||||
-- ['o'] = { '@loop.inner', '@loop.outer' },
|
||||
-- ['n'] = '@local.scope',
|
||||
-- ['y'] = '@conditional.outer',
|
||||
-- ['e'] = '@statement.outer',
|
||||
-- ['/'] = '@comment.outer',
|
||||
-- }
|
||||
-- do
|
||||
-- vim.keymap.set({ 'n', 'x', 'o' }, ']' .. keys, function()
|
||||
-- require('nvim-treesitter-textobjects.move').goto_next_start(query, 'textobjects')
|
||||
-- end)
|
||||
-- vim.keymap.set({ 'n', 'x', 'o' }, '[' .. keys, function()
|
||||
-- require('nvim-treesitter-textobjects.move').goto_previous_start(query, 'textobjects')
|
||||
-- end)
|
||||
-- end
|
||||
-- -- require('nvim-treesitter.configs').setup {
|
||||
-- -- incremental_selection = {
|
||||
-- -- enable = true,
|
||||
-- -- keymaps = {
|
||||
-- -- -- mappings for incremental selection (visual mappings)
|
||||
-- -- init_selection = '<C-S-D>', -- maps in normal mode to init the node/scope selection
|
||||
-- -- node_incremental = '<C-S-D>', -- increment to the upper named parent
|
||||
-- -- scope_incremental = '<C-S-U>', -- increment to the upper scope (as defined in locals.scm)
|
||||
-- -- node_decremental = '<C-S-S>', -- decrement to the previous node
|
||||
-- -- },
|
||||
-- -- },
|
||||
|
||||
-- -- textobjects = {
|
||||
-- -- -- syntax-aware textobjects
|
||||
-- -- enable = true,
|
||||
-- -- keymaps = {
|
||||
-- -- ['iL'] = {
|
||||
-- -- -- you can define your own textobjects directly here
|
||||
-- -- go = '(function_definition) @function',
|
||||
-- -- },
|
||||
-- -- -- or you use the queries from supported languages with textobjects.scm
|
||||
-- -- ['af'] = '@function.outer',
|
||||
-- -- ['if'] = '@function.inner',
|
||||
-- -- ['aC'] = '@class.outer',
|
||||
-- -- ['iC'] = '@class.inner',
|
||||
-- -- ['ay'] = '@conditional.outer',
|
||||
-- -- ['iy'] = '@conditional.inner',
|
||||
-- -- ['aj'] = '@loop.outer',
|
||||
-- -- ['ij'] = '@loop.inner',
|
||||
-- -- ['is'] = '@statement.inner',
|
||||
-- -- ['as'] = '@statement.outer',
|
||||
-- -- ['ac'] = '@comment.outer',
|
||||
-- -- ['ic'] = '@comment.inner',
|
||||
-- -- ['ap'] = '@comment.parameter',
|
||||
-- -- ['ip'] = '@comment.parameter',
|
||||
-- -- },
|
||||
-- -- move = {
|
||||
-- -- enable = true,
|
||||
-- -- set_jumps = true, -- whether to set jumps in the jumplist
|
||||
-- -- goto_next_start = {
|
||||
-- -- [']m'] = '@function.outer',
|
||||
-- -- [']]'] = '@class.outer',
|
||||
-- -- },
|
||||
-- -- goto_next_end = {
|
||||
-- -- [']M'] = '@function.outer',
|
||||
-- -- [']['] = '@class.outer',
|
||||
-- -- },
|
||||
-- -- goto_previous_start = {
|
||||
-- -- ['[m'] = '@function.outer',
|
||||
-- -- ['[['] = '@class.outer',
|
||||
-- -- },
|
||||
-- -- goto_previous_end = {
|
||||
-- -- ['[M'] = '@function.outer',
|
||||
-- -- ['[]'] = '@class.outer',
|
||||
-- -- },
|
||||
-- -- },
|
||||
-- -- select = {
|
||||
-- -- enable = true,
|
||||
-- -- keymaps = {
|
||||
-- -- -- You can use the capture groups defined in textobjects.scm
|
||||
-- -- ['af'] = '@function.outer',
|
||||
-- -- ['if'] = '@function.inner',
|
||||
-- -- ['ac'] = '@class.outer',
|
||||
-- -- ['ic'] = '@class.inner',
|
||||
-- -- -- Or you can define your own textobjects like this
|
||||
-- -- ['iF'] = {
|
||||
-- -- python = '(function_definition) @function',
|
||||
-- -- cpp = '(function_definition) @function',
|
||||
-- -- c = '(function_definition) @function',
|
||||
-- -- java = '(method_declaration) @function',
|
||||
-- -- go = '(method_declaration) @function',
|
||||
-- -- },
|
||||
-- -- },
|
||||
-- -- },
|
||||
-- -- },
|
||||
-- -- }
|
||||
-- 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
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
return {
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
build = ':TSUpdate',
|
||||
main = 'nvim-treesitter.configs', -- Sets main module to use for opts
|
||||
branch = 'main',
|
||||
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
|
||||
opts = {
|
||||
ensure_installed = {
|
||||
config = function()
|
||||
require('nvim-treesitter').setup {}
|
||||
require('nvim-treesitter').install {
|
||||
'bash',
|
||||
'c',
|
||||
'diff',
|
||||
@@ -17,18 +18,13 @@ return {
|
||||
'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' } },
|
||||
},
|
||||
'php',
|
||||
'javascript',
|
||||
'typescript',
|
||||
'json',
|
||||
}
|
||||
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:
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user