Don't bother saving if we reported diagnostics.

Always report if file has diagnostics, always report if file is interactive.
This commit is contained in:
Jacob Dufault 2017-05-20 01:07:54 -07:00
parent 29845cc1e3
commit 9d3187a06c
2 changed files with 13 additions and 18 deletions

View File

@ -53,7 +53,7 @@ std::vector<std::string> kEmptyArgs;
std::string FormatMicroseconds(long long microseconds) { std::string FormatMicroseconds(long long microseconds) {
long long milliseconds = microseconds / 1000; long long milliseconds = microseconds / 1000;
long long remaining = microseconds - milliseconds; long long remaining = microseconds - milliseconds;
// Only show two digits after the dot. // Only show two digits after the dot.
while (remaining >= 100) while (remaining >= 100)
remaining /= 10; remaining /= 10;
@ -1086,19 +1086,17 @@ void ParseFile(IndexerConfig* config,
// Note: we are reusing the parent perf. // Note: we are reusing the parent perf.
perf.index_load_cached = time.ElapsedMicrosecondsAndReset(); perf.index_load_cached = time.ElapsedMicrosecondsAndReset();
// Publish diagnostics. We guard behind a |report_diagnostics| flag to // Publish diagnostics. We should only need to publish empty diagnostics if
// avoid heavy lock contention in working_files->GetFileByFilename(). // |is_interactive| is true, as we may have previously published diagnostic
if (is_interactive) { // for that file. If the user has diagnostics on files they are not
WorkingFile* file = working_files->GetFileByFilename(new_index->path); // editing, then they can either edit the file, in which case
if ((file && file->has_diagnostics) || !new_index->diagnostics.empty()) { // |is_interactive| will be true, or they can change the flags cquery runs
if (file) // with, in which case vscode will get restarted.
file->has_diagnostics = !new_index->diagnostics.empty(); if (is_interactive || !new_index->diagnostics.empty()) {
Out_TextDocumentPublishDiagnostics diag;
Out_TextDocumentPublishDiagnostics diag; diag.params.uri = lsDocumentUri::FromPath(new_index->path);
diag.params.uri = lsDocumentUri::FromPath(new_index->path); diag.params.diagnostics = new_index->diagnostics;
diag.params.diagnostics = new_index->diagnostics; IpcManager::instance()->SendOutMessageToClient(IpcId::TextDocumentPublishDiagnostics, diag);
IpcManager::instance()->SendOutMessageToClient(IpcId::TextDocumentPublishDiagnostics, diag);
}
} }
@ -2171,7 +2169,7 @@ bool QueryDbMainLoop(
Index_OnIdMapped response(request->indexed_content, request->perf, request->is_interactive); Index_OnIdMapped response(request->indexed_content, request->perf, request->is_interactive);
Timer time; Timer time;
if (request->previous) { if (request->previous) {
response.previous_id_map = MakeUnique<IdMap>(db, request->previous->id_cache); response.previous_id_map = MakeUnique<IdMap>(db, request->previous->id_cache);
response.previous_index = std::move(request->previous); response.previous_index = std::move(request->previous);
@ -2423,7 +2421,6 @@ void LanguageServerStdinLoop(IndexerConfig* config, std::unordered_map<IpcId, Ti
void StdoutMain(std::unordered_map<IpcId, Timer>* request_times, MultiQueueWaiter* waiter) { void StdoutMain(std::unordered_map<IpcId, Timer>* request_times, MultiQueueWaiter* waiter) {

View File

@ -27,8 +27,6 @@ struct WorkingFile {
// This map goes from buffer-line -> indices+1 in all_buffer_lines. // This map goes from buffer-line -> indices+1 in all_buffer_lines.
// Note: The items in the value entry are 1-based liness. // Note: The items in the value entry are 1-based liness.
std::unordered_map<std::string, std::vector<int>> all_buffer_lines_lookup; std::unordered_map<std::string, std::vector<int>> 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); WorkingFile(const std::string& filename, const std::string& buffer_content);