5

In neovim, these keymaps (from nvim-lspconfig) show diagnostics from LSP servers on a floating window:

vim.keymap.set('n', '<leader>le', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)

The floating window uses highlight group :h hl-NormalFloat. I set its background to be equal to :h hl-Normal so it looks like a transparent window. The problem is: now I can't distinguish between the floating window and the main window.

I could reset the background color of NormalFloat to something distinguishable than Normal, but that would not work properly with the highlighting colors of the diagnostic messages. Adding a border around the floating would be the best solution. How do I do that?

1 Answer 1

9

Since version 5.0, neovim supports adding borders to floating windows. :h lsp integrates it, too. But not by default; we have to enable it. The following configuration would do so.

local _border = "single"

vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
  vim.lsp.handlers.hover, {
    border = _border
  }
)

vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
  vim.lsp.handlers.signature_help, {
    border = _border
  }
)

vim.diagnostic.config{
  float={border=_border}
}

The border of the floating windows uses FloatBorder highlight group. So we will have to define it for optimum readability/visibility.

highlight FloatBorder  ctermfg=NONE ctermbg=NONE cterm=NONE

The document for border can be found in :h nvim_open_win (search for /\v<border:), which is used in configuring LSP diagnostics (see :h vim.diagnostic.config()) and LSP handlers (see :h vim.lsp.handlers.hover() and :h vim.lsp.handlers.signature_help()).

 

P.S. The floating window of :LSPInfo does not use the configuration of the diagnostic or handlers. It's provided by the plugin nvim-lspconfig, which provides a separate configuration for its border, which can be activated by this code:

require('lspconfig.ui.windows').default_options = {
  border = _border
}
1
  • 2
    Thank you for the bit about :LSPInfo! That was the missing piece for me. Cheers!
    – jrnxf
    Nov 29, 2022 at 4:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.