Skip to content

Commit

Permalink
Indexer now has access to |config|
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdufault committed Feb 1, 2018
1 parent e259bb9 commit c98d53c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
13 changes: 8 additions & 5 deletions src/command_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,14 @@ void RunQueryDbThread(const std::string& bin_name,

ClangCompleteManager clang_complete(
config, &project, &working_files,
std::bind(&EmitDiagnostics, &working_files, std::placeholders::_1,
std::placeholders::_2),
std::bind(&IndexWithTuFromCodeCompletion, &file_consumer_shared,
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, std::placeholders::_4));
[&](std::string path, std::vector<lsDiagnostic> diagnostics) {
EmitDiagnostics(&working_files, path, diagnostics);
},
[&](ClangTranslationUnit* tu, const std::vector<CXUnsavedFile>& unsaved,
const std::string& path, const std::vector<std::string>& args) {
IndexWithTuFromCodeCompletion(config, &file_consumer_shared, tu,
unsaved, path, args);
});

IncludeComplete include_complete(config, &project);
auto global_code_complete_cache = MakeUnique<CodeCompleteCache>();
Expand Down
5 changes: 3 additions & 2 deletions src/import_pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ ImportPipelineStatus::ImportPipelineStatus()
// real-time indexing.
// TODO: add option to disable this.
void IndexWithTuFromCodeCompletion(
Config* config,
FileConsumerSharedState* file_consumer_shared,
ClangTranslationUnit* tu,
const std::vector<CXUnsavedFile>& file_contents,
Expand All @@ -530,8 +531,8 @@ void IndexWithTuFromCodeCompletion(

PerformanceImportFile perf;
ClangIndex index;
auto indexes = ParseWithTu(file_consumer_shared, &perf, tu, &index, path,
args, file_contents);
auto indexes = ParseWithTu(config, file_consumer_shared, &perf, tu, &index,
path, args, file_contents);
if (!indexes)
return;

Expand Down
1 change: 1 addition & 0 deletions src/import_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct ImportPipelineStatus {
};

void IndexWithTuFromCodeCompletion(
Config* config,
FileConsumerSharedState* file_consumer_shared,
ClangTranslationUnit* tu,
const std::vector<CXUnsavedFile>& file_contents,
Expand Down
16 changes: 9 additions & 7 deletions src/indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

// Defined in command_line.cc
extern bool g_debug;
extern bool g_index_make_unique;

namespace {

Expand Down Expand Up @@ -237,6 +236,8 @@ struct ConstructorCache {
};

struct IndexParam {
Config* config = nullptr;

std::unordered_set<CXFile> seen_cx_files;
std::vector<std::string> seen_files;
FileContentsMap file_contents;
Expand All @@ -256,8 +257,8 @@ struct IndexParam {
NamespaceHelper ns;
ConstructorCache ctors;

IndexParam(ClangTranslationUnit* tu, FileConsumer* file_consumer)
: tu(tu), file_consumer(file_consumer) {}
IndexParam(Config* config, ClangTranslationUnit* tu, FileConsumer* file_consumer)
: config(config), tu(tu), file_consumer(file_consumer) {}
};

IndexFile* ConsumeFile(IndexParam* param, CXFile file) {
Expand Down Expand Up @@ -1967,7 +1968,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {

bool is_template = ref->referencedEntity->templateKind !=
CXIdxEntityCXXTemplateKind::CXIdxEntity_NonTemplate;
if (g_index_make_unique && is_template &&
if (param->config->index.attributeMakeCallsToCtor && is_template &&
str_begin("make", ref->referencedEntity->name)) {
// Try to find the return type of called function. That type will have
// the constructor function we add a usage to.
Expand Down Expand Up @@ -2099,11 +2100,12 @@ optional<std::vector<std::unique_ptr<IndexFile>>> Parse(
if (dump_ast)
Dump(clang_getTranslationUnitCursor(tu->cx_tu));

return ParseWithTu(file_consumer_shared, perf, tu.get(), index, file, args,
unsaved_files);
return ParseWithTu(config, file_consumer_shared, perf, tu.get(), index, file,
args, unsaved_files);
}

optional<std::vector<std::unique_ptr<IndexFile>>> ParseWithTu(
Config* config,
FileConsumerSharedState* file_consumer_shared,
PerformanceImportFile* perf,
ClangTranslationUnit* tu,
Expand All @@ -2126,7 +2128,7 @@ optional<std::vector<std::unique_ptr<IndexFile>>> ParseWithTu(
callback.indexEntityReference = &OnIndexReference;

FileConsumer file_consumer(file_consumer_shared, file);
IndexParam param(tu, &file_consumer);
IndexParam param(config, tu, &file_consumer);
for (const CXUnsavedFile& contents : file_contents) {
param.file_contents[contents.Filename] = FileContents(
contents.Filename, std::string(contents.Contents, contents.Length));
Expand Down
1 change: 1 addition & 0 deletions src/indexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ optional<std::vector<std::unique_ptr<IndexFile>>> Parse(
ClangIndex* index,
bool dump_ast = false);
optional<std::vector<std::unique_ptr<IndexFile>>> ParseWithTu(
Config* config,
FileConsumerSharedState* file_consumer_shared,
PerformanceImportFile* perf,
ClangTranslationUnit* tu,
Expand Down
2 changes: 0 additions & 2 deletions src/messages/initialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// TODO Cleanup global variables
extern std::string g_init_options;
int g_index_comments;
bool g_index_make_unique;

namespace {

Expand Down Expand Up @@ -504,7 +503,6 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
}

g_index_comments = config->index.comments;
g_index_make_unique = config->index.attributeMakeCallsToCtor;
if (config->cacheDirectory.empty()) {
LOG_S(ERROR) << "cacheDirectory cannot be empty.";
exit(1);
Expand Down

0 comments on commit c98d53c

Please sign in to comment.