diff --git a/src/command_line.cc b/src/command_line.cc index 038c2ecc..ea7c9908 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -53,7 +53,7 @@ std::vector kEmptyArgs; std::string FormatMicroseconds(long long microseconds) { long long milliseconds = microseconds / 1000; long long remaining = microseconds - milliseconds; - + // Only show two digits after the dot. while (remaining >= 100) remaining /= 10; @@ -1086,19 +1086,17 @@ void ParseFile(IndexerConfig* config, // Note: we are reusing the parent perf. perf.index_load_cached = time.ElapsedMicrosecondsAndReset(); - // Publish diagnostics. We guard behind a |report_diagnostics| flag to - // avoid heavy lock contention in working_files->GetFileByFilename(). - if (is_interactive) { - WorkingFile* file = working_files->GetFileByFilename(new_index->path); - if ((file && file->has_diagnostics) || !new_index->diagnostics.empty()) { - if (file) - file->has_diagnostics = !new_index->diagnostics.empty(); - - Out_TextDocumentPublishDiagnostics diag; - diag.params.uri = lsDocumentUri::FromPath(new_index->path); - diag.params.diagnostics = new_index->diagnostics; - IpcManager::instance()->SendOutMessageToClient(IpcId::TextDocumentPublishDiagnostics, diag); - } + // Publish diagnostics. We should only need to publish empty diagnostics if + // |is_interactive| is true, as we may have previously published diagnostic + // for that file. If the user has diagnostics on files they are not + // editing, then they can either edit the file, in which case + // |is_interactive| will be true, or they can change the flags cquery runs + // with, in which case vscode will get restarted. + if (is_interactive || !new_index->diagnostics.empty()) { + Out_TextDocumentPublishDiagnostics diag; + diag.params.uri = lsDocumentUri::FromPath(new_index->path); + diag.params.diagnostics = new_index->diagnostics; + IpcManager::instance()->SendOutMessageToClient(IpcId::TextDocumentPublishDiagnostics, diag); } @@ -2171,7 +2169,7 @@ bool QueryDbMainLoop( Index_OnIdMapped response(request->indexed_content, request->perf, request->is_interactive); Timer time; - + if (request->previous) { response.previous_id_map = MakeUnique(db, request->previous->id_cache); response.previous_index = std::move(request->previous); @@ -2423,7 +2421,6 @@ void LanguageServerStdinLoop(IndexerConfig* config, std::unordered_map* request_times, MultiQueueWaiter* waiter) { diff --git a/src/working_files.h b/src/working_files.h index f2675b63..0b755042 100644 --- a/src/working_files.h +++ b/src/working_files.h @@ -27,8 +27,6 @@ struct WorkingFile { // This map goes from buffer-line -> indices+1 in all_buffer_lines. // Note: The items in the value entry are 1-based liness. std::unordered_map> all_buffer_lines_lookup; - // True iff this file currently has reported diagnostics. - bool has_diagnostics = false; WorkingFile(const std::string& filename, const std::string& buffer_content);