From 5d06b6fdddd29a4cdb1bf8ad1a8c4b72447f4f93 Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 5 Jan 2021 10:54:04 +0100 Subject: [PATCH] Language client: slightly improved codeAction message where range is set to diagnostic range if only one diagnostic exists --- src/source_language_protocol.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/source_language_protocol.cpp b/src/source_language_protocol.cpp index 269abaa..0254999 100644 --- a/src/source_language_protocol.cpp +++ b/src/source_language_protocol.cpp @@ -996,20 +996,23 @@ void Source::LanguageProtocolView::update_diagnostics_async(std::vectorbegin(); - auto end = get_buffer()->end(); - auto range = "{\"start\":{\"line\": " + std::to_string(start.get_line()) + ",\"character\":" + std::to_string(start.get_line_offset()) + R"(},"end":{"line":)" + std::to_string(end.get_line()) + ",\"character\":" + std::to_string(end.get_line_offset()) + "}}"; + if(diagnostics.size() != 1) { // Use diagnostic range if only one diagnostic, otherwise use whole buffer + auto start = get_buffer()->begin(); + auto end = get_buffer()->end(); + range = "{\"start\":{\"line\": " + std::to_string(start.get_line()) + ",\"character\":" + std::to_string(start.get_line_offset()) + R"(},"end":{"line":)" + std::to_string(end.get_line()) + ",\"character\":" + std::to_string(end.get_line_offset()) + "}}"; + } auto request = (R"("textDocument":{"uri":")" + uri + "\"},\"range\":" + range + ",\"context\":{\"diagnostics\":[" + diagnostics_string + "],\"only\":[\"quickfix\"]}"); thread_pool.push([this, diagnostics = std::move(diagnostics), request = std::move(request), last_count]() mutable {