mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-16 21:58:08 +00:00
indexer: disable warnings and skip processed function bodies
This commit is contained in:
parent
646aca5b7f
commit
d417597a11
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
|
|
||||||
#include <clang/AST/AST.h>
|
#include <clang/AST/AST.h>
|
||||||
#include <clang/Frontend/FrontendAction.h>
|
#include <clang/Frontend/FrontendAction.h>
|
||||||
|
#include <clang/Frontend/MultiplexConsumer.h>
|
||||||
#include <clang/Index/IndexDataConsumer.h>
|
#include <clang/Index/IndexDataConsumer.h>
|
||||||
#include <clang/Index/IndexingAction.h>
|
#include <clang/Index/IndexingAction.h>
|
||||||
#include <clang/Index/USRGeneration.h>
|
#include <clang/Index/USRGeneration.h>
|
||||||
@ -1159,10 +1160,28 @@ public:
|
|||||||
IndexFrontendAction(IndexParam ¶m) : param(param) {}
|
IndexFrontendAction(IndexParam ¶m) : param(param) {}
|
||||||
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
|
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
|
||||||
StringRef InFile) override {
|
StringRef InFile) override {
|
||||||
|
class SkipProcessed : public ASTConsumer {
|
||||||
|
IndexParam ¶m;
|
||||||
|
const ASTContext *ctx = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SkipProcessed(IndexParam ¶m) : param(param) {}
|
||||||
|
void Initialize(ASTContext &ctx) override { this->ctx = &ctx; }
|
||||||
|
bool shouldSkipFunctionBody(Decl *d) override {
|
||||||
|
const SourceManager &sm = ctx->getSourceManager();
|
||||||
|
FileID fid = sm.getFileID(sm.getExpansionLoc(d->getLocation()));
|
||||||
|
return !(g_config->index.multiVersion && param.useMultiVersion(fid)) &&
|
||||||
|
!param.consumeFile(fid);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Preprocessor &PP = CI.getPreprocessor();
|
Preprocessor &PP = CI.getPreprocessor();
|
||||||
PP.addPPCallbacks(
|
PP.addPPCallbacks(
|
||||||
std::make_unique<IndexPPCallbacks>(PP.getSourceManager(), param));
|
std::make_unique<IndexPPCallbacks>(PP.getSourceManager(), param));
|
||||||
return std::make_unique<ASTConsumer>();
|
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
|
||||||
|
Consumers.push_back(std::make_unique<SkipProcessed>(param));
|
||||||
|
Consumers.push_back(std::make_unique<ASTConsumer>());
|
||||||
|
return std::make_unique<MultiplexConsumer>(std::move(Consumers));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
@ -1229,6 +1248,10 @@ Index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
|
|||||||
if (!CI)
|
if (!CI)
|
||||||
return {};
|
return {};
|
||||||
ok = false;
|
ok = false;
|
||||||
|
// Disable computing warnings which will be discarded anyway.
|
||||||
|
CI->getDiagnosticOpts().IgnoreWarnings = true;
|
||||||
|
// Enable IndexFrontendAction::shouldSkipFunctionBody.
|
||||||
|
CI->getFrontendOpts().SkipFunctionBodies = true;
|
||||||
// -fparse-all-comments enables documentation in the indexer and in
|
// -fparse-all-comments enables documentation in the indexer and in
|
||||||
// code completion.
|
// code completion.
|
||||||
CI->getLangOpts()->CommentOpts.ParseAllComments = g_config->index.comments > 1;
|
CI->getLangOpts()->CommentOpts.ParseAllComments = g_config->index.comments > 1;
|
||||||
@ -1245,6 +1268,7 @@ Index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
|
|||||||
auto Clang = std::make_unique<CompilerInstance>(PCH);
|
auto Clang = std::make_unique<CompilerInstance>(PCH);
|
||||||
Clang->setInvocation(std::move(CI));
|
Clang->setInvocation(std::move(CI));
|
||||||
Clang->createDiagnostics(&DC, false);
|
Clang->createDiagnostics(&DC, false);
|
||||||
|
Clang->getDiagnostics().setIgnoreAllWarnings(true);
|
||||||
Clang->setTarget(TargetInfo::CreateTargetInfo(
|
Clang->setTarget(TargetInfo::CreateTargetInfo(
|
||||||
Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
|
Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
|
||||||
if (!Clang->hasTarget())
|
if (!Clang->hasTarget())
|
||||||
|
Loading…
Reference in New Issue
Block a user