From ab0135093bc18ccf82325bc8ee14c25230a71786 Mon Sep 17 00:00:00 2001 From: Stefan Boca <45266795+stefanboca@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:58:34 -0700 Subject: [PATCH] feat(treesitter-context): which-key toggle (#4059) ## Description Add a which-key toggle for treesitter-context ## Screenshots ![image](https://github.com/user-attachments/assets/28c02607-a7e8-409c-a190-4fd2db85e8bb) ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines. --- .../plugins/extras/ui/treesitter-context.lua | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lua/lazyvim/plugins/extras/ui/treesitter-context.lua b/lua/lazyvim/plugins/extras/ui/treesitter-context.lua index a1f8d5f3..019977ed 100644 --- a/lua/lazyvim/plugins/extras/ui/treesitter-context.lua +++ b/lua/lazyvim/plugins/extras/ui/treesitter-context.lua @@ -1,21 +1,22 @@ -- Show context of the current function return { "nvim-treesitter/nvim-treesitter-context", - event = "LazyFile", - opts = { mode = "cursor", max_lines = 3 }, - keys = { - { - "ut", - function() - local tsc = require("treesitter-context") - tsc.toggle() - if LazyVim.inject.get_upvalue(tsc.toggle, "enabled") then - LazyVim.info("Enabled Treesitter Context", { title = "Option" }) + event = "VeryLazy", + opts = function() + local tsc = require("treesitter-context") + + LazyVim.toggle.map("ut", { + name = "Treesitter Context", + get = tsc.enabled, + set = function(state) + if state then + tsc.enable() else - LazyVim.warn("Disabled Treesitter Context", { title = "Option" }) + tsc.disable() end end, - desc = "Toggle Treesitter Context", - }, - }, + }) + + return { mode = "cursor", max_lines = 3 } + end, }