From 0e5312790ef6a8b17261d34fde32e9383fd70dd4 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Tue, 13 Jun 2017 20:08:31 -0700 Subject: [PATCH] Add more detailed logging for failed unique file id --- src/file_consumer.cc | 5 +++-- src/file_consumer.h | 3 ++- src/indexer.cc | 6 +++++- src/libclangmm/TranslationUnit.cc | 1 + src/libclangmm/TranslationUnit.h | 19 ++++++++++--------- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/file_consumer.cc b/src/file_consumer.cc index a05fd539..5e3effdc 100644 --- a/src/file_consumer.cc +++ b/src/file_consumer.cc @@ -21,14 +21,15 @@ void FileConsumer::SharedState::Reset(const std::string& file) { files.erase(it); } -FileConsumer::FileConsumer(SharedState* shared_state) : shared_(shared_state) {} +FileConsumer::FileConsumer(SharedState* shared_state, const std::string& parse_file) + : shared_(shared_state), parse_file_(parse_file) {} IndexFile* FileConsumer::TryConsumeFile(CXFile file, bool* is_first_ownership) { assert(is_first_ownership); CXFileUniqueID file_id; if (clang_getFileUniqueID(file, &file_id) != 0) { - std::cerr << "Could not get unique file id for " << FileName(file) << std::endl; + std::cerr << "Could not get unique file id when parsing " << parse_file_ << std::endl; return nullptr; } diff --git a/src/file_consumer.h b/src/file_consumer.h index 9988d89c..e0012f34 100644 --- a/src/file_consumer.h +++ b/src/file_consumer.h @@ -33,7 +33,7 @@ struct FileConsumer { void Reset(const std::string& file); }; - FileConsumer(SharedState* shared_state); + FileConsumer(SharedState* shared_state, const std::string& parse_file); // Returns true if this instance owns given |file|. This will also attempt to // take ownership over |file|. @@ -52,4 +52,5 @@ struct FileConsumer { private: std::unordered_map> local_; SharedState* shared_; + std::string parse_file_; }; \ No newline at end of file diff --git a/src/indexer.cc b/src/indexer.cc index 9fa8b220..1683a55b 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1535,6 +1535,10 @@ std::vector> Parse( unsaved_files.push_back(unsaved); } clang::TranslationUnit tu(index, file, args, unsaved_files, CXTranslationUnit_KeepGoing | CXTranslationUnit_DetailedPreprocessingRecord); + if (tu.did_fail) { + std::cerr << "!! Failed creating translation unit for " << file << std::endl; + return {}; + } perf->index_parse = timer.ElapsedMicrosecondsAndReset(); @@ -1548,7 +1552,7 @@ std::vector> Parse( &indexEntityReference} }; - FileConsumer file_consumer(file_consumer_shared); + FileConsumer file_consumer(file_consumer_shared, file); IndexParam param(&tu, &file_consumer); CXFile cx_file = clang_getFile(tu.cx_tu, file.c_str()); diff --git a/src/libclangmm/TranslationUnit.cc b/src/libclangmm/TranslationUnit.cc index fac21792..a4dee975 100644 --- a/src/libclangmm/TranslationUnit.cc +++ b/src/libclangmm/TranslationUnit.cc @@ -2,6 +2,7 @@ #include "Utility.h" #include "../platform.h" +#include "../utils.h" #include #include diff --git a/src/libclangmm/TranslationUnit.h b/src/libclangmm/TranslationUnit.h index 267c0ad5..c65e9980 100644 --- a/src/libclangmm/TranslationUnit.h +++ b/src/libclangmm/TranslationUnit.h @@ -1,15 +1,16 @@ -#ifndef TRANSLATIONUNIT_H_ -#define TRANSLATIONUNIT_H_ -#include -#include -#include -#include -#include +#pragma once + + #include "Index.h" #include "Cursor.h" -#include "../language_server_api.h" + +#include + +#include +#include namespace clang { + class TranslationUnit { public: TranslationUnit(Index* index, @@ -27,5 +28,5 @@ class TranslationUnit { CXTranslationUnit cx_tu; }; + } // namespace clang -#endif // TRANSLATIONUNIT_H_