How to make zls do this?

The initial question is not very helpful, because I don’t know how to explain it


but basically, I want to know how to make zls do the type infernce shown in the above picture. (The glowing green highlighted text after declaration of std and time) . The link to the origin of the screenshot is youtube. This is not a serious question I just want to know

These are called “inlay hints”.

In zls.json configuration file, inlay hints are enabled by default.

You can use the ZLS Installation Guide to find everything related to zls configuration for your editor.

4 Likes

To toggle this in neovim I usually just do.

:lua vim.lsp.inlay_hint.enable()

Or

:lua vim.lsp.inlay_hint.enable(false) to disable.

1 Like

How about <leader>th?

  if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then
     map('<leader>th', function()
       vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
     end, '[T]oggle Inlay [H]ints')
end

I find them bulky, but also useful, so I turn inlays on and off rather frequently. Goes in the LspAttach callback.