Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inlay_hint enable(<no args>) does not activate inlay hints on open buffers #28624

Closed
justinmk opened this issue May 3, 2024 · 13 comments · Fixed by #28629
Closed

inlay_hint enable(<no args>) does not activate inlay hints on open buffers #28624

justinmk opened this issue May 3, 2024 · 13 comments · Fixed by #28629
Labels
bug issues reporting wrong behavior bug-regression wrong behavior that was introduced in a previous commit (please bisect) lsp
Milestone

Comments

@justinmk
Copy link
Member

justinmk commented May 3, 2024

Problem

regression from #28523 or #28543

vim.lsp.inlay_hint.is_enabled()  -- false (this is expected ✅)
vim.lsp.inlay_hint.enable()  -- enable globally. But inlay hints are not shown (wrong ❌)
vim.lsp.inlay_hint.is_enabled()  -- true (ok ✅)
vim.lsp.inlay_hint.is_enabled({bufnr=0}) -- true (ok ✅)

Workarounds

  • passing an explicit bufnr activates inlay hints in existing visible buffers: vim.lsp.inlay_hint.enable(true, {bufnr=0})
  • reloading a buffer with :edit activates the hints

Expected behavior

vim.lsp.inlay_hint.enable(nil|true) should activate inlay hints for open buffers

@justinmk justinmk added bug issues reporting wrong behavior bug-regression wrong behavior that was introduced in a previous commit (please bisect) lsp labels May 3, 2024
@justinmk justinmk added this to the 0.10 milestone May 3, 2024
@justinmk justinmk changed the title inlay_hint enable() does not activate inlay hints without explicit bufnr inlay_hint enable(<no args>) does not activate inlay hints on open buffers May 3, 2024
@mehalter
Copy link
Contributor

mehalter commented May 3, 2024

Ah it looks like we opened issues separately regarding similar things with vim.lsp.inlay_hint (#28625). I actually didn't even see if the inlay hints actually get displayed in my issue and just referred to the incorrect state behavior of the enabling. Let me know if we should consolidate my issue into this to centralize bugs with the new API.

@mehalter
Copy link
Contributor

mehalter commented May 3, 2024

I will move over the case I found here:

vim.lsp.inlay_hint.is_enabled() -- false (ok ✅)
vim.lsp.inlay_hint.enable(true) -- enable globally
vim.lsp.inlay_hint.is_enabled() -- true (ok ✅)
vim.lsp.inlay_hint.is_enabled({ bufnr = 0 }) -- true (ok ✅)
vim.lsp.inlay_hint.enable(false, { bufnr = 0 })
vim.lsp.inlay_hint.is_enabled({ bufnr = 0 }) -- true (wrong ❌)

@ofseed
Copy link
Contributor

ofseed commented May 3, 2024

Seems to be separate problems, For now, I can reproduce from the case @mehalter provided and I know the reason, but I can't reproduce from what @justinmk provided. I will look into this issue

@mehalter
Copy link
Contributor

mehalter commented May 3, 2024

Thanks for investigating @ofseed let me know if you want me to reopen my issue to separate them. I figured they may be resulting from the same root cause. Granted I also can't replicate the other issue with just calling enable without a buffer number

@ofseed
Copy link
Contributor

ofseed commented May 3, 2024

#28627 should fix the case @mehalter provided, I'm not sure if it fixes the problem @justinmk is having.

@ofseed
Copy link
Contributor

ofseed commented May 3, 2024

@justinmk I still can't find how to reproduce, can you please provide a more detailed use case?

@justinmk
Copy link
Member Author

justinmk commented May 3, 2024

can you please provide a more detailed use case?

tested with 5282361 :

  1. open a file which has a LSP server that provides inline hints.
  2. run lua vim.lsp.inlay_hint.enable()
  3. inlay hints not displayed.
  4. reload the buffer with :edit, now the inlay hints are displayed.

If step (2) is changed to lua vim.lsp.inlay_hint.enable(true, {bufnr=0}) , then there is no issue (step 3 shows inlay hints).

@mehalter
Copy link
Contributor

mehalter commented May 3, 2024

Hm, I can't replicate this at all either, tested with 5282361 as well

As soon as I run lua vim.lsp.inlay_hint.enable() it shows the inlay hints (assuming the language server is fully loaded). What language server are you testing it with @justinmk ?

@justinmk
Copy link
Member Author

justinmk commented May 3, 2024

clangd, opening main.c from Nvim source tree. This didn't happen until the recent changes.

@ofseed
Copy link
Contributor

ofseed commented May 3, 2024

This didn't happen until the recent changes.

This may be important information. Rather than reload the buffer by :edit, do inlay hints appear when you modify the document?

Edit: I found I can reproduce it by clangd, and they do appear after editing, thanks.

@justinmk
Copy link
Member Author

justinmk commented May 3, 2024

Rather than reload the buffer by :edit, do inlay hints appear when you modify the document?

yes

@sergeken
Copy link

sergeken commented May 7, 2024

Also, it might take time before the inlay hints are shown. I've this experience with a rust project that has a few "heavy" dependencies and rust_analyzer is "chewing" on the code for some minutes. And until then nothing is shown. Inlay hints are the last thing that seems to be performed. I've observed the same behavior in vscode.
Can you check with top to see that clangd is indeed "done".

@ofseed
Copy link
Contributor

ofseed commented May 7, 2024

This is a bug that needs to meet certain conditions to occur, and it does exist. #28629 will fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior bug-regression wrong behavior that was introduced in a previous commit (please bisect) lsp
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants