Skip to content

Commit

Permalink
feat: added support for the new builtin inlay hints
Browse files Browse the repository at this point in the history
Enable with:
```lua
{"neovim/nvim-lspconfig", opts = {inlay_hints = {enabled = true}}}
```
  • Loading branch information
folke committed Jun 21, 2023
1 parent 428bdf7 commit 01c7eee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lua/lazyvim/config/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ map("n", "<leader>ul", function() Util.toggle("relativenumber", true) Util.toggl
map("n", "<leader>ud", Util.toggle_diagnostics, { desc = "Toggle Diagnostics" })
local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3
map("n", "<leader>uc", function() Util.toggle("conceallevel", false, {0, conceallevel}) end, { desc = "Toggle Conceal" })
if vim.lsp.buf.inlay_hint then
map("n", "<leader>uh", function() vim.lsp.buf.inlay_hint(0, nil) end, { desc = "Toggle Inlay Hints" })
end

-- lazygit
map("n", "<leader>gg", function() Util.float_term({ "lazygit" }, { cwd = Util.get_root(), esc_esc = false, ctrl_hjkl = false }) end, { desc = "Lazygit (root dir)" })
Expand Down
14 changes: 14 additions & 0 deletions lua/lazyvim/plugins/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ return {
},
severity_sort = true,
},
-- Enable this to enable the builtin LSP inlay hints on Neovim >= 0.10.0
-- Be aware that you also will need to properly configure your LSP server to
-- provide the inlay hints.
inlay_hints = {
enabled = false,
},
-- add any global capabilities here
capabilities = {},
-- Automatically format on save
Expand Down Expand Up @@ -92,6 +98,14 @@ return {
vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" })
end

if opts.inlay_hints.enabled and vim.lsp.buf.inlay_hint then
Util.on_attach(function(client, buffer)
if client.server_capabilities.inlayHintProvider then
vim.lsp.buf.inlay_hint(buffer, true)
end
end)
end

if type(opts.diagnostics.virtual_text) == "table" and opts.diagnostics.virtual_text.prefix == "icons" then
opts.diagnostics.virtual_text.prefix = vim.fn.has("nvim-0.10.0") == 0 and ""
or function(diagnostic)
Expand Down

4 comments on commit 01c7eee

@rofrol
Copy link

@rofrol rofrol commented on 01c7eee Jun 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow I cannot make it work.

@appelgriebsch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow I cannot make it work.

requires nightly neovim, and you have to configure the LSP adapter to include inlay-hints (e.g. for rust-tools https://github.com/simrat39/rust-tools.nvim#configuration)

@folke
Copy link
Collaborator Author

@folke folke commented on 01c7eee Jun 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check my config for setting up inlay hints for tsserver and lua_ls. Although for lua_ls I disable most:

https://github.com/folke/dot/blob/194946c1103c6aa6040a6d387aa895345feea3e3/nvim/lua/plugins/lsp.lua#L69

@rofrol
Copy link

@rofrol rofrol commented on 01c7eee Jun 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks guys. Regarding nigthly I think this PR added inline hints neovim/neovim#23984

Please sign in to comment.