nvim-neotest / neotest

An extensible framework for interacting with tests within NeoVim.
MIT License
2.35k stars 115 forks source link

Change diagnostic highlighting, without applying the same highlighting to all other lsp diagnostics #176

Closed DasOhmoff closed 1 year ago

DasOhmoff commented 1 year ago

Hello :) , thanks again for this nice plugin!

I have the following question: Is it possible to change neotest's diagnostic highlighting of errors, without applying the same highlighting also for all kinds of other lsp errors?

I would like to change the color of the failed test diagnostics, because otherwise they look identical to the lsp diagnostic errors, and it gets a little confusing sometimes: image Both the virtual text and gutter highlighting is the same. I would like to change both of these highlightings, how can I do so?

Thank you for your help!

rcarriga commented 1 year ago

I don't believe this is possible with the current diagnostic API. You could implement this yourself but it'll require overriding the built-in handlers

For example the virtual text handler sets the highlight group here https://github.com/neovim/neovim/blob/ce80b8f50d7d56ac12aa06a64a65799ec18b69af/runtime/lua/vim/diagnostic.lua#L1069 so you could replace the implementation to use a namespace specific one and then change the highlight if it is the neotest namespace

DasOhmoff commented 1 year ago

Oh, that seems a lot more complicated than I expected. Thanks for the answer though, is very helpful :)

So if I understand correctly, when I would override the function, I would have to copy the whole original function and its dependencies and override some of its code, is that right? Maybe I just misunderstood, and there is another way, but if not, then I don't want to go there, this seems a little too much for me.

Looking at the complexity of it, I thought I should try to just change the severity from error to info instead, then the colors would be different in most of the cases:

local original = vim.diagnostic.handlers.virtual_text.show;
vim.diagnostic.handlers.virtual_text.show = function(namespace, bufnr, diagnostic, opts)
  if namespace == neotest_namespace_id then
    for key,value in pairs(diagnostic) do
      value.severity = vim.diagnostic.severity.INFO
    end
  end

  original(namespace, bufnr, diagnostic, opts)
end

But this does not seem to work many times, only seldomly do both the sign and virtual text have the INFO color, most of the time, the colors are still wrong.

Is there a way then to change the severity from error to info without too much hassle, so that I then can see the color difference?

rcarriga commented 1 year ago

I've added a diagnostic.severity config option so you can change the severity used for diagnostics :smile:

DasOhmoff commented 1 year ago

That's perfect! Thanks! :)