lsp: Add new highlight groups used in show_line_diagnostics (#12473)

* lsp: support custom hl groups in show_line_diagnostics

Closes #12472.

* runtime: add docs for the new lsp highlight groups

Co-authored-by: francisco souza <fsouza@users.noreply.github.com>
This commit is contained in:
francisco souza
2020-06-18 08:04:49 -04:00
committed by GitHub
parent 25aa2969f2
commit 70d4b31b83
3 changed files with 33 additions and 9 deletions

View File

@@ -164,21 +164,36 @@ name: >
LSP HIGHLIGHT *lsp-highlight* LSP HIGHLIGHT *lsp-highlight*
*hl-LspDiagnosticsError* *hl-LspDiagnosticsError*
LspDiagnosticsError used for "Error" diagnostic virtual text LspDiagnosticsError used for "Error" diagnostic virtual text
*hl-LspDiagnosticsErrorSign* *hl-LspDiagnosticsErrorSign*
LspDiagnosticsErrorSign used for "Error" diagnostic signs in sign column LspDiagnosticsErrorSign used for "Error" diagnostic signs in sign
column
*hl-LspDiagnosticsErrorFloating*
LspDiagnosticsErrorFloating used for "Error" diagnostic messages in the
diagnostics float
*hl-LspDiagnosticsWarning* *hl-LspDiagnosticsWarning*
LspDiagnosticsWarning used for "Warning" diagnostic virtual text LspDiagnosticsWarning used for "Warning" diagnostic virtual text
*hl-LspDiagnosticsWarningSign* *hl-LspDiagnosticsWarningSign*
LspDiagnosticsWarningSign used for "Warning" diagnostic signs in sign column LspDiagnosticsWarningSign used for "Warning" diagnostic signs in sign
column
*hl-LspDiagnosticsWarningFloating*
LspDiagnosticsWarningFloating used for "Warning" diagnostic messages in the
diagnostics float
*hl-LspDiagnosticsInformation* *hl-LspDiagnosticsInformation*
LspDiagnosticsInformation used for "Information" diagnostic virtual text LspDiagnosticsInformation used for "Information" diagnostic virtual text
*hl-LspDiagnosticsInformationSign* *hl-LspDiagnosticsInformationSign*
LspDiagnosticsInformationSign used for "Information" signs in sign column LspDiagnosticsInformationSign used for "Information" signs in sign column
*hl-LspDiagnosticsInformationFloating*
LspDiagnosticsInformationFloating used for "Information" diagnostic messages in
the diagnostics float
*hl-LspDiagnosticsHint* *hl-LspDiagnosticsHint*
LspDiagnosticsHint used for "Hint" diagnostic virtual text LspDiagnosticsHint used for "Hint" diagnostic virtual text
*hl-LspDiagnosticsHintSign* *hl-LspDiagnosticsHintSign*
LspDiagnosticsHintSign used for "Hint" diagnostic signs in sign column LspDiagnosticsHintSign used for "Hint" diagnostic signs in sign
column
*hl-LspDiagnosticsHintFloating*
LspDiagnosticsHintFloating used for "Hint" diagnostic messages in the
diagnostics float
*hl-LspReferenceText* *hl-LspReferenceText*
LspReferenceText used for highlighting "text" references LspReferenceText used for highlighting "text" references
*hl-LspReferenceRead* *hl-LspReferenceRead*

View File

@@ -859,6 +859,8 @@ do
local severity_highlights = {} local severity_highlights = {}
local severity_floating_highlights = {}
local default_severity_highlight = { local default_severity_highlight = {
[protocol.DiagnosticSeverity.Error] = { guifg = "Red" }; [protocol.DiagnosticSeverity.Error] = { guifg = "Red" };
[protocol.DiagnosticSeverity.Warning] = { guifg = "Orange" }; [protocol.DiagnosticSeverity.Warning] = { guifg = "Orange" };
@@ -870,6 +872,7 @@ do
for severity, hi_info in pairs(default_severity_highlight) do for severity, hi_info in pairs(default_severity_highlight) do
local severity_name = protocol.DiagnosticSeverity[severity] local severity_name = protocol.DiagnosticSeverity[severity]
local highlight_name = "LspDiagnostics"..severity_name local highlight_name = "LspDiagnostics"..severity_name
local floating_highlight_name = highlight_name.."Floating"
-- Try to fill in the foreground color with a sane default. -- Try to fill in the foreground color with a sane default.
local cmd_parts = {"highlight", "default", highlight_name} local cmd_parts = {"highlight", "default", highlight_name}
for k, v in pairs(hi_info) do for k, v in pairs(hi_info) do
@@ -877,7 +880,9 @@ do
end end
api.nvim_command(table.concat(cmd_parts, ' ')) api.nvim_command(table.concat(cmd_parts, ' '))
api.nvim_command('highlight link ' .. highlight_name .. 'Sign ' .. highlight_name) api.nvim_command('highlight link ' .. highlight_name .. 'Sign ' .. highlight_name)
api.nvim_command('highlight link ' .. highlight_name .. 'Floating ' .. highlight_name)
severity_highlights[severity] = highlight_name severity_highlights[severity] = highlight_name
severity_floating_highlights[severity] = floating_highlight_name
end end
function M.buf_clear_diagnostics(bufnr) function M.buf_clear_diagnostics(bufnr)
@@ -926,7 +931,7 @@ do
-- TODO(ashkan) make format configurable? -- TODO(ashkan) make format configurable?
local prefix = string.format("%d. ", i) local prefix = string.format("%d. ", i)
local hiname = severity_highlights[diagnostic.severity] local hiname = severity_floating_highlights[diagnostic.severity]
assert(hiname, 'unknown severity: ' .. tostring(diagnostic.severity)) assert(hiname, 'unknown severity: ' .. tostring(diagnostic.severity))
local message_lines = split_lines(diagnostic.message) local message_lines = split_lines(diagnostic.message)
table.insert(lines, prefix..message_lines[1]) table.insert(lines, prefix..message_lines[1])

View File

@@ -770,10 +770,13 @@ describe('LSP', function()
it('highlight groups', function() it('highlight groups', function()
eq({'LspDiagnosticsError', eq({'LspDiagnosticsError',
'LspDiagnosticsErrorFloating',
'LspDiagnosticsErrorSign', 'LspDiagnosticsErrorSign',
'LspDiagnosticsHint', 'LspDiagnosticsHint',
'LspDiagnosticsHintFloating',
'LspDiagnosticsHintSign', 'LspDiagnosticsHintSign',
'LspDiagnosticsInformation', 'LspDiagnosticsInformation',
'LspDiagnosticsInformationFloating',
'LspDiagnosticsInformationSign', 'LspDiagnosticsInformationSign',
'LspDiagnosticsUnderline', 'LspDiagnosticsUnderline',
'LspDiagnosticsUnderlineError', 'LspDiagnosticsUnderlineError',
@@ -781,6 +784,7 @@ describe('LSP', function()
'LspDiagnosticsUnderlineInformation', 'LspDiagnosticsUnderlineInformation',
'LspDiagnosticsUnderlineWarning', 'LspDiagnosticsUnderlineWarning',
'LspDiagnosticsWarning', 'LspDiagnosticsWarning',
'LspDiagnosticsWarningFloating',
'LspDiagnosticsWarningSign', 'LspDiagnosticsWarningSign',
}, },
exec_lua([[require'vim.lsp'; return vim.fn.getcompletion('Lsp', 'highlight')]])) exec_lua([[require'vim.lsp'; return vim.fn.getcompletion('Lsp', 'highlight')]]))