From 880fb0d146ab752206c5261a58b568cc75d74637 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 22 Mar 2021 10:21:56 -0400 Subject: lsp: Force re-display of diagnostics when opening a file --- runtime/lua/vim/lsp.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index f0845bfc80..4c453df3f6 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -293,6 +293,19 @@ local function text_document_did_open_handler(bufnr, client) } client.notify('textDocument/didOpen', params) util.buf_versions[bufnr] = params.textDocument.version + + -- Next chance we get, we should re-do the diagnostics + vim.schedule(function() + vim.lsp.handlers["textDocument/publishDiagnostics"]( + nil, + "textDocument/publishDiagnostics", + { + diagnostics = vim.lsp.diagnostic.get(bufnr, client.id), + uri = vim.uri_from_bufnr(bufnr), + }, + client.id + ) + end) end -- FIXME: DOC: Shouldn't need to use a dummy function -- cgit From 875979ec3f528b01c8acf2cc5eec6c7854a181b9 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 22 Mar 2021 10:22:23 -0400 Subject: lsp: Unopened buffers return 0 for line count, which leads to broken positions --- runtime/lua/vim/lsp/diagnostic.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index a1f24706c0..4e82c46fef 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -270,8 +270,10 @@ local function set_diagnostic_cache(diagnostics, bufnr, client_id) diagnostic.severity = DiagnosticSeverity.Error end -- Account for servers that place diagnostics on terminating newline - local start = diagnostic.range.start - start.line = math.min(start.line, buf_line_count - 1) + if buf_line_count > 0 then + local start = diagnostic.range.start + start.line = math.min(start.line, buf_line_count - 1) + end end diagnostic_cache[bufnr][client_id] = diagnostics -- cgit