nvim-lua / kickstart.nvim

A launch point for your personal nvim configuration
MIT License
18.86k stars 21.57k forks source link

turn inlay hints on by default? #948

Closed damccull closed 2 months ago

damccull commented 4 months ago

I just updated to the most recent commit for kickstart.nvim and I'm happy to see a toggle now for inlay hints.

However, I want it on by default and able to be toggled off. I understand the <leader>th keymap will toggle to the inverse of the current state, so I tried adding this to my init.lua near my vim.opts.

-- Enable inlay hints by default; toggle off with <leader>th
vim.lsp.inlay_hint.enable()

The toggle will still work if I toggle it twice (I'm assuming the first one is setting it to 'off' after my code messes up the state), but I can't get it to default on. How do I fix this?

eljamm commented 4 months ago

How about adding it like this, instead?

if client and client.server_capabilities.inlayHintProvider and vim.lsp.inlay_hint then
  -- Toggle inlay hints
  map('<leader>th', function()
    vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
  end, '[T]oggle Inlay [H]ints')

  -- Enable inlay hints by default
  vim.lsp.inlay_hint.enable()
end

This way, inlay hints will be on by default and you can toggle them with <leader>th

damccull commented 4 months ago

Oh, wow. That's great, thanks. Exactly what I was trying to do and in a much better way.

damccull commented 4 months ago

Well, I thought this should work, but inlay hints are not enabling until I toggle it twice, still. Am I using the enable() function wrong?

damccull commented 4 months ago

Ok, so it does seem to be activating inlay hints. However, they aren't showing up until something in the code changes. If I force rust_analyzer to reevaluate the code by changing whitespace above or below where I should see an inlay, for instance, it shows up. Otherwise I need to toggle it twice. Is there an additional code I need to make it display them automatically without needing to change something or manually toggle it twice?

eljamm commented 4 months ago

I'm using rustaceanvim and it works normally.

I guess the issue you're describing is related to this, which rustaceanvim is working around here.

sergeken commented 4 months ago

Would be great to have a commented section with

-- Remove comment to enable inlay hints by default -- vim.lsp.inlay_hint.enable()

dffuller commented 3 months ago

It appears some of this code made it into the last release.

if client and client.server_capabilities.inlayHintProvider and vim.lsp.inlay_hint then
  -- Toggle inlay hints
  map('<leader>th', function()
    vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
  end, '[T]oggle Inlay [H]ints')

  -- Enable inlay hints by default
  vim.lsp.inlay_hint.enable()
end

When I go through diagnostic errors in a (basically) new kickstart.nvim file, I am getting an error stating "This function requires 1 argument but instead it is receiving 0 for the is_enabled() call. The diagnostic error goes away when I add a table { bufnr = 0} inside the call, but I'm not sure this is what is desired.

Edit: It looks like you can just drop the parens after is_enabled. They seem to be throwing the diagnostic error.

eljamm commented 3 months ago

Curious why that doesn't work for you considering that's how it's written in the Neovim docs. It still works for me, but deleting the parens works as well.

Is it a difference in versions? I'm using Neovim v0.10.0

dffuller commented 3 months ago

I, too, am using v0.10.0. I can't say for certain that it "doesn't work" but I was getting diagnostic errors for the issue.

eljamm commented 3 months ago

Oh, that's just a warning not an error, so you can safely ignore it. I didn't see it before because I had turned off some neodev diagnostics.

It's worth noting that I thought removing the parens worked at first, but with that the toggle only works once, then it stops working. Replacing the parens with curly braces worked, though, and the warning disappeared as well:

    vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled {})

Don't know what the ramifications of this is are, though.

VlaDexa commented 3 months ago

I was getting diagnostic errors for the issue.

This was a neovim docs issue

feoh commented 2 months ago

Fixed in a recent merge.

VlaDexa commented 2 months ago

Not quite fixed (because the initial issue wasn't a bug, more of a question), but I think it's overall resolved apart from the neovim issue.