When indexing make sure we use the correct contents.

Hopefully this will make overlapping saves more robust.
This commit is contained in:
Jacob Dufault 2017-05-16 00:38:15 -07:00
parent d8567c75cc
commit f907d1d1b9
4 changed files with 14 additions and 1 deletions

View File

@ -1006,7 +1006,8 @@ void ParseFile(IndexerConfig* config,
std::vector<std::unique_ptr<IndexFile>> indexes = Parse( std::vector<std::unique_ptr<IndexFile>> indexes = Parse(
config, file_consumer_shared, config, file_consumer_shared,
tu_path, tu_args); tu_path, tu_args,
entry.filename, indexed_content);
time.ResetAndPrint("Parsing/indexing " + tu_path); time.ResetAndPrint("Parsing/indexing " + tu_path);
for (std::unique_ptr<IndexFile>& new_index : indexes) { for (std::unique_ptr<IndexFile>& new_index : indexes) {

View File

@ -1380,6 +1380,8 @@ std::vector<std::unique_ptr<IndexFile>> Parse(
IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared, IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared,
std::string file, std::string file,
std::vector<std::string> args, std::vector<std::string> args,
const std::string& file_contents_path,
const optional<std::string>& file_contents,
bool dump_ast) { bool dump_ast) {
if (!config->enableIndexing) if (!config->enableIndexing)
@ -1390,6 +1392,13 @@ std::vector<std::unique_ptr<IndexFile>> Parse(
clang::Index index(0 /*excludeDeclarationsFromPCH*/, clang::Index index(0 /*excludeDeclarationsFromPCH*/,
0 /*displayDiagnostics*/); 0 /*displayDiagnostics*/);
std::vector<CXUnsavedFile> unsaved_files; std::vector<CXUnsavedFile> 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); clang::TranslationUnit tu(index, file, args, unsaved_files, CXTranslationUnit_KeepGoing);
if (dump_ast) if (dump_ast)

View File

@ -506,5 +506,7 @@ std::vector<std::unique_ptr<IndexFile>> Parse(
IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared, IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared,
std::string file, std::string file,
std::vector<std::string> args, std::vector<std::string> args,
const std::string& file_contents_path,
const optional<std::string>& file_contents,
bool dump_ast = false); bool dump_ast = false);
void IndexInit(); void IndexInit();

View File

@ -148,6 +148,7 @@ void RunTests() {
"-IC:/Users/jacob/Desktop/superindex/indexer/third_party/rapidjson/include", "-IC:/Users/jacob/Desktop/superindex/indexer/third_party/rapidjson/include",
"-IC:/Users/jacob/Desktop/superindex/indexer/src" "-IC:/Users/jacob/Desktop/superindex/indexer/src"
}, },
"", nullopt,
false /*dump_ast*/); false /*dump_ast*/);
#if false #if false