diff --git a/README.md b/README.md index 72f67a8..47c3d21 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ rt.setup({ -- Commands: -- RustEnableInlayHints -- RustDisableInlayHints + -- RustToggleInlayHints -- RustSetInlayHints -- RustUnsetInlayHints @@ -85,6 +86,8 @@ rt.setup({ require('rust-tools').inlay_hints.enable() -- Disable inlay hints auto update and unset them for all buffers require('rust-tools').inlay_hints.disable() + -- Toggle between enabled and disabled inlay hints states for all buffer + require('rust-tools').inlay_hints.toggle() ``` diff --git a/lua/rust-tools/init.lua b/lua/rust-tools/init.lua index ca07557..cbfe05e 100644 --- a/lua/rust-tools/init.lua +++ b/lua/rust-tools/init.lua @@ -11,6 +11,7 @@ local M = { inlay_hints = { enable = nil, disable = nil, + toggle = nil, set = nil, unset = nil, cache = nil, @@ -82,6 +83,9 @@ function M.setup(opts) render = function() inlay.render(hints) end, + toggle = function() + inlay.toggle(hints) + end, } local join_lines = require("rust-tools.join_lines") diff --git a/lua/rust-tools/inlay_hints.lua b/lua/rust-tools/inlay_hints.lua index 0df31a1..bf73565 100644 --- a/lua/rust-tools/inlay_hints.lua +++ b/lua/rust-tools/inlay_hints.lua @@ -16,7 +16,7 @@ end -- Disable hints and clear all cached buffers function M.disable(self) - self.disable = false + self.enabled = false M.disable_cache_autocmd() for k, _ in pairs(self.cache) do @@ -39,9 +39,13 @@ function M.enable(self) set_all(self) end --- Set inlay hints only for the current buffer -function M.set(self) - M.cache_render(self, 0) +-- Toggles inlay hints state globally. Uses disable and enable internally +function M.toggle(self) + if self.enabled then + M.disable(self) + else + M.enable(self) + end end -- Clear hints only for the current buffer diff --git a/lua/rust-tools/lsp.lua b/lua/rust-tools/lsp.lua index 3288eeb..a2f2cdd 100644 --- a/lua/rust-tools/lsp.lua +++ b/lua/rust-tools/lsp.lua @@ -52,6 +52,9 @@ local function setup_commands() RustDisableInlayHints = { rt.inlay_hints.disable, }, + RustToggleInlayHints = { + rt.inlay_hints.toggle, + }, RustLastDebug = { rt.cached_commands.execute_last_debuggable, },