Feature request: Inline virtual text?
vishalbalaji opened this issue · comments
vishalbalaji commented
With support for inlay hints from neovim 0.10+, could we add support for inline virtualtext hints, reminiscent of VSCode? Other libraries, such as tailwind-tools.nvim have already implemented this.
(Screenshot from tailwind-tools.nvim repo)
This is relatively simple to add, a patch for this would be as follows:
diff --git a/lua/colorizer/buffer.lua b/lua/colorizer/buffer.lua
index 04e953e..9defecd 100644
--- a/lua/colorizer/buffer.lua
+++ b/lua/colorizer/buffer.lua
@@ -109,11 +109,23 @@ function buffer.add_highlight(buf, ns, line_start, line_end, data, options)
for linenr, hls in pairs(data) do
for _, hl in ipairs(hls) do
local hlname = create_highlight(hl.rgb_hex, mode)
- buf_set_virtual_text(buf, ns, linenr, hl.range[2], {
- end_col = hl.range[2],
+
+ local start_col = hl.range[2]
+ local opts = {
virt_text = { { options.virtualtext or "■", hlname } },
hl_mode = "combine",
- })
+ priority = 0,
+ }
+
+ if options.virtualtext_inline then
+ start_col = hl.range[1]
+ opts.virt_text_pos = "inline"
+ opts.virt_text = { { (options.virtualtext or "■") .. " ", hlname } }
+ end
+
+ opts.end_col = start_col
+
+ buf_set_virtual_text(buf, ns, linenr, start_col, opts)
end
end
end
This patch assumes a new user option called virtualtext_inline
, which will control whether the to use the regular virtualtext or the inline one.
I would be happy to open a PR if the maintainers are open to it.
Bruno Krugel commented
Please do!