Fix spurious "Failed to index" errors

This commit is contained in:
Fangrui Song 2018-09-22 18:00:50 -07:00
parent 28d33324b1
commit 6ea399559d
4 changed files with 12 additions and 7 deletions

View File

@ -1235,15 +1235,18 @@ std::vector<std::unique_ptr<IndexFile>>
Index(CompletionManager *completion, WorkingFiles *wfiles, VFS *vfs,
const std::string &opt_wdir, const std::string &file,
const std::vector<const char *> &args,
const std::vector<std::pair<std::string, std::string>> &remapped) {
const std::vector<std::pair<std::string, std::string>> &remapped, bool &ok) {
ok = true;
if (!g_config->index.enabled)
return {};
auto PCH = std::make_shared<PCHContainerOperations>();
llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem();
std::shared_ptr<CompilerInvocation> 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<FrontendAction> Action = createIndexingAction(
DataConsumer, IndexOpts, std::make_unique<IndexFrontendAction>(param));
bool ok = false;
{
llvm::CrashRecoveryContext CRC;
auto parse = [&]() {

View File

@ -304,5 +304,6 @@ std::vector<std::unique_ptr<IndexFile>>
Index(CompletionManager *complete, WorkingFiles *wfiles, VFS *vfs,
const std::string &opt_wdir, const std::string &file,
const std::vector<const char *> &args,
const std::vector<std::pair<std::string, std::string>> &remapped);
}
const std::vector<std::pair<std::string, std::string>> &remapped,
bool &ok);
} // namespace ccls::idx

View File

@ -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;

View File

@ -317,7 +317,8 @@ bool RunIndexTests(const std::string &filter_path, bool enable_update) {
std::vector<const char *> 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;