From c633ce437bfb939c5b15be884299bebd8f192c29 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 12 Sep 2018 11:12:00 -0700 Subject: [PATCH] pipeline improvement for files not having a project entry (e.g. .h) --- src/messages/textDocument_didChange.cc | 6 ++-- src/messages/textDocument_didOpen.cc | 10 +++--- src/messages/textDocument_didSave.cc | 4 +-- src/pipeline.cc | 44 +++++++++++++++----------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/messages/textDocument_didChange.cc b/src/messages/textDocument_didChange.cc index 2e0a494e..53978df8 100644 --- a/src/messages/textDocument_didChange.cc +++ b/src/messages/textDocument_didChange.cc @@ -27,10 +27,8 @@ struct Handler_TextDocumentDidChange const auto ¶ms = request->params; std::string path = params.textDocument.uri.GetPath(); working_files->OnChange(params); - if (g_config->index.onChange) { - Project::Entry entry = project->FindCompilationEntryForFile(path); - pipeline::Index(entry.filename, entry.args, IndexMode::OnChange); - } + if (g_config->index.onChange) + pipeline::Index(path, {}, IndexMode::OnChange); clang_complete->NotifyView(path); if (g_config->diagnostics.onChange) clang_complete->DiagnosticsUpdate( diff --git a/src/messages/textDocument_didOpen.cc b/src/messages/textDocument_didOpen.cc index f68ba84d..721b2371 100644 --- a/src/messages/textDocument_didOpen.cc +++ b/src/messages/textDocument_didOpen.cc @@ -57,12 +57,10 @@ struct Handler_TextDocumentDidOpen // Submit new index request if it is not a header file. if (SourceFileLanguage(path) != LanguageId::Unknown) { - Project::Entry entry = project->FindCompilationEntryForFile(path); - pipeline::Index(entry.filename, - params.args.size() ? params.args : entry.args, - IndexMode::Normal); - - clang_complete->FlushSession(entry.filename); + pipeline::Index( + path, params.args.size() ? params.args : std::vector{}, + IndexMode::Normal); + clang_complete->FlushSession(path); } clang_complete->NotifyView(path); diff --git a/src/messages/textDocument_didSave.cc b/src/messages/textDocument_didSave.cc index 25c8bc81..d4d89de3 100644 --- a/src/messages/textDocument_didSave.cc +++ b/src/messages/textDocument_didSave.cc @@ -33,9 +33,7 @@ struct Handler_TextDocumentDidSave void Run(In_TextDocumentDidSave *request) override { const auto ¶ms = request->params; std::string path = params.textDocument.uri.GetPath(); - - Project::Entry entry = project->FindCompilationEntryForFile(path); - pipeline::Index(entry.filename, entry.args, IndexMode::Normal); + pipeline::Index(path, {}, IndexMode::Normal); clang_complete->NotifySave(path); } }; diff --git a/src/pipeline.cc b/src/pipeline.cc index 49259d63..f8726247 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -178,25 +178,23 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles, return false; } - Project::Entry entry; - { - std::lock_guard lock(project->mutex_); - auto it = project->path_to_entry_index.find(request.path); - if (it != project->path_to_entry_index.end()) - entry = project->entries[it->second]; - else { - entry.filename = request.path; - entry.args = request.args; - } - } + Project::Entry entry = project->FindCompilationEntryForFile(request.path); + if (request.args.size()) + entry.args = request.args; std::string path_to_index = entry.filename; std::unique_ptr prev; - // Try to load the file from cache. std::optional write_time = LastWriteTime(path_to_index); if (!write_time) return true; int reparse = vfs->Stamp(path_to_index, *write_time); + if (request.path != path_to_index) { + std::optional mtime1 = LastWriteTime(request.path); + if (!mtime1) + return true; + if (vfs->Stamp(request.path, *mtime1)) + reparse = 2; + } if (g_config->index.onChange) reparse = 2; if (!vfs->Mark(path_to_index, g_thread_id, 1) && !reparse) @@ -245,8 +243,14 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles, IndexUpdate update = IndexUpdate::CreateDelta(nullptr, prev.get()); on_indexed->PushBack(std::move(update), request.mode != IndexMode::NonInteractive); - std::lock_guard lock(vfs->mutex); - vfs->state[path].loaded = true; + { + std::lock_guard lock(vfs->mutex); + vfs->state[path].loaded = true; + } + if (entry.id >= 0) { + std::lock_guard lock(project->mutex_); + project->path_to_entry_index[path] = entry.id; + } } } return true; @@ -256,9 +260,9 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles, std::vector> remapped; if (g_config->index.onChange) { - std::string content = wfiles->GetContent(request.path); + std::string content = wfiles->GetContent(path_to_index); if (content.size()) - remapped.emplace_back(request.path, content); + remapped.emplace_back(path_to_index, content); } auto indexes = idx::Index(completion, wfiles, vfs, entry.directory, path_to_index, entry.args, remapped); @@ -277,7 +281,7 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles, for (std::unique_ptr &curr : indexes) { std::string path = curr->path; - bool do_update = path == path_to_index, loaded; + bool do_update = path == path_to_index || path == request.path, loaded; { std::lock_guard lock(vfs->mutex); VFS::State &st = vfs->state[path]; @@ -288,11 +292,13 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles, loaded = st.loaded; st.loaded = true; } - if (!do_update) - continue; if (std::string reason; !matcher.IsMatch(path, &reason)) { LOG_IF_S(INFO, loud) << "skip emitting and storing index of " << path << " for " << reason; + do_update = false; + } + if (!do_update) { + vfs->Reset(path); continue; }