~p00f/public-inbox

clangd_extensions.nvim: feat: return state after v2 APPLIED

~lnk3: 1
 feat: return state after

 2 files changed, 32 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~p00f/public-inbox/patches/51509/mbox | git am -3
Learn more about email & git

[PATCH clangd_extensions.nvim v2] feat: return state after Export this patch

From: lnc3l0t <lnk3@protonmail.com>

Return the state after toggle_inlay_hints has been called, useful for attaching callbacks to the toggle behaviour.
For example enable/disable autocmds when toggling or untoggling.
---
 README.md                             | 31 +++++++++++++++++++++++++++
 lua/clangd_extensions/inlay_hints.lua |  1 +
 2 files changed, 32 insertions(+)

diff --git a/README.md b/README.md
index 3751410..8fc2faf 100644
--- a/README.md
+++ b/README.md
@@ -104,6 +104,37 @@ Add this to your nvim-lspconfig / `vim.lsp.start()`'s `on_attach`:
require("clangd_extensions.inlay_hints").setup_autocmd()
require("clangd_extensions.inlay_hints").set_inlay_hints()
```

You can also enable, disable or toggle the hints with `ClangdSetInlayHints`, `ClangdDisableInlayHints` and `ClangdToggleInlayHints`.
Toggling returns the current state of the hints, this is useful if you want to hook a callback when toggling inlay hints:
```lua
if require("clangd_extensions.inlay_hints").toggle_inlay_hints() then
    -- Inlay hints are enabled
else
    -- Inlay hints are disabled
end
```
For example if you have autocommands related to Clangd inlay hints you might want to disable/enable them when toggling inlay hints:
```lua
on_attach = function(_, buf)
    local group = vim.api.nvim_create_augroup("clangd_no_inlay_hints_in_insert", { clear = true })

    vim.keymap.set("n", "<leader>lh", function()
        if require("clangd_extensions.inlay_hints").toggle_inlay_hints() then
            vim.api.nvim_create_autocmd("InsertEnter", { group = group, buffer = buf,
                callback = require("clangd_extensions.inlay_hints").disable_inlay_hints
            })
            vim.api.nvim_create_autocmd({ "TextChanged", "InsertLeave" }, { group = group, buffer = buf,
                callback = require("clangd_extensions.inlay_hints").set_inlay_hints
            })
        else
            vim.api.nvim_clear_autocmds({ group = group, buffer = buf })
        end
    end, { buffer = buf, desc = "[l]sp [h]ints toggle" })
end,
}
```

### [View AST](https://clangd.llvm.org/extensions#ast)
![image](https://user-images.githubusercontent.com/36493671/255611133-35f397d3-02f8-4d14-b70a-126be6c098fa.gif)
You can fold nodes using `zc` and friends - the AST window has `shiftwidth=2` and `foldmethod=indent`.
diff --git a/lua/clangd_extensions/inlay_hints.lua b/lua/clangd_extensions/inlay_hints.lua
index 2d03fe4..f8afd1a 100644
--- a/lua/clangd_extensions/inlay_hints.lua
+++ b/lua/clangd_extensions/inlay_hints.lua
@@ -272,6 +272,7 @@ function M.toggle_inlay_hints()
        M.set_inlay_hints()
    end
    enabled = not enabled
    return enabled
end

function M.disable_inlay_hints()
-- 
2.43.0