summaryrefslogtreecommitdiffstatshomepage
path: root/nvim
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-10-14 16:00:54 -0500
committerToby Vincent <tobyv13@gmail.com>2022-10-14 16:00:54 -0500
commit6acbce39243f6ef9fd7dba56aa732280fb63c350 (patch)
treed582b64b972c923f8f115936db70834b1dfb8608 /nvim
parent4420269a8c8d9d6baa6bc3a9ba355935f859b6d0 (diff)
feat(nvim): manually handle treesitter smart_rename keymap
Diffstat (limited to 'nvim')
-rw-r--r--nvim/.config/nvim/lua/tobyvin/plugins/treesitter.lua38
1 files changed, 36 insertions, 2 deletions
diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/treesitter.lua b/nvim/.config/nvim/lua/tobyvin/plugins/treesitter.lua
index 54f1ce8..c67fb3e 100644
--- a/nvim/.config/nvim/lua/tobyvin/plugins/treesitter.lua
+++ b/nvim/.config/nvim/lua/tobyvin/plugins/treesitter.lua
@@ -1,5 +1,7 @@
local M = {}
+M.attached_keymaps = {}
+
M.setup = function()
local status_ok, treesitter = pcall(require, "nvim-treesitter.configs")
if not status_ok then
@@ -7,8 +9,37 @@ M.setup = function()
return
end
+ local queries = require("nvim-treesitter.query")
+
+ treesitter.define_modules({
+ tobyvin_keymaps = {
+ attach = function(bufnr, _)
+ local refactor_module = require("nvim-treesitter-refactor.smart_rename")
+ local smart_rename = function()
+ vim.notify("ts renameing")
+ refactor_module.smart_rename(bufnr)
+ end
+
+ vim.keymap.set("n", "<leader>lr", smart_rename, { desc = "Rename", buffer = bufnr })
+ M.attached_keymaps[bufnr] = { "n", "<leader>lr", { buffer = bufnr } }
+ end,
+ detach = function(bufnr)
+ local attached_keymaps = vim.F.if_nil(M.attached_keymaps[bufnr], {})
+ for _, attached_keymap in pairs(attached_keymaps) do
+ vim.keymap.del(unpack(attached_keymap))
+ end
+ end,
+ is_supported = function(lang)
+ return queries.has_locals(lang)
+ end,
+ },
+ })
+
treesitter.setup({
ensure_installed = "all",
+ tobyvin_keymaps = {
+ enable = true,
+ },
indent = {
enable = true,
},
@@ -23,12 +54,15 @@ M.setup = function()
incremental_selection = {
enable = true,
keymaps = {
- init_selection = "<CR>",
- scope_incremental = "<CR>",
node_incremental = "<TAB>",
node_decremental = "<S-TAB>",
},
},
+ refactor = {
+ smart_rename = {
+ enable = true,
+ },
+ },
playground = {
enable = true,
},