From e616ec439436816bb39b1d5e720593e6c66580c9 Mon Sep 17 00:00:00 2001 From: Alvaro Muñoz Date: Fri, 3 Jan 2020 23:35:09 +0100 Subject: LSP: differentiate diagnostic underline by severity --- runtime/lua/vim/lsp/util.lua | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'runtime') diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 0de5fdad46..338aedb4e0 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -547,7 +547,10 @@ do local diagnostic_ns = api.nvim_create_namespace("vim_lsp_diagnostics") local underline_highlight_name = "LspDiagnosticsUnderline" - api.nvim_command(string.format("highlight default %s gui=underline cterm=underline", underline_highlight_name)) + vim.cmd(string.format("highlight default %s gui=underline cterm=underline", underline_highlight_name)) + for kind, _ in pairs(protocol.DiagnosticSeverity) do + vim.cmd(string.format("highlight default link %s%s %s", underline_highlight_name, kind, underline_highlight_name)) + end local severity_highlights = {} @@ -657,13 +660,21 @@ do function M.buf_diagnostics_underline(bufnr, diagnostics) for _, diagnostic in ipairs(diagnostics) do - local start = diagnostic.range.start + local start = diagnostic.range["start"] local finish = diagnostic.range["end"] + local hlmap = { + [protocol.DiagnosticSeverity.Error]='Error', + [protocol.DiagnosticSeverity.Warning]='Warning', + [protocol.DiagnosticSeverity.Information]='Information', + [protocol.DiagnosticSeverity.Hint]='Hint', + } + -- TODO care about encoding here since this is in byte index? - highlight_range(bufnr, diagnostic_ns, underline_highlight_name, - {start.line, start.character}, - {finish.line, finish.character} + highlight_range(bufnr, diagnostic_ns, + underline_highlight_name..hlmap[diagnostic.severity], + {start.line, start.character}, + {finish.line, finish.character} ) end end -- cgit From 0a1c6d9a374a0c984515d0af43b1c71af6c55eb2 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 8 Jan 2020 09:46:25 -0800 Subject: LSP: highlight groups test, doc --- runtime/doc/lsp.txt | 35 +++++++++++++++++++++++++---------- runtime/lua/vim/lsp/util.lua | 4 +++- 2 files changed, 28 insertions(+), 11 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index 70a3110042..c173ecead3 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -57,24 +57,39 @@ use of |v:lua| to call Lua from Vimscript): > autocmd Filetype python setlocal omnifunc=v:lua.vim.lsp.omnifunc -FAQ ~ - -> How to force-reload LSP? +================================================================================ +FAQ *lsp-faq* -Stop all clients, then reload the buffer. > +- Q: How to force-reload LSP? + A: Stop all clients, then reload the buffer. > :lua vim.lsp.stop_all_clients() :edit -> Why isn't completion working? - -In the buffer where you want to use LSP, check that 'omnifunc' is set to -"v:lua.vim.lsp.omnifunc": > +- Q: Why isn't completion working? + A: In the buffer where you want to use LSP, check that 'omnifunc' is set to + "v:lua.vim.lsp.omnifunc": > :verbose set omnifunc? -Some other plugin may be overriding the option. To avoid that, you could set -the option in an |after-directory| ftplugin, e.g. "after/ftplugin/python.vim". +< Some other plugin may be overriding the option. To avoid that, you could + set the option in an |after-directory| ftplugin, e.g. + "after/ftplugin/python.vim". + +================================================================================ +LSP HIGHLIGHT *lsp-highlight* + +When LSP is activated these highlight groups are defined: + + LspDiagnosticsError + LspDiagnosticsHint + LspDiagnosticsInformation + LspDiagnosticsUnderline + LspDiagnosticsUnderlineError + LspDiagnosticsUnderlineHint + LspDiagnosticsUnderlineInformation + LspDiagnosticsUnderlineWarning + LspDiagnosticsWarning ================================================================================ LSP API *lsp-api* diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 338aedb4e0..df82e2d412 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -549,7 +549,9 @@ do local underline_highlight_name = "LspDiagnosticsUnderline" vim.cmd(string.format("highlight default %s gui=underline cterm=underline", underline_highlight_name)) for kind, _ in pairs(protocol.DiagnosticSeverity) do - vim.cmd(string.format("highlight default link %s%s %s", underline_highlight_name, kind, underline_highlight_name)) + if type(kind) == 'string' then + vim.cmd(string.format("highlight default link %s%s %s", underline_highlight_name, kind, underline_highlight_name)) + end end local severity_highlights = {} -- cgit