From 68acd1fcacd32c381811e7475282b0a27769b4c2 Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Sat, 11 Jan 2025 08:38:17 +0100 Subject: [PATCH] fix(nvim): treesitter textobject bindings for Go --- vim/lua/treesitter_config.lua | 8 ++++---- vim/queries/go/textobjects.scm | 14 ++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/vim/lua/treesitter_config.lua b/vim/lua/treesitter_config.lua index 1577305..58e3600 100644 --- a/vim/lua/treesitter_config.lua +++ b/vim/lua/treesitter_config.lua @@ -40,15 +40,15 @@ require("nvim-treesitter.configs").setup({ enable = true, lookahead = true, keymaps = { - ["ak"] = "@keyed_element.outer", - ["iv"] = "@keyed_element.inner", - ["av"] = "@keyed_element.inner", + ["ak"] = "@kv_element.all", + ["ik"] = "@kv_element.key", + ["iv"] = "@kv_element.value", + ["av"] = "@kv_element.all", ["at"] = "@composite_literal", ["ia"] = "@parameter.inner", ["aa"] = "@parameter.outer", ["ac"] = "@comment.outer", ["as"] = "@statement.outer", - ["ar"] = "@return", ["af"] = "@function.outer", ["if"] = "@function.inner", }, diff --git a/vim/queries/go/textobjects.scm b/vim/queries/go/textobjects.scm index ac2c5b0..cbcc883 100644 --- a/vim/queries/go/textobjects.scm +++ b/vim/queries/go/textobjects.scm @@ -4,8 +4,14 @@ ;; @keyed_element.outer => key and value ;; @keyed_element.inner => value -(keyed_element (_) . (_) @keyed_element.inner) @keyed_element.outer -(field_declaration type: (_) @keyed_element.inner) @keyed_element.outer -(parameter_declaration type: (_) @keyed_element.inner) @keyed_element.outer +(keyed_element . ((_) @kv_element.key)) +(keyed_element ((_) @kv_element.value) .) +(keyed_element) @kv_element.all -(composite_literal (_)) @composite_literal +(parameter_declaration) @kv_element.all +(parameter_declaration . ((_) @kv_element.key)) +(parameter_declaration ((_) @kv_element.value) .) + +(field_declaration) @kv_element.all +(field_declaration . ((_) @kv_element.key)) +(field_declaration ((_) @kv_element.value) .)