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

@ -1086,20 +1086,18 @@ 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();
// 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);
}
}
// Any any existing dependencies to |new_index| that were there before,
@ -2423,7 +2421,6 @@ void LanguageServerStdinLoop(IndexerConfig* config, std::unordered_map<IpcId, Ti
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.
// Note: The items in the value entry are 1-based liness.
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);