lsp-inlayhints.nvim
lsp-inlayhints.nvim copied to clipboard
Support inline virtual text
Inline virtual text will soon be merged into master: https://github.com/neovim/neovim/pull/23426
This Plugin is of course the perfect candidate for implementing this feature.
Testers needed for the anticonceal branch.
TODO yield every 5ms on the main 'render' loop. Ref https://github.com/neovim/neovim/commit/edf05b005f34f59dd40468c36cc139e217345a71 (l104-120)
@lvimuser I would like to test it. Do you mind sharing instructions on how to apply the patch on neovim master branch?
In neovim repo directory I do:
$ wget https://patch-diff.githubusercontent.com/raw/neovim/neovim/pull/23426.patch && git apply 23426.patch --allow-overlap --reject --whitespace=fix
$ make CMAKE_BUILD_TYPE=RelWithDebInfo
Fails with error:
mkdir -p build
touch build/.ran-deps-cmake
ninja -C .deps
ninja: Entering directory `.deps'
[4/10] Performing download step (download, verify and extract) for 'libuv'
FAILED: build/src/libuv-stamp/libuv-download /Users/lukasz.kurpiewski/Projects/neovim/.deps/build/src/libuv-stamp/libuv-download
cd /Users/lukasz.kurpiewski/Projects/neovim/.deps/build/src && /opt/homebrew/Cellar/cmake/3.26.3/bin/cmake -P /Users/lukasz.kurpiewski/Projects/neovim/.deps/build/src/libuv-stamp/download-libuv.cmake && /opt/homebrew/Cellar/cmake/3.26.3/bin/cmake -P /Users/lukasz.kurpiewski/Projects/neovim/.deps/build/src/libuv-stamp/verify-libuv.cmake && /opt/homebrew/Cellar/cmake/3.26.3/bin/cmake -P /Users/lukasz.kurpiewski/Projects/neovim/.deps/build/src/libuv-stamp/extract-libuv.cmake && /opt/homebrew/Cellar/cmake/3.26.3/bin/cmake -E touch /Users/lukasz.kurpiewski/Projects/neovim/.deps/build/src/libuv-stamp/libuv-download
-- Downloading...
dst='/Users/lukasz.kurpiewski/Projects/neovim/.deps/build/downloads/libuv/62c2374a8c005ce9e42088965f8f8af2532c177b.tar.gz'
timeout='none'
inactivity timeout='none'
-- Using src='https://github.com/libuv/libuv/archive/62c2374a8c005ce9e42088965f8f8af2532c177b.tar.gz'
-- verifying file...
file='/Users/lukasz.kurpiewski/Projects/neovim/.deps/build/downloads/libuv/62c2374a8c005ce9e42088965f8f8af2532c177b.tar.gz'
-- SHA256 hash of
/Users/lukasz.kurpiewski/Projects/neovim/.deps/build/downloads/libuv/62c2374a8c005ce9e42088965f8f8af2532c177b.tar.gz
does not match expected value
expected: 'cd97aff8e7073fb128aef7a45e9183264ccaf07945a6cb430053070bd03ff200'
actual: 'c7e89137da65a1cb550ba96b892dfeeabea982bf33b9237bcf9bbcd90f2e70a1'
-- Hash mismatch, removing...
(...)
If I just apply the patch without --allow-overlap --reject --whitespace=fix I get:
2023-05-11 15:10:52 (1.35 MB/s) - ‘23426.patch’ saved [137917]
error: patch failed: runtime/doc/news.txt:52
error: runtime/doc/news.txt: patch does not apply
@lvimuser I would like to test it. Do you mind sharing instructions on how to apply the patch on neovim
masterbranch?In neovim repo directory I do:
$ wget https://patch-diff.githubusercontent.com/raw/neovim/neovim/pull/23426.patch && git apply 23426.patch --allow-overlap --reject --whitespace=fix
git am 23426.patch worked without any issues.
Hey! Thanks for your work on this plugin. In majority of cases that I've tested it works really well. I've been testing this for a while and I found two things:
- One thing is that inlay hints does not render on the first line of the buffer:
https://github.com/lvimuser/lsp-inlayhints.nvim/assets/35625949/74f1becb-5d79-4fc1-b77c-f3b56d3db92c
- Don't know if it's possible but when we have set
set cursorlineand on the line that our cursor is at the moment there is a hint withpaddingLeftorpaddingRight, this padding has different background than thecursorlinebackground. I think it would be nice to have this background the same color as the cursorline:
1. One thing is that inlay hints does not render on the first line of the buffer:
I've pushed a commit, could you try it out?
3. Don't know if it's possible but when we have set `set cursorline` and on the line that our cursor is at the moment there is a hint with `paddingLeft` or `paddingRight`, this padding has different background than the `cursorline` background. I think it would be nice to have this background the same color as the cursorline:
Try to experiment with different values of highlight in the formatter function, perhaps "None"
virt_text_formatter = function(label, hint, opts, client_name)
...
local vt = {}
vt[#vt + 1] = hint.paddingLeft and { " ", "Normal" } or nil
vt[#vt + 1] = { label, opts.highlight }
vt[#vt + 1] = hint.paddingRight and { " ", "Normal" } or nil
return vt
end,
if not, then it's probably https://github.com/lvimuser/lsp-inlayhints.nvim/commit/aa1fee3469f70842fecb0e915fa0d1e5c6784501#diff-35ff978c429cae2ed9217298ef4810beb45307b1baee86f83eb7233f60109fbaL132
I've checked the newest commit and now it works well. About the 3. you were right:
vt[#vt + 1] = hint.paddingLeft and { " ", "None" } or nil
vt[#vt + 1] = { label, opts.highlight }
vt[#vt + 1] = hint.paddingRight and { " ", "None" } or nil
or even
vt[#vt + 1] = hint.paddingLeft and { " " } or nil
vt[#vt + 1] = { label, opts.highlight }
vt[#vt + 1] = hint.paddingRight and { " " } or nil
works just as intended. Thanks and that all from my side
Hello, I was trying to test this out with neovim built from 23426.
Is there a config that I need to set or some settings I need to update? Or I also need the patch from anticonceal branch?
I am seeing the inlay hints but they are all appended at the end of the line. Below are examples:
If you have hints at the end of a line, it means that you have this plugin version from "main" branch and you need version from "anticonceal" branch. Packer has "brach" option you can add in your config to install plugin version from branch ("lazy" should have something similar)
thanks for the info @KostkaBrukowa! Works now.
This seems to work great, with one issue: calling .toggle() hides the inlay hints, but calling it again doesn't re-display the inlay hints.
The anticonceal feature has been merged to master https://github.com/neovim/neovim/pull/20130
Seems to work very fine. An edge case seems to be when the inlay hints are racing with LSP semantic token highlighting. If the inlay hints resolve first:
If the semantic tokens resolve first and inlay hints appear after the LSP semantic highlighting they seem to inherit from the LSP highlighting (or is this something else?)
woo I am excited for this update
If you didn't know, you could use the right_gravity option when placing virtual text. This would, if right_gravity was set to false, when inserting, place the inserted text to the right of the virtual text rather than the left. I found this particularly nice for the parameter type of some LSPs. For example with rust-analyzer
Very nice plugin, thank you.
only_current_line is broken though, it shows on current line when buffer is entered, but not when cursor is moved to another line.
Edit: workaround: autocmd CursorHold * silent! lua require('lsp-inlinehints').show(nil, 5)
Tested and works with lua, cpp, TS with anticonceal, was not successful with rust, anyone else got it working ?
EDIT: should probably state the issue, nothing is showing at all with the anticonceal branch everything works fine on master.
Tested on TS also and had no issues, super thanks!
Seems to work very fine. An edge case seems to be when the inlay hints are racing with LSP semantic token highlighting. If the inlay hints resolve first:
If the semantic tokens resolve first and inlay hints appear after the LSP semantic highlighting they seem to inherit from the LSP highlighting (or is this something else?)
Thanks for the report. I have no idea what's going on there...
If you didn't know, you could use the
right_gravityoption when placing virtual text. This would, ifright_gravitywas set to false, when inserting, place the inserted text to the right of the virtual text rather than the left. I found this particularly nice for the parameter type of some LSPs. For example with rust-analyzer
Thanks, it's way better.
Tested and works with lua, cpp, TS with anticonceal, was not successful with rust, anyone else got it working ?
EDIT: should probably state the issue, nothing is showing at all with the anticonceal branch everything works fine on master.
Not sure... I'll look into it on the weekend.
Seems to work very fine. An edge case seems to be when the inlay hints are racing with LSP semantic token highlighting. If the inlay hints resolve first:
If the semantic tokens resolve first and inlay hints appear after the LSP semantic highlighting they seem to inherit from the LSP highlighting (or is this something else?)
I wonder if this also happens with https://github.com/neovim/neovim/pull/23736...? If so, it's probably a bug in core
was not successful with rust, anyone else got it working ?
EDIT: should probably state the issue, nothing is showing at all with the anticonceal branch everything works fine on master.
It seems like the hints only show up after making some change to the file. but then they update normally
EDIT: does it have something to do with the fact that when inlayhints tries to render initially, rust_analyzer is probably still stuck indexing, so it fails, and then only updates on edit. is there a change related to that in the anticonceal branch?
@IndianBoy42 Yes you are correct, editing the file does resolve the problem, interesting.
@A-Lamia You can try https://github.com/junnplus/lsp-setup.nvim#inlay-hints, I have tested it on Rust and it should work.
Things are working pretty well, but with a few caveats:
- The
togglefunction is erratic. Most times, hints don't come back after toggling them back on unless I modify the buffer I'm editing. I'm guessing that's because the LSP doesn't emit them unless the file is modified, but I figure the plugin should be caching or hiding them instead of outright deleting everything when disabling the hints with the toggle function. - I don't know what the plugin is doing with the highlights but it seems it's not using the highlight group provided as-is. For example, if I specify no background, it will somehow always display with the general background instead of whatever other extmark is present there. Although maybe that's a neovim bug? Extmarks have been finicky lately.
- Is there any way to choose which display mode we want for the hints? I would like to have them as-is for most languages, but switch them back to the old way (at the end of the line) for rust-analyzer, as I find the hits much too disruptive visually.
It might also be worth it to think about the future of this plugin when this pr exists
@A-Lamia You can try junnplus/lsp-setup.nvim#inlay-hints, I have tested it on Rust and it should work.
Seem to not have any luck with I'm guessing the rust configuration, still the same problem where you need to edit to get things to show up.
@ rust-analyzer. Does it happen only on the first buffer, or on each new buffer?
Huh, I dont know what happened but now it just works from the first buffer
Using anticonceal branch on nightly (NVIM v0.10.0-dev-411+g9dd48f783), rust-analyzer inlay hints don't seem to work until rust-analyzer is stopped and started again. Anyone experience something similar, or have a fix?
Config:
{
"lvimuser/lsp-inlayhints.nvim",
event = "LspAttach",
branch = "anticonceal",
opts = {},
config = function(_, opts)
require("lsp-inlayhints").setup(opts)
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("LspAttach_inlayhints", {}),
callback = function(args)
if not (args.data and args.data.client_id) then
return
end
local client = vim.lsp.get_client_by_id(args.data.client_id)
require("lsp-inlayhints").on_attach(client, args.buf)
end,
})
end,
},
Using anticonceal branch on nightly (NVIM v0.10.0-dev-411+g9dd48f783), rust-analyzer inlay hints don't seem to work until rust-analyzer is stopped and started again.
You're creating the autocommand after the LspAttach event, so it'll only trigger on subsequent events... Think about the loading order. You can
- set
lazy = trueand remove theeventkey; or - use ~~
setup~~initinstead ofconfig.
Details
{
"lvimuser/lsp-inlayhints.nvim",
branch = "anticonceal",
opts = {},
lazy = true,
init = function()
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("LspAttach_inlayhints", {}),
callback = function(args)
if not (args.data and args.data.client_id) then
return
end
local client = vim.lsp.get_client_by_id(args.data.client_id)
require("lsp-inlayhints").on_attach(client, args.buf)
end,
})
end,
}

