Skip to content

Commit 2ba50c9

Browse files
TheFedaikinMunifTanjim
authored andcommitted
feat(inlay_hints): add toggle function
PR: simrat39#346
1 parent 95a62a0 commit 2ba50c9

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ rt.setup({
7373
-- Commands:
7474
-- RustEnableInlayHints
7575
-- RustDisableInlayHints
76+
-- RustToggleInlayHints
7677
-- RustSetInlayHints
7778
-- RustUnsetInlayHints
7879

@@ -85,6 +86,8 @@ rt.setup({
8586
require('rust-tools').inlay_hints.enable()
8687
-- Disable inlay hints auto update and unset them for all buffers
8788
require('rust-tools').inlay_hints.disable()
89+
-- Toggle between enabled and disabled inlay hints states for all buffer
90+
require('rust-tools').inlay_hints.toggle()
8891
```
8992
</details>
9093

lua/rust-tools/init.lua

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local M = {
1111
inlay_hints = {
1212
enable = nil,
1313
disable = nil,
14+
toggle = nil,
1415
set = nil,
1516
unset = nil,
1617
cache = nil,
@@ -85,6 +86,9 @@ function M.setup(opts)
8586
render = function()
8687
inlay.render(hints)
8788
end,
89+
toggle = function()
90+
inlay.toggle(hints)
91+
end,
8892
}
8993

9094
local join_lines = require("rust-tools.join_lines")

lua/rust-tools/inlay_hints.lua

+10-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ end
1616

1717
-- Disable hints and clear all cached buffers
1818
function M.disable(self)
19-
self.disable = false
19+
self.enabled = false
2020
M.disable_cache_autocmd()
2121

2222
for k, _ in pairs(self.cache) do
@@ -44,6 +44,15 @@ function M.set(self)
4444
M.cache_render(self, 0)
4545
end
4646

47+
-- Toggles inlay hints state globally. Uses disable and enable internally
48+
function M.toggle(self)
49+
if self.enabled then
50+
M.disable(self)
51+
else
52+
M.enable(self)
53+
end
54+
end
55+
4756
-- Clear hints only for the current buffer
4857
function M.unset()
4958
clear_ns(0)

lua/rust-tools/lsp.lua

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ local function setup_commands()
5555
RustDisableInlayHints = {
5656
rt.inlay_hints.disable,
5757
},
58+
RustToggleInlayHints = {
59+
rt.inlay_hints.toggle,
60+
},
5861
RustLastDebug = {
5962
rt.cached_commands.execute_last_debuggable,
6063
},

0 commit comments

Comments
 (0)