refactor(nvim): extract treesitter config

This commit is contained in:
Rob Watson 2023-09-17 22:44:10 +02:00
parent 7158f541b9
commit 8df0c3b325
3 changed files with 106 additions and 105 deletions

111
nvimrc
View File

@ -339,111 +339,12 @@ packadd! vim-wordmotion " https://github.com/chaoren/vim-wordmotion.git
" enable inline vim highlighting:
let g:vimsyn_embed= 'lPr'
" Treesitter
packadd! nvim-treesitter " https://github.com/nvim-treesitter/nvim-treesitter.git
packadd! nvim-treesitter-textobjects " https://github.com/nvim-treesitter/nvim-treesitter-textobjects.git
packadd! nvim-treesitter-refactor " https://github.com/nvim-treesitter/nvim-treesitter-refactor.git
packadd! nvim-treesitter-context " https://github.com/nvim-treesitter/nvim-treesitter-context.git
packadd! playground " https://github.com/nvim-treesitter/playground.git
lua <<EOF
require 'nvim-treesitter.configs'.setup {
ensure_installed = "all",
highlight = {
enable = true,
disable = {"vim", "swift"},
additional_vim_regex_highlighting = true,
},
incremental_selection = {
enable = true,
},
indent = {
-- enabling breaks autoindent:
enable = false,
},
textobjects = {
select = {
enable = true,
lookahead = true,
keymaps = {
["ak"] = "@keyed_element.outer",
["av"] = "@keyed_element.inner",
["ia"] = "@parameter.inner",
["aa"] = "@parameter.outer",
["ac"] = "@comment.outer",
["at"] = "@statement.outer",
["ar"] = "@return",
["af"] = "@function.outer",
["if"] = "@function.inner",
},
},
move = {
enable = true,
set_jumps = true,
goto_next_start = {
["]a"] = "@parameter.inner",
["]f"] = "@function.outer",
["]F"] = "@function.inner",
},
goto_previous_start = {
["[a"] = "@parameter.inner",
["[f"] = "@function.outer",
["[F"] = "@function.inner",
},
},
lsp_interop = {
enable = true,
peek_definition_code = {
["<leader>d"] = "@class.outer",
["<leader>d"] = "@function.outer",
},
},
},
refactor = {
highlight_definitions = { enable = true },
highlight_current_scope = { enable = false },
smart_rename = {
enable = true,
keymaps = {
smart_rename = "grr",
},
},
navigation = {
enable = true,
keymaps = {
-- goto_definition_lsp_fallback = "gd",
goto_next_usage = "]r",
goto_previous_usage = "[r",
},
},
},
playground = {
enable = true,
disable = {},
updatetime = 25,
persist_queries = false,
keybindings = {
toggle_query_editor = 'o',
toggle_hl_groups = 'i',
toggle_injected_languages = 't',
toggle_anonymous_nodes = 'a',
toggle_language_display = 'I',
focus_language = 'f',
unfocus_language = 'F',
update = 'R',
goto_node = '<cr>',
show_help = '?',
},
}
}
EOF
lua <<EOF
require'treesitter-context'.setup{
enable = true,
}
EOF
" Treesitter: see lua/treesitter_config.lua
" packadd! nvim-treesitter " https://github.com/nvim-treesitter/nvim-treesitter.git
" packadd! nvim-treesitter-textobjects " https://github.com/nvim-treesitter/nvim-treesitter-textobjects.git
" packadd! nvim-treesitter-refactor " https://github.com/nvim-treesitter/nvim-treesitter-refactor.git
" packadd! nvim-treesitter-context " https://github.com/nvim-treesitter/nvim-treesitter-context.git
" packadd! playground " https://github.com/nvim-treesitter/playground.git
" copilot:

View File

@ -2,3 +2,4 @@ require "helpers"
require "commands"
require "test_runner"
require "formatter_config"
require "treesitter_config"

View File

@ -0,0 +1,99 @@
vim.api.nvim_command("packadd nvim-treesitter")
vim.api.nvim_command("packadd nvim-treesitter-textobjects")
vim.api.nvim_command("packadd nvim-treesitter-refactor")
vim.api.nvim_command("packadd nvim-treesitter-context")
vim.api.nvim_command("packadd playground")
require 'nvim-treesitter.configs'.setup {
ensure_installed = "all",
highlight = {
enable = true,
disable = {"vim", "swift"},
additional_vim_regex_highlighting = true,
},
incremental_selection = {
enable = true,
},
indent = {
-- enabling breaks autoindent:
enable = false,
},
textobjects = {
select = {
enable = true,
lookahead = true,
keymaps = {
["ak"] = "@keyed_element.outer",
["av"] = "@keyed_element.inner",
["ia"] = "@parameter.inner",
["aa"] = "@parameter.outer",
["ac"] = "@comment.outer",
["at"] = "@statement.outer",
["ar"] = "@return",
["af"] = "@function.outer",
["if"] = "@function.inner",
},
},
move = {
enable = true,
set_jumps = true,
goto_next_start = {
["]a"] = "@parameter.inner",
["]f"] = "@function.outer",
["]F"] = "@function.inner",
},
goto_previous_start = {
["[a"] = "@parameter.inner",
["[f"] = "@function.outer",
["[F"] = "@function.inner",
},
},
lsp_interop = {
enable = true,
peek_definition_code = {
["<leader>d"] = "@class.outer",
-- ["<leader>d"] = "@function.outer",
},
},
},
refactor = {
highlight_definitions = { enable = true },
highlight_current_scope = { enable = false },
smart_rename = {
enable = true,
keymaps = {
smart_rename = "grr",
},
},
navigation = {
enable = true,
keymaps = {
-- goto_definition_lsp_fallback = "gd",
goto_next_usage = "]r",
goto_previous_usage = "[r",
},
},
},
playground = {
enable = true,
disable = {},
updatetime = 25,
persist_queries = false,
keybindings = {
toggle_query_editor = 'o',
toggle_hl_groups = 'i',
toggle_injected_languages = 't',
toggle_anonymous_nodes = 'a',
toggle_language_display = 'I',
focus_language = 'f',
unfocus_language = 'F',
update = 'R',
goto_node = '<cr>',
show_help = '?',
},
}
}
require'treesitter-context'.setup{
enable = true,
}