aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2020-01-08 22:48:57 -0800
committerGitHub <noreply@github.com>2020-01-08 22:48:57 -0800
commit25afa10f9277dd6148a6abb3d7577c67f479fce2 (patch)
treef716d09f58416c4f4329743578b8aa536f20ae49
parentb6276f5aee835a6d44b2957027c5399c976c6647 (diff)
parent0a1c6d9a374a0c984515d0af43b1c71af6c55eb2 (diff)
downloadrneovim-25afa10f9277dd6148a6abb3d7577c67f479fce2.tar.gz
rneovim-25afa10f9277dd6148a6abb3d7577c67f479fce2.tar.bz2
rneovim-25afa10f9277dd6148a6abb3d7577c67f479fce2.zip
Merge #11669 'LSP: differentiate diagnostic underline by severity'
-rw-r--r--runtime/doc/lsp.txt35
-rw-r--r--runtime/lua/vim/lsp/util.lua23
-rw-r--r--test/functional/helpers.lua5
-rw-r--r--test/functional/plugin/lsp/util_spec.lua76
-rw-r--r--test/functional/plugin/lsp_spec.lua (renamed from test/functional/plugin/lsp/lsp_spec.lua)80
5 files changed, 128 insertions, 91 deletions
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 0de5fdad46..df82e2d412 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -547,7 +547,12 @@ 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
+ 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 = {}
@@ -657,13 +662,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
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 0fdfcd70ba..e0012c6ced 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -559,6 +559,11 @@ function module.wait()
session:request('nvim_eval', '1')
end
+function module.buf_lines(bufnr)
+ return module.exec_lua("return vim.api.nvim_buf_get_lines((...), 0, -1, false)", bufnr)
+end
+
+--@see buf_lines()
function module.curbuf_contents()
module.wait() -- Before inspecting the buffer, process all input.
return table.concat(module.curbuf('get_lines', 0, -1, true), '\n')
diff --git a/test/functional/plugin/lsp/util_spec.lua b/test/functional/plugin/lsp/util_spec.lua
deleted file mode 100644
index 1cf0e48be4..0000000000
--- a/test/functional/plugin/lsp/util_spec.lua
+++ /dev/null
@@ -1,76 +0,0 @@
-local helpers = require('test.functional.helpers')(after_each)
-local eq = helpers.eq
-local exec_lua = helpers.exec_lua
-local dedent = helpers.dedent
-local insert = helpers.insert
-local clear = helpers.clear
-
-describe('LSP util', function()
- local test_text = dedent([[
- First line of text
- Second line of text
- Third line of text
- Fourth line of text]])
-
- local function reset()
- clear()
- insert(test_text)
- end
-
- before_each(reset)
-
- local function make_edit(y_0, x_0, y_1, x_1, text)
- return {
- range = {
- start = { line = y_0, character = x_0 };
- ["end"] = { line = y_1, character = x_1 };
- };
- newText = type(text) == 'table' and table.concat(text, '\n') or (text or "");
- }
- end
-
- local function buf_lines(bufnr)
- return exec_lua("return vim.api.nvim_buf_get_lines((...), 0, -1, false)", bufnr)
- end
-
- describe('apply_edits', function()
- it('should apply simple edits', function()
- local edits = {
- make_edit(0, 0, 0, 0, {"123"});
- make_edit(1, 0, 1, 1, {"2"});
- make_edit(2, 0, 2, 2, {"3"});
- }
- exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1)
- eq({
- '123First line of text';
- '2econd line of text';
- '3ird line of text';
- 'Fourth line of text';
- }, buf_lines(1))
- end)
-
- it('should apply complex edits', function()
- local edits = {
- make_edit(0, 0, 0, 0, {"", "12"});
- make_edit(0, 0, 0, 0, {"3", "foo"});
- make_edit(0, 1, 0, 1, {"bar", "123"});
- make_edit(0, #"First ", 0, #"First line of text", {"guy"});
- make_edit(1, 0, 1, #'Second', {"baz"});
- make_edit(2, #'Th', 2, #"Third", {"e next"});
- make_edit(3, #'', 3, #"Fourth", {"another line of text", "before this"});
- make_edit(3, #'Fourth', 3, #"Fourth line of text", {"!"});
- }
- exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1)
- eq({
- '';
- '123';
- 'fooFbar';
- '123irst guy';
- 'baz line of text';
- 'The next line of text';
- 'another line of text';
- 'before this!';
- }, buf_lines(1))
- end)
- end)
-end)
diff --git a/test/functional/plugin/lsp/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index e54275e820..4829a33861 100644
--- a/test/functional/plugin/lsp/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -1,8 +1,11 @@
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
+local buf_lines = helpers.buf_lines
+local dedent = helpers.dedent
local exec_lua = helpers.exec_lua
local eq = helpers.eq
+local insert = helpers.insert
local iswin = helpers.iswin
local retry = helpers.retry
local NIL = helpers.NIL
@@ -706,3 +709,80 @@ describe('LSP', function()
end)
end)
+
+describe('LSP', function()
+ before_each(function()
+ clear()
+ end)
+
+ local function make_edit(y_0, x_0, y_1, x_1, text)
+ return {
+ range = {
+ start = { line = y_0, character = x_0 };
+ ["end"] = { line = y_1, character = x_1 };
+ };
+ newText = type(text) == 'table' and table.concat(text, '\n') or (text or "");
+ }
+ end
+
+ it('highlight groups', function()
+ eq({'LspDiagnosticsError',
+ 'LspDiagnosticsHint',
+ 'LspDiagnosticsInformation',
+ 'LspDiagnosticsUnderline',
+ 'LspDiagnosticsUnderlineError',
+ 'LspDiagnosticsUnderlineHint',
+ 'LspDiagnosticsUnderlineInformation',
+ 'LspDiagnosticsUnderlineWarning',
+ 'LspDiagnosticsWarning',
+ },
+ exec_lua([[require'vim.lsp'; return vim.fn.getcompletion('Lsp', 'highlight')]]))
+ end)
+
+ describe('apply_edits', function()
+ before_each(function()
+ insert(dedent([[
+ First line of text
+ Second line of text
+ Third line of text
+ Fourth line of text]]))
+ end)
+ it('applies apply simple edits', function()
+ local edits = {
+ make_edit(0, 0, 0, 0, {"123"});
+ make_edit(1, 0, 1, 1, {"2"});
+ make_edit(2, 0, 2, 2, {"3"});
+ }
+ exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1)
+ eq({
+ '123First line of text';
+ '2econd line of text';
+ '3ird line of text';
+ 'Fourth line of text';
+ }, buf_lines(1))
+ end)
+ it('applies complex edits', function()
+ local edits = {
+ make_edit(0, 0, 0, 0, {"", "12"});
+ make_edit(0, 0, 0, 0, {"3", "foo"});
+ make_edit(0, 1, 0, 1, {"bar", "123"});
+ make_edit(0, #"First ", 0, #"First line of text", {"guy"});
+ make_edit(1, 0, 1, #'Second', {"baz"});
+ make_edit(2, #'Th', 2, #"Third", {"e next"});
+ make_edit(3, #'', 3, #"Fourth", {"another line of text", "before this"});
+ make_edit(3, #'Fourth', 3, #"Fourth line of text", {"!"});
+ }
+ exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1)
+ eq({
+ '';
+ '123';
+ 'fooFbar';
+ '123irst guy';
+ 'baz line of text';
+ 'The next line of text';
+ 'another line of text';
+ 'before this!';
+ }, buf_lines(1))
+ end)
+ end)
+end)