Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

feat(inlay-hints): add inlay hints toggle function #346

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ rt.setup({
-- Commands:
-- RustEnableInlayHints
-- RustDisableInlayHints
-- RustToggleInlayHints
-- RustSetInlayHints
-- RustUnsetInlayHints

Expand All @@ -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()
```
</details>

Expand Down
4 changes: 4 additions & 0 deletions lua/rust-tools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local M = {
inlay_hints = {
enable = nil,
disable = nil,
toggle = nil,
set = nil,
unset = nil,
cache = nil,
Expand Down Expand Up @@ -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")
Expand Down
12 changes: 8 additions & 4 deletions lua/rust-tools/inlay_hints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lua/rust-tools/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down