jubnzv / virtual-types.nvim

Neovim plugin that shows type annotations as virtual text
MIT License
352 stars 5 forks source link

Not working with rust-analyzer #2

Open ghost opened 2 years ago

ghost commented 2 years ago

I've followed readme instructions step by step, installed virtual-types.nvim, included the on_attach snippet, but it simply doesn't works, no error or warning output is displayed, but the virtual texts aren't showing up when i open a .rs file

Not sure if this is relevant, but I'm using nvim-lspinstall for easing the process of setting up language servers

Here's my system details:

jubnzv commented 2 years ago

This plugin works with any LSP server that supports textDocument/codeLens.

Please check the documentation of rust-analyzer to make sure that it supports textDocument/codeLens request, and you have configured it correctly.

ajitid commented 2 years ago

@henriquehbr @sbaildon @beauwilliams have you guys got this plugin working with rust-analyzer? If yes, care to share the code for it?

I expected types to show up in virtual text, but I only can see run commands at the top of the file.

aspeddro commented 2 years ago

textDocument/codeLens in rust_analyzer not show type hints, he providers command to build, debug and tests.

Type hints in rust_analyzer is supported by experimental/inlayHints. See https://github.com/simrat39/rust-tools.nvim/ plugin.

https://github.com/simrat39/rust-tools.nvim/blob/9f89fe6d9762ef89973bbb698c750dd21b94ec44/lua/rust-tools/inlay_hints.lua#L257-L259

LSP espeficifcation for 3.17: https://github.com/microsoft/language-server-protocol/issues/956

ocamllsp has not yet implemented the type hint feature in the textDocument/inlayHints method, so some servers show a different result.

Note

Neovim has built-in support for codelens.

local on_attach = function(client, bufnr)
  --- Only Neovim 0.7
  if client.resolved_capabilities.code_lens then
    local codelens = vim.api.nvim_create_augroup(
      'LSPCodeLens',
      { clear = true }
    )
    vim.api.nvim_create_autocmd({ 'BufEnter' }, {
      group = codelens,
      callback = function()
        vim.lsp.codelens.refresh()
      end,
      buffer = bufnr,
      once = true,
    })
    vim.api.nvim_create_autocmd({ 'BufWritePost', 'CursorHold' }, {
      group = codelens,
      callback = function()
        vim.lsp.codelens.refresh()
      end,
      buffer = bufnr,
    })
  end
end