From f64d510b60e38c89ef3325346cce201d4b4da93b Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 26 May 2020 12:47:56 +0200 Subject: [PATCH] Language client: added workaround for servers that does not report quickfix diagnostics --- src/source_language_protocol.cc | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/source_language_protocol.cc b/src/source_language_protocol.cc index 75eb832..deaeb36 100644 --- a/src/source_language_protocol.cc +++ b/src/source_language_protocol.cc @@ -966,16 +966,30 @@ void Source::LanguageProtocolView::update_diagnostics_async(std::vectorsecond.get("kind") == "quickfix") { auto title = it->second.get("title"); std::vector quickfix_diagnostics; - auto diagnostics_pt = it->second.get_child("diagnostics"); - for(auto it = diagnostics_pt.begin(); it != diagnostics_pt.end(); ++it) - quickfix_diagnostics.emplace_back(it->second); + auto diagnostics_pt = it->second.get_child_optional("diagnostics"); + if(diagnostics_pt) { + for(auto it = diagnostics_pt->begin(); it != diagnostics_pt->end(); ++it) + quickfix_diagnostics.emplace_back(it->second); + } auto changes = it->second.get_child("edit.changes"); for(auto file_it = changes.begin(); file_it != changes.end(); ++file_it) { for(auto edit_it = file_it->second.begin(); edit_it != file_it->second.end(); ++edit_it) { LanguageProtocol::TextEdit edit(edit_it->second); - for(auto &diagnostic : diagnostics) { - for(auto &quickfix_diagnostic : quickfix_diagnostics) { - if(diagnostic.message == quickfix_diagnostic.message && diagnostic.range == quickfix_diagnostic.range) { + if(!quickfix_diagnostics.empty()) { + for(auto &diagnostic : diagnostics) { + for(auto &quickfix_diagnostic : quickfix_diagnostics) { + if(diagnostic.message == quickfix_diagnostic.message && diagnostic.range == quickfix_diagnostic.range) { + auto pair = diagnostic.quickfixes.emplace(title, std::vector{}); + pair.first->second.emplace_back(edit.new_text, filesystem::get_path_from_uri(file_it->first).string(), std::make_pair(Offset(edit.range.start.line, edit.range.start.character), + Offset(edit.range.end.line, edit.range.end.character))); + break; + } + } + } + } + else { // Workaround for language server that does not report quickfix diagnostics + for(auto &diagnostic : diagnostics) { + if(edit.range.start.line == diagnostic.range.start.line) { auto pair = diagnostic.quickfixes.emplace(title, std::vector{}); pair.first->second.emplace_back(edit.new_text, filesystem::get_path_from_uri(file_it->first).string(), std::make_pair(Offset(edit.range.start.line, edit.range.start.character), Offset(edit.range.end.line, edit.range.end.character)));