Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP: default diagnostic highlight groups not created #14034

Closed
clason opened this issue Feb 28, 2021 · 9 comments
Closed

LSP: default diagnostic highlight groups not created #14034

clason opened this issue Feb 28, 2021 · 9 comments
Labels
bug issues reporting wrong behavior highlight lsp lua stdlib

Comments

@clason
Copy link
Member

clason commented Feb 28, 2021

Background: Questions on Gitter about "how do I enable underline for diagnostics", which should be enabled by default.

Tracing this back, it seems that vim.lsp.diagnostic._define_default_signs_and_highlights doesn't actually define these groups during startup. (Before refuting this, make sure these highlight groups aren't actually defined by your colorscheme as well.)

Tracing further, the issue is that the highlight inside this vim.cmd never gets executed:

vim.cmd(string.format([[highlight %s %s %s]], default and "default" or "", higroup, table.concat(options, " ")))

Which is weird, since

  1. replacing that vim.cmd by print;
  2. replacing that string.format(...) by echo 'foo';
  3. manually calling :lua vim.lsp.diagnostic._define_default_signs_and_highlights() while neovim is running

all show the expected behavior.

@clason clason added bug issues reporting wrong behavior highlight lua stdlib labels Feb 28, 2021
@clason clason added the lsp label Feb 28, 2021
@clason
Copy link
Member Author

clason commented Feb 28, 2021

@tjdevries @bfredl

@ruffson
Copy link
Sponsor

ruffson commented Mar 15, 2021

I have the same problem: no underline on errors and warning. I do see them when I do :lua vim.lsp.diagnostic._define_default_signs_and_highlights().

So I had to put autocmd CursorHold * lua vim.lsp.diagnostic._define_default_signs_and_highlights() in my init.vim.
Thank you for this issue, I was going mad not seeing where the mistake is in a line.

@mjlbach
Copy link
Contributor

mjlbach commented Mar 15, 2021

@clason I can't reproduce this (ignore the garish unset color scheme)

image

image

@comfortablynick
Copy link

After I set my colorscheme, all the highlight groups are cleared unless I set them (I guess this is expected). I don't know what the best way to do this is, but this is what I've been using:

local api = vim.api

function set_hl()
  local ns = api.nvim_create_namespace("hl-lsp")
  api.nvim_set_hl(ns, "LspDiagnosticsDefaultError", {fg = "#ff5f87"})
  api.nvim_set_hl(ns, "LspDiagnosticsDefaultWarning", {fg = "#d78f00"})
  api.nvim_set_hl(ns, "LspDiagnosticsDefaultInformation", {fg = "#d78f00"})
  api.nvim_set_hl(ns, "LspDiagnosticsDefaultHint", {fg = "#ff5f87", bold = true})
  api.nvim_set_hl(ns, "LspDiagnosticsUnderlineError",
                  {fg = "#ff5f87", sp = "#ff5f87", undercurl = true})
  api.nvim_set_hl(ns, "LspDiagnosticsUnderlineWarning",
                  {fg = "#d78f00", sp = "#d78f00", undercurl = true})
  api.nvim_set_hl(ns, "LspReferenceText", {link = "CursorColumn"})
  api.nvim_set_hl(ns, "LspReferenceRead", {link = "LspReferenceText"})
  api.nvim_set_hl(ns, "LspReferenceWrite", {link = "LspReferenceText"})
  api.nvim__set_hl_ns(ns) -- This changed to unstable API
end

My highlights recently disappeared which led me to find that nvim_set_hl_ns() had been changed to nvim__set_hl_ns(). Interestingly I never saw an error, it just stopped working.

So I had to put autocmd CursorHold * lua vim.lsp.diagnostic._define_default_signs_and_highlights() in my init.vim.

@ruffson Why a CursorHold autocmd? I have my custom highlights on a ColorScheme autocmd and they work fine. Not sure if you are trying to do something different.

@ruffson
Copy link
Sponsor

ruffson commented Mar 17, 2021

@ruffson Why a CursorHold autocmd? I have my custom highlights on a ColorScheme autocmd and they work fine. Not sure if you are trying to do something different.

Oh just because I'm a noob and don't know what I'm doing :) What is a better way? Just replace CursorHold with ColorScheme?

@clason
Copy link
Member Author

clason commented Apr 1, 2021

Update: the issue arises when you use a color scheme that contains the line

hi clear

in the beginning (to allow switching color schemes cleanly). Removing that line (unsurprisingly) sets the default highlight groups correctly.

@koalp
Copy link

koalp commented Apr 1, 2021

Update: the issue arises when you use a color scheme that contains the line

hi clear

in the beginning (to allow switching color schemes cleanly). Removing that line (unsurprisingly) sets the default highlight groups correctly.

So is this an issue with colorscheme that do not define highlighting for lsp highlight groups rather than a neovim issue ? Do you think it could (and should) be solved in neovim or should we open issues in colorscheme repositories stating that neovim is supported ? (after 0.5 release ?)

@clason
Copy link
Member Author

clason commented Apr 1, 2021

I think this is an issue with how (or whether) neovim defines these groups. Note that it's perfectly fine to define these groups yourself after setting a color scheme, so it's not necessarily a defect in color schemes to not define it. (For example, I'm not sad that I'm not getting the underlines -- quite the converse since I prefer not to have them!)

It's just not clear (heh) that this way of setting default highlight groups is possible (or if so, reasonable) so that it a) circumvents color schemes that clear all other highlights, b) doesn't overwrite highlight groups if they are set by color scheme or user, and c) doesn't involve messy autocommands.

@clason
Copy link
Member Author

clason commented Apr 14, 2021

Closing as duplicate of #12579 (🤦 for not finding this when creating this issue)

@clason clason closed this as completed Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior highlight lsp lua stdlib
Projects
None yet
Development

No branches or pull requests

7 participants