Fix spurious "Failed to index" errors

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

View File

@ -1220,15 +1220,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.
CI->getLangOpts()->CommentOpts.ParseAllComments =
@ -1288,7 +1291,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

@ -292,5 +292,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

@ -266,10 +266,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

@ -305,7 +305,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;