From 5e1a86d3b257db37c8b443deea6ca1fefcb0b1aa Mon Sep 17 00:00:00 2001 From: Kevin Traver Date: Sat, 14 Oct 2023 06:40:25 -0600 Subject: [PATCH] feat(toggle): add keymap to toggle treesitter context (#1711) * feat: add keymap to toggle treesitter context * fix: get correct enabled state --------- Co-authored-by: Folke Lemaitre --- lua/lazyvim/plugins/formatting.lua | 2 +- lua/lazyvim/plugins/treesitter.lua | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/formatting.lua b/lua/lazyvim/plugins/formatting.lua index 5042f076..c98a7252 100644 --- a/lua/lazyvim/plugins/formatting.lua +++ b/lua/lazyvim/plugins/formatting.lua @@ -6,7 +6,7 @@ local M = {} local format_opts = {} ---@param opts ConformOpts -function M.setup(plugin, opts) +function M.setup(_, opts) local util = require("conform.util") opts.formatters = opts.formatters or {} for name, formatter in pairs(opts.formatters) do diff --git a/lua/lazyvim/plugins/treesitter.lua b/lua/lazyvim/plugins/treesitter.lua index c833a707..1b4debcf 100644 --- a/lua/lazyvim/plugins/treesitter.lua +++ b/lua/lazyvim/plugins/treesitter.lua @@ -110,6 +110,22 @@ return { event = "LazyFile", enabled = true, opts = { mode = "cursor" }, + keys = { + { + "ut", + function() + local Util = require("lazyvim.util") + local tsc = require("treesitter-context") + tsc.toggle() + if Util.inject.get_upvalue(tsc.toggle, "enabled") then + Util.info("Enabled Treesitter Context", { title = "Option" }) + else + Util.warn("Disabled Treesitter Context", { title = "Option" }) + end + end, + desc = "Toggle Treesitter Context", + }, + }, }, -- Automatically add closing tags for HTML and JSX