lewis6991/hover.nvim

LSP hover has different syntax highlighting, does not respect conceallevel for links

Closed this issue · 6 comments

The LSP hover seems to be using a different colour scheme than the editor.

For example (see the colouring of the line import numpy as np in the editor vs. the hover floating window):
Screenshot from 2024-06-14 10-32-37

In comparison, the default vim.lsp.buf.hover() uses the same colours:
Screenshot from 2024-06-14 10-32-26

Furthermore, the hover doesn't respect the conceallevel for links. At conceallevel=2, these should be hidden unless the cursor is on the same line. The current behaviour makes markdown with URLs harder to read.

Incidentally, is there a way to fall back to the default hover (vim.lsp.buf.hover()) if every hover provider fails to execute? For example, what if I want to use the GitHub issues and DAP providers, but don't want to use the LSP provider? That is, I want "K" for GitHub issues and DAP expressions, but show the native LSP help.

There is no way to fallback to the default LSP hover other than copying the implementation. The current implementation is based off the old one before it got rewritten.

Feel free to write your own provider that does what you want.

The filetype of the float window is detected as markdown. I don't understand why it isn't using the same markdown syntax highlighting which is used in the editor. Is the default syntax highlighting being overridden somehow?

Yes

Can you explain the reason? Is it to implement specific features? It seems strange to me not to use the same highlighting for code in the LSP floating window as in the main editor window. The identical colours are really helpful in visually pattern matching my code against the LSP help.

It seems strange to me not to use the same highlighting for code in the LSP floating window as in the main editor window.

It uses the exact same highlighting as Nvim 0.9 and earlier. Specifically, it calls vim.lsp.util.convert_inpuit_to_markdown_lines(), which is provided by Nvim's stdlib. Nvim 0.10 updated the highlighting to a new implementation that uses treesitter.

If you are still confused then I suggest you look at the code. The LSP provider is just 110 LOC.

I'll even paste the most relevant section:

  execute = function(opts, done)
    local row, col = opts.pos[1] - 1, opts.pos[2]
    local util = require('vim.lsp.util')

    buf_request_all(
      opts.bufnr,
      'textDocument/hover',
      create_params(opts.bufnr, row, col),
      function(results)
        for _, result in pairs(results or {}) do
          if result.contents then
            local lines = util.convert_input_to_markdown_lines(result.contents)
            if not vim.tbl_isempty(lines) then
              done{lines=lines, filetype="markdown"}
              return
            end
          end
        end
        -- no results
        done()
      end
    )
  end

Thanks, I'll work around this.