From f907d1d1b9bcc5387246ab3c580f46e69d1078fe Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Tue, 16 May 2017 00:38:15 -0700 Subject: [PATCH] When indexing make sure we use the correct contents. Hopefully this will make overlapping saves more robust. --- src/command_line.cc | 3 ++- src/indexer.cc | 9 +++++++++ src/indexer.h | 2 ++ src/test.cc | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/command_line.cc b/src/command_line.cc index 051082c7..7ad8fabd 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -1006,7 +1006,8 @@ void ParseFile(IndexerConfig* config, std::vector> indexes = Parse( config, file_consumer_shared, - tu_path, tu_args); + tu_path, tu_args, + entry.filename, indexed_content); time.ResetAndPrint("Parsing/indexing " + tu_path); for (std::unique_ptr& new_index : indexes) { diff --git a/src/indexer.cc b/src/indexer.cc index 54e21ea0..91212290 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1380,6 +1380,8 @@ std::vector> Parse( IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared, std::string file, std::vector args, + const std::string& file_contents_path, + const optional& file_contents, bool dump_ast) { if (!config->enableIndexing) @@ -1390,6 +1392,13 @@ std::vector> Parse( clang::Index index(0 /*excludeDeclarationsFromPCH*/, 0 /*displayDiagnostics*/); std::vector unsaved_files; + if (file_contents) { + CXUnsavedFile unsaved; + unsaved.Filename = file_contents_path.c_str(); + unsaved.Contents = file_contents->c_str(); + unsaved.Length = file_contents->size(); + unsaved_files.push_back(unsaved); + } clang::TranslationUnit tu(index, file, args, unsaved_files, CXTranslationUnit_KeepGoing); if (dump_ast) diff --git a/src/indexer.h b/src/indexer.h index e8f5c10d..fd71ff36 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -506,5 +506,7 @@ std::vector> Parse( IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared, std::string file, std::vector args, + const std::string& file_contents_path, + const optional& file_contents, bool dump_ast = false); void IndexInit(); diff --git a/src/test.cc b/src/test.cc index be8329a4..245579d9 100644 --- a/src/test.cc +++ b/src/test.cc @@ -148,6 +148,7 @@ void RunTests() { "-IC:/Users/jacob/Desktop/superindex/indexer/third_party/rapidjson/include", "-IC:/Users/jacob/Desktop/superindex/indexer/src" }, + "", nullopt, false /*dump_ast*/); #if false