Do not index standard library headers

This commit is contained in:
Jacob Dufault 2017-03-05 22:47:37 -08:00
parent 49c6f7787a
commit 36f69e61a9
3 changed files with 37 additions and 4 deletions

View File

@ -604,7 +604,7 @@ void LanguageServerMain(std::string process_name) {
int mai232n(int argc, char** argv) { int main(int argc, char** argv) {
// We need to write to stdout in binary mode because in Windows, writing // We need to write to stdout in binary mode because in Windows, writing
// \n will implicitly write \r\n. Language server API will ignore a // \n will implicitly write \r\n. Language server API will ignore a
// \r\r\n split request. // \r\r\n split request.

View File

@ -1,5 +1,7 @@
#include "indexer.h" #include "indexer.h"
#include <chrono>
#include "serializer.h" #include "serializer.h"
IndexedFile::IndexedFile(const std::string& path) IndexedFile::IndexedFile(const std::string& path)
@ -555,9 +557,10 @@ optional<TypeId> AddDeclUsages(IndexedFile* db, clang::Cursor decl_cursor,
return param.initial_type; return param.initial_type;
} }
void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
bool is_system_def = clang_Location_isInSystemHeader(clang_getCursorLocation(decl->cursor)); bool is_system_def = clang_Location_isInSystemHeader(clang_getCursorLocation(decl->cursor));
if (is_system_def)
return;
IndexParam* param = static_cast<IndexParam*>(client_data); IndexParam* param = static_cast<IndexParam*>(client_data);
IndexedFile* db = param->db; IndexedFile* db = param->db;
@ -861,6 +864,10 @@ bool IsFunction(CXCursorKind kind) {
} }
void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
if (clang_Location_isInSystemHeader(clang_getCursorLocation(ref->cursor)) ||
clang_Location_isInSystemHeader(clang_getCursorLocation(ref->referencedEntity->cursor)))
return;
IndexParam* param = static_cast<IndexParam*>(client_data); IndexParam* param = static_cast<IndexParam*>(client_data);
IndexedFile* db = param->db; IndexedFile* db = param->db;
clang::Cursor cursor(ref->cursor); clang::Cursor cursor(ref->cursor);
@ -1007,6 +1014,28 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re
} }
void emptyIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {}
void emptyIndexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {}
struct Timer {
using Clock = std::chrono::high_resolution_clock;
std::chrono::time_point<Clock> start_;
Timer() {
Reset();
}
void Reset() {
start_ = Clock::now();
}
void PrintElapsed() {
std::chrono::time_point<Clock> end = Clock::now();
std::cerr << "Indexing took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start_).count() << "ms" << std::endl;
}
};
IndexedFile Parse(std::string filename, std::vector<std::string> args, bool dump_ast) { IndexedFile Parse(std::string filename, std::vector<std::string> args, bool dump_ast) {
clang::Index index(0 /*excludeDeclarationsFromPCH*/, 0 /*displayDiagnostics*/); clang::Index index(0 /*excludeDeclarationsFromPCH*/, 0 /*displayDiagnostics*/);
clang::TranslationUnit tu(index, filename, args); clang::TranslationUnit tu(index, filename, args);
@ -1018,6 +1047,7 @@ IndexedFile Parse(std::string filename, std::vector<std::string> args, bool dump
IndexerCallbacks callbacks[] = { IndexerCallbacks callbacks[] = {
{ &abortQuery, &diagnostic, &enteredMainFile, &ppIncludedFile, &importedASTFile, &startedTranslationUnit, &indexDeclaration, &indexEntityReference } { &abortQuery, &diagnostic, &enteredMainFile, &ppIncludedFile, &importedASTFile, &startedTranslationUnit, &indexDeclaration, &indexEntityReference }
//{ &abortQuery, &diagnostic, &enteredMainFile, &ppIncludedFile, &importedASTFile, &startedTranslationUnit, &emptyIndexDeclaration, &emptyIndexEntityReference }
/* /*
callbacks.abortQuery = &abortQuery; callbacks.abortQuery = &abortQuery;
callbacks.diagnostic = &diagnostic; callbacks.diagnostic = &diagnostic;
@ -1033,8 +1063,11 @@ IndexedFile Parse(std::string filename, std::vector<std::string> args, bool dump
IndexedFile db(filename); IndexedFile db(filename);
NamespaceHelper ns; NamespaceHelper ns;
IndexParam param(&db, &ns); IndexParam param(&db, &ns);
Timer time;
clang_indexTranslationUnit(index_action, &param, callbacks, sizeof(callbacks), clang_indexTranslationUnit(index_action, &param, callbacks, sizeof(callbacks),
CXIndexOpt_IndexFunctionLocalSymbols | CXIndexOpt_SkipParsedBodiesInSession, tu.cx_tu); CXIndexOpt_IndexFunctionLocalSymbols | CXIndexOpt_SkipParsedBodiesInSession, tu.cx_tu);
time.PrintElapsed();
clang_IndexAction_dispose(index_action); clang_IndexAction_dispose(index_action);

View File

@ -82,7 +82,7 @@ void VerifySerializeToFrom(IndexedFile* file) {
} }
} }
int main(int argc, char** argv) { int main23(int argc, char** argv) {
// TODO: Assert that we need to be on clang >= 3.9.1 // TODO: Assert that we need to be on clang >= 3.9.1
/* /*
@ -98,7 +98,7 @@ int main(int argc, char** argv) {
//if (path != "tests/constructors/invalid_reference.cc") continue; //if (path != "tests/constructors/invalid_reference.cc") continue;
//if (path == "tests/inheritance/class_inherit_templated_parent.cc") continue; //if (path == "tests/inheritance/class_inherit_templated_parent.cc") continue;
//if (path != "tests/namespaces/namespace_reference.cc") continue; //if (path != "tests/namespaces/namespace_reference.cc") continue;
if (path == "tests/stl.cc") continue; //if (path != "tests/stl.cc") continue;
//if (path != "tests/templates/template_class_type_usage_folded_into_one.cc") continue; //if (path != "tests/templates/template_class_type_usage_folded_into_one.cc") continue;
//path = "C:/Users/jacob/Desktop/superindex/indexer/" + path; //path = "C:/Users/jacob/Desktop/superindex/indexer/" + path;