aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xci/before_script.sh6
-rw-r--r--ci/common/build.sh9
-rw-r--r--runtime/doc/lsp.txt31
-rw-r--r--runtime/lua/vim/lsp.lua2
-rw-r--r--runtime/lua/vim/lsp/buf.lua6
-rw-r--r--runtime/lua/vim/lsp/callbacks.lua15
-rw-r--r--runtime/lua/vim/lsp/util.lua114
-rw-r--r--src/nvim/os/signal.c33
-rw-r--r--src/nvim/syntax.c2
-rw-r--r--src/nvim/testdir/test_messages.vim3
-rw-r--r--src/nvim/tui/tui.c3
-rw-r--r--src/nvim/version.c6
-rw-r--r--test/functional/plugin/lsp_spec.lua16
13 files changed, 134 insertions, 112 deletions
diff --git a/ci/before_script.sh b/ci/before_script.sh
index a0e87adb9e..1759dbe942 100755
--- a/ci/before_script.sh
+++ b/ci/before_script.sh
@@ -10,6 +10,12 @@ fi
CI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${CI_DIR}/common/build.sh"
+# Enable ipv6 on Travis. ref: a39c8b7ce30d
+if ! test "${TRAVIS_OS_NAME}" = osx ; then
+ echo "before_script.sh: enable ipv6"
+ sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=0
+fi
+
# Test some of the configuration variables.
if [[ -n "${GCOV}" ]] && [[ ! $(type -P "${GCOV}") ]]; then
echo "\$GCOV: '${GCOV}' is not executable."
diff --git a/ci/common/build.sh b/ci/common/build.sh
index 02e1110a15..0024f2cbd5 100644
--- a/ci/common/build.sh
+++ b/ci/common/build.sh
@@ -86,12 +86,3 @@ build_nvim() {
cd "${TRAVIS_BUILD_DIR}"
}
-
-macos_rvm_dance() {
- # neovim-ruby gem requires a ruby newer than the macOS default.
- source ~/.rvm/scripts/rvm
- rvm get stable --auto-dotfiles
- rvm reload
- rvm use 2.2.5
- rvm use
-}
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 4c59e53343..e53853b1b1 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -752,9 +752,6 @@ npcall({fn}, {...}) *vim.lsp.buf.npcall()*
ok_or_nil({status}, {...}) *vim.lsp.buf.ok_or_nil()*
TODO: Documentation
-peek_definition() *vim.lsp.buf.peek_definition()*
- TODO: Documentation
-
*vim.lsp.buf.range_formatting()*
range_formatting({options}, {start_pos}, {end_pos})
TODO: Documentation
@@ -915,6 +912,21 @@ apply_text_edits({text_edits}, {bufnr})
apply_workspace_edit({workspace_edit})
TODO: Documentation
+ *vim.lsp.util.diagnostics_by_buf*
+diagnostics_by_buf
+ A table containing diagnostics grouped by buf.
+
+ {<bufnr>: {diagnostics}}
+
+ {diagnostics} is an array of diagnostics.
+
+ By default this is populated by the
+ `textDocument/publishDiagnostics` callback via
+ |vim.lsp.util.buf_diagnostics_save_positions|.
+
+ It contains entries for active buffers. Once a buffer is
+ detached the entries for it are discarded.
+
buf_clear_diagnostics({bufnr}) *vim.lsp.util.buf_clear_diagnostics()*
TODO: Documentation
@@ -945,9 +957,14 @@ buf_diagnostics_count({kind})
buf_clear_references({bufnr}) *vim.lsp.util.buf_clear_references()*
TODO: Documentation
- *vim.lsp.util.buf_diagnostics_save_positions()*
+ *vim.lsp.util.buf_diagnostics_save()*
buf_diagnostics_save_positions({bufnr}, {diagnostics})
- TODO: Documentation
+ Stores the diagnostics into |vim.lsp.util.diagnostics_by_buf|
+
+ Parameters: ~
+ {bufr} bufnr for which the diagnostics are for.
+ {diagnostics} Diagnostics[] received from the
+ langauge server.
*vim.lsp.util.buf_diagnostics_underline()*
buf_diagnostics_underline({bufnr}, {diagnostics})
@@ -1033,10 +1050,6 @@ npcall({fn}, {...}) *vim.lsp.util.npcall()*
ok_or_nil({status}, {...}) *vim.lsp.util.ok_or_nil()*
TODO: Documentation
- *vim.lsp.util.open_floating_peek_preview()*
-open_floating_peek_preview({bufnr}, {start}, {finish}, {opts})
- TODO: Documentation
-
*vim.lsp.util.open_floating_preview()*
open_floating_preview({contents}, {filetype}, {opts})
TODO: Documentation
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index afff4d9900..17135e078c 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -198,6 +198,7 @@ local function text_document_did_open_handler(bufnr, client)
}
}
client.notify('textDocument/didOpen', params)
+ util.buf_versions[bufnr] = params.textDocument.version
end
--- LSP client object.
@@ -722,6 +723,7 @@ function lsp.buf_attach_client(bufnr, client_id)
client.notify('textDocument/didClose', params)
end
end)
+ util.buf_versions[bufnr] = nil
all_buffer_active_clients[bufnr] = nil
end;
-- TODO if we know all of the potential clients ahead of time, then we
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index fc9e10cb73..587d1f52e9 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -32,12 +32,6 @@ function M.hover()
request('textDocument/hover', params)
end
-function M.peek_definition()
- local params = util.make_position_params()
- request('textDocument/peekDefinition', params)
-end
-
-
function M.declaration()
local params = util.make_position_params()
request('textDocument/declaration', params)
diff --git a/runtime/lua/vim/lsp/callbacks.lua b/runtime/lua/vim/lsp/callbacks.lua
index 9c30085f37..bd2cbf1ea7 100644
--- a/runtime/lua/vim/lsp/callbacks.lua
+++ b/runtime/lua/vim/lsp/callbacks.lua
@@ -151,21 +151,6 @@ M['textDocument/signatureHelp'] = function(_, method, result)
end)
end
-M['textDocument/peekDefinition'] = function(_, _, result, _)
- if not (result and result[1]) then return end
- local loc = result[1]
- local bufnr = vim.uri_to_bufnr(loc.uri) or error("not found: "..tostring(loc.uri))
- local start = loc.range.start
- local finish = loc.range["end"]
- util.open_floating_peek_preview(bufnr, start, finish, { offset_x = 1 })
- local headbuf = util.open_floating_preview({"Peek:"}, nil, {
- offset_y = -(finish.line - start.line);
- width = finish.character - start.character + 2;
- })
- -- TODO(ashkan) change highlight group?
- api.nvim_buf_add_highlight(headbuf, -1, 'Keyword', 0, -1)
-end
-
M['textDocument/documentHighlight'] = function(_, _, result, _)
if not result then return end
local bufnr = api.nvim_get_current_buf()
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index ce5baf5b4b..49798a452f 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -6,6 +6,31 @@ local list_extend = vim.list_extend
local M = {}
+--- Diagnostics received from the server via `textDocument/publishDiagnostics`
+-- by buffer.
+--
+-- {<bufnr>: {diagnostics}}
+--
+-- This contains only entries for active buffers. Entries for detached buffers
+-- are discarded.
+--
+-- If you override the `textDocument/publishDiagnostic` callback,
+-- this will be empty unless you call `buf_diagnostics_save_positions`.
+--
+--
+-- Diagnostic is:
+--
+-- {
+-- range: Range
+-- message: string
+-- severity?: DiagnosticSeverity
+-- code?: number | string
+-- source?: string
+-- tags?: DiagnosticTag[]
+-- relatedInformation?: DiagnosticRelatedInformation[]
+-- }
+M.diagnostics_by_buf = {}
+
local split = vim.split
local function split_lines(value)
return split(value, '\n', true)
@@ -134,8 +159,7 @@ end
function M.apply_text_document_edit(text_document_edit)
local text_document = text_document_edit.textDocument
local bufnr = vim.uri_to_bufnr(text_document.uri)
- -- TODO(ashkan) check this is correct.
- if (M.buf_versions[bufnr] or 0) > text_document.version then
+ if M.buf_versions[bufnr] > text_document.version then
print("Buffer ", text_document.uri, " newer than edits.")
return
end
@@ -597,31 +621,6 @@ function M.open_floating_preview(contents, filetype, opts)
return floating_bufnr, floating_winnr
end
-local function validate_lsp_position(pos)
- validate { pos = {pos, 't'} }
- validate {
- line = {pos.line, 'n'};
- character = {pos.character, 'n'};
- }
- return true
-end
-
-function M.open_floating_peek_preview(bufnr, start, finish, opts)
- validate {
- bufnr = {bufnr, 'n'};
- start = {start, validate_lsp_position, 'valid start Position'};
- finish = {finish, validate_lsp_position, 'valid finish Position'};
- opts = { opts, 't', true };
- }
- local width = math.max(finish.character - start.character + 1, 1)
- local height = math.max(finish.line - start.line + 1, 1)
- local floating_winnr = api.nvim_open_win(bufnr, false, M.make_floating_popup_options(width, height, opts))
- api.nvim_win_set_cursor(floating_winnr, {start.line+1, start.character})
- api.nvim_command("autocmd CursorMoved * ++once lua pcall(vim.api.nvim_win_close, "..floating_winnr..", true)")
- return floating_winnr
-end
-
-
local function highlight_range(bufnr, ns, hiname, start, finish)
if start[1] == finish[1] then
-- TODO care about encoding here since this is in byte index?
@@ -636,8 +635,6 @@ local function highlight_range(bufnr, ns, hiname, start, finish)
end
do
- local all_buffer_diagnostics = {}
-
local diagnostic_ns = api.nvim_create_namespace("vim_lsp_diagnostics")
local reference_ns = api.nvim_create_namespace("vim_lsp_references")
local sign_ns = 'vim_lsp_signs'
@@ -693,13 +690,12 @@ do
-- if #marks == 0 then
-- return
-- end
- -- local buffer_diagnostics = all_buffer_diagnostics[bufnr]
local lines = {"Diagnostics:"}
local highlights = {{0, "Bold"}}
- local buffer_diagnostics = all_buffer_diagnostics[bufnr]
+ local buffer_diagnostics = M.diagnostics_by_buf[bufnr]
if not buffer_diagnostics then return end
- local line_diagnostics = buffer_diagnostics[line]
+ local line_diagnostics = M.diagnostics_group_by_line(buffer_diagnostics[line])
if not line_diagnostics then return end
for i, diagnostic in ipairs(line_diagnostics) do
@@ -727,6 +723,8 @@ do
return popup_bufnr, winnr
end
+ --- Saves the diagnostics (Diagnostic[]) into diagnostics_by_buf
+ --
function M.buf_diagnostics_save_positions(bufnr, diagnostics)
validate {
bufnr = {bufnr, 'n', true};
@@ -735,28 +733,15 @@ do
if not diagnostics then return end
bufnr = bufnr == 0 and api.nvim_get_current_buf() or bufnr
- if not all_buffer_diagnostics[bufnr] then
+ if not M.diagnostics_by_buf[bufnr] then
-- Clean up our data when the buffer unloads.
api.nvim_buf_attach(bufnr, false, {
on_detach = function(b)
- all_buffer_diagnostics[b] = nil
+ M.diagnostics_by_buf[b] = nil
end
})
end
- all_buffer_diagnostics[bufnr] = {}
- local buffer_diagnostics = all_buffer_diagnostics[bufnr]
-
- for _, diagnostic in ipairs(diagnostics) do
- local start = diagnostic.range.start
- -- local mark_id = api.nvim_buf_set_extmark(bufnr, diagnostic_ns, 0, start.line, 0, {})
- -- buffer_diagnostics[mark_id] = diagnostic
- local line_diagnostics = buffer_diagnostics[start.line]
- if not line_diagnostics then
- line_diagnostics = {}
- buffer_diagnostics[start.line] = line_diagnostics
- end
- table.insert(line_diagnostics, diagnostic)
- end
+ M.diagnostics_by_buf[bufnr] = diagnostics
end
function M.buf_diagnostics_underline(bufnr, diagnostics)
@@ -800,15 +785,26 @@ do
end
end
- function M.buf_diagnostics_virtual_text(bufnr, diagnostics)
- local buffer_line_diagnostics = all_buffer_diagnostics[bufnr]
- if not buffer_line_diagnostics then
- M.buf_diagnostics_save_positions(bufnr, diagnostics)
+ function M.diagnostics_group_by_line(diagnostics)
+ if not diagnostics then return end
+ local diagnostics_by_line = {}
+ for _, diagnostic in ipairs(diagnostics) do
+ local start = diagnostic.range.start
+ local line_diagnostics = diagnostics_by_line[start.line]
+ if not line_diagnostics then
+ line_diagnostics = {}
+ diagnostics_by_line[start.line] = line_diagnostics
+ end
+ table.insert(line_diagnostics, diagnostic)
end
- buffer_line_diagnostics = all_buffer_diagnostics[bufnr]
- if not buffer_line_diagnostics then
+ return diagnostics_by_line
+ end
+
+ function M.buf_diagnostics_virtual_text(bufnr, diagnostics)
+ if not diagnostics then
return
end
+ local buffer_line_diagnostics = M.diagnostics_group_by_line(diagnostics)
for line, line_diags in pairs(buffer_line_diagnostics) do
local virt_texts = {}
for i = 1, #line_diags - 1 do
@@ -822,12 +818,12 @@ do
end
function M.buf_diagnostics_count(kind)
local bufnr = vim.api.nvim_get_current_buf()
- local buffer_line_diagnostics = all_buffer_diagnostics[bufnr]
- if not buffer_line_diagnostics then return end
+ local diagnostics = M.diagnostics_by_buf[bufnr]
+ if not diagnostics then return end
local count = 0
- for _, line_diags in pairs(buffer_line_diagnostics) do
- for _, diag in ipairs(line_diags) do
- if protocol.DiagnosticSeverity[kind] == diag.severity then count = count + 1 end
+ for _, diagnostic in pairs(diagnostics) do
+ if protocol.DiagnosticSeverity[kind] == diagnostic.severity then
+ count = count + 1
end
end
return count
diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c
index ba6226ef9d..112de9fed8 100644
--- a/src/nvim/os/signal.c
+++ b/src/nvim/os/signal.c
@@ -50,22 +50,13 @@ void signal_init(void)
signal_watcher_init(&main_loop, &shup, NULL);
signal_watcher_init(&main_loop, &squit, NULL);
signal_watcher_init(&main_loop, &sterm, NULL);
-#ifdef SIGPIPE
- signal_watcher_start(&spipe, on_signal, SIGPIPE);
-#endif
- signal_watcher_start(&shup, on_signal, SIGHUP);
-#ifdef SIGQUIT
- signal_watcher_start(&squit, on_signal, SIGQUIT);
-#endif
- signal_watcher_start(&sterm, on_signal, SIGTERM);
#ifdef SIGPWR
signal_watcher_init(&main_loop, &spwr, NULL);
- signal_watcher_start(&spwr, on_signal, SIGPWR);
#endif
#ifdef SIGUSR1
signal_watcher_init(&main_loop, &susr1, NULL);
- signal_watcher_start(&susr1, on_signal, SIGUSR1);
#endif
+ signal_start();
}
void signal_teardown(void)
@@ -83,11 +74,33 @@ void signal_teardown(void)
#endif
}
+void signal_start(void)
+{
+#ifdef SIGPIPE
+ signal_watcher_start(&spipe, on_signal, SIGPIPE);
+#endif
+ signal_watcher_start(&shup, on_signal, SIGHUP);
+#ifdef SIGQUIT
+ signal_watcher_start(&squit, on_signal, SIGQUIT);
+#endif
+ signal_watcher_start(&sterm, on_signal, SIGTERM);
+#ifdef SIGPWR
+ signal_watcher_start(&spwr, on_signal, SIGPWR);
+#endif
+#ifdef SIGUSR1
+ signal_watcher_start(&susr1, on_signal, SIGUSR1);
+#endif
+}
+
void signal_stop(void)
{
+#ifdef SIGPIPE
signal_watcher_stop(&spipe);
+#endif
signal_watcher_stop(&shup);
+#ifdef SIGQUIT
signal_watcher_stop(&squit);
+#endif
signal_watcher_stop(&sterm);
#ifdef SIGPWR
signal_watcher_stop(&spwr);
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index ddb9188371..ef4dfb3caa 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -6400,7 +6400,7 @@ static int color_numbers_88[28] = { 0, 4, 2, 6,
75, 11, 78, 15, -1 };
// for xterm with 256 colors...
static int color_numbers_256[28] = { 0, 4, 2, 6,
- 1, 5, 130, 130,
+ 1, 5, 130, 3,
248, 248, 7, 7,
242, 242,
12, 81, 10, 121,
diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim
index aad21c002f..7fbf04311d 100644
--- a/src/nvim/testdir/test_messages.vim
+++ b/src/nvim/testdir/test_messages.vim
@@ -6,6 +6,9 @@ function Test_messages()
set nomore
" Avoid the "message maintainer" line.
let $LANG = ''
+ let $LC_ALL = ''
+ let $LC_MESSAGES = ''
+ let $LC_COLLATE = ''
let arr = map(range(10), '"hello" . v:val')
for s in arr
diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c
index 8bcdb681a2..1aa8df905e 100644
--- a/src/nvim/tui/tui.c
+++ b/src/nvim/tui/tui.c
@@ -31,6 +31,7 @@
#include "nvim/event/signal.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
+#include "nvim/os/signal.h"
#include "nvim/os/tty.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
@@ -1239,7 +1240,9 @@ static void suspend_event(void **argv)
tui_terminal_stop(ui);
data->cont_received = false;
stream_set_blocking(input_global_fd(), true); // normalize stream (#2598)
+ signal_stop();
kill(0, SIGTSTP);
+ signal_start();
while (!data->cont_received) {
// poll the event loop until SIGCONT is received
loop_poll_events(data->loop, -1);
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 9c14ced2ad..15a9713c7c 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -398,7 +398,7 @@ static const int included_patches[] = {
1523,
1522,
1521,
- // 1520,
+ 1520,
1519,
1518,
1517,
@@ -530,7 +530,7 @@ static const int included_patches[] = {
1391,
1390,
1389,
- // 1388,
+ 1388,
1387,
1386,
1385,
@@ -789,7 +789,7 @@ static const int included_patches[] = {
1132,
1131,
1130,
- // 1129,
+ 1129,
1128,
1127,
1126,
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index b21e344acd..a57443f909 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -845,4 +845,20 @@ describe('LSP', function()
eq({}, exec_lua([[return vim.lsp.util.text_document_completion_list_to_complete_items(...)]], {}, prefix))
end)
end)
+ describe('buf_diagnostics_save_positions', function()
+ it('stores the diagnostics in diagnostics_by_buf', function ()
+ local diagnostics = {
+ { range = {}; message = "diag1" },
+ { range = {}; message = "diag2" },
+ }
+ exec_lua([[
+ vim.lsp.util.buf_diagnostics_save_positions(...)]], 0, diagnostics)
+ eq(1, exec_lua [[ return #vim.lsp.util.diagnostics_by_buf ]])
+ eq(diagnostics, exec_lua [[
+ for _, diagnostics in pairs(vim.lsp.util.diagnostics_by_buf) do
+ return diagnostics
+ end
+ ]])
+ end)
+ end)
end)