From 6ea399559deaad8beef05a34af8653f8cda8a85d Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 22 Sep 2018 18:00:50 -0700 Subject: [PATCH] Fix spurious "Failed to index" errors --- src/indexer.cc | 6 ++++-- src/indexer.h | 5 +++-- src/pipeline.cc | 5 +++-- src/test.cc | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/indexer.cc b/src/indexer.cc index 080511b7..45af8e7e 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1235,15 +1235,18 @@ std::vector> Index(CompletionManager *completion, WorkingFiles *wfiles, VFS *vfs, const std::string &opt_wdir, const std::string &file, const std::vector &args, - const std::vector> &remapped) { + const std::vector> &remapped, bool &ok) { + ok = true; if (!g_config->index.enabled) return {}; auto PCH = std::make_shared(); llvm::IntrusiveRefCntPtr FS = vfs::getRealFileSystem(); std::shared_ptr CI = BuildCompilerInvocation(args, FS); + // e.g. .s if (!CI) return {}; + ok = false; // -fparse-all-comments enables documentation in the indexer and in // code completion. if (g_config->index.comments > 1) @@ -1313,7 +1316,6 @@ Index(CompletionManager *completion, WorkingFiles *wfiles, VFS *vfs, std::unique_ptr Action = createIndexingAction( DataConsumer, IndexOpts, std::make_unique(param)); - bool ok = false; { llvm::CrashRecoveryContext CRC; auto parse = [&]() { diff --git a/src/indexer.h b/src/indexer.h index 2dbe6d6f..553ee640 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -304,5 +304,6 @@ std::vector> Index(CompletionManager *complete, WorkingFiles *wfiles, VFS *vfs, const std::string &opt_wdir, const std::string &file, const std::vector &args, - const std::vector> &remapped); -} + const std::vector> &remapped, + bool &ok); +} // namespace ccls::idx diff --git a/src/pipeline.cc b/src/pipeline.cc index 631ecd7b..9864a09b 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -278,10 +278,11 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles, if (content.size()) remapped.emplace_back(path_to_index, content); } + bool ok; auto indexes = idx::Index(completion, wfiles, vfs, entry.directory, - path_to_index, entry.args, remapped); + path_to_index, entry.args, remapped, ok); - if (indexes.empty()) { + if (!ok) { if (g_config->index.enabled && request.id.Valid()) { Out_Error out; out.id = request.id; diff --git a/src/test.cc b/src/test.cc index 69cf8536..57af162c 100644 --- a/src/test.cc +++ b/src/test.cc @@ -317,7 +317,8 @@ bool RunIndexTests(const std::string &filter_path, bool enable_update) { std::vector cargs; for (auto &arg : flags) cargs.push_back(arg.c_str()); - auto dbs = ccls::idx::Index(&completion, &wfiles, &vfs, "", path, cargs, {}); + bool ok; + auto dbs = ccls::idx::Index(&completion, &wfiles, &vfs, "", path, cargs, {}, ok); for (const auto &entry : all_expected_output) { const std::string &expected_path = entry.first;