From 6cd6552343c3f9b2f85de0f4c27ec2583c5b4064 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Sat, 15 Apr 2017 17:57:20 +0200 Subject: [PATCH] data: improvements on error management * mark all files with errors as incomplete * fix incomplete label in codeview tooltip not updated properly * added setting for canceling indexing for files with fatal errors --- bin/app/user/ApplicationSettings_template.xml | 1 + src/lib/data/IntermediateStorage.cpp | 25 ++++++++++++++++--- src/lib/data/IntermediateStorage.h | 4 ++- src/lib/data/indexer/Indexer.h | 15 ++++++++--- src/lib/data/indexer/IndexerCommand.cpp | 12 ++++++++- src/lib/data/indexer/IndexerCommand.h | 5 ++++ src/lib/data/parser/ParserClient.cpp | 11 ++++++++ src/lib/data/parser/ParserClient.h | 4 +++ src/lib/data/parser/ParserClientImpl.cpp | 4 --- src/lib/project/Project.cpp | 3 +++ src/lib/settings/ApplicationSettings.cpp | 10 ++++++++ src/lib/settings/ApplicationSettings.h | 3 +++ src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp | 2 +- .../qt/element/QtCodeFileTitleButton.cpp | 7 ++++++ .../QtProjectWizzardContentPreferences.cpp | 6 +++++ .../QtProjectWizzardContentPreferences.h | 2 ++ 16 files changed, 100 insertions(+), 14 deletions(-) diff --git a/bin/app/user/ApplicationSettings_template.xml b/bin/app/user/ApplicationSettings_template.xml index 15f0e894..f2ea4d00 100644 --- a/bin/app/user/ApplicationSettings_template.xml +++ b/bin/app/user/ApplicationSettings_template.xml @@ -30,6 +30,7 @@ + diff --git a/src/lib/data/IntermediateStorage.cpp b/src/lib/data/IntermediateStorage.cpp index 512800e2..c08c0de7 100644 --- a/src/lib/data/IntermediateStorage.cpp +++ b/src/lib/data/IntermediateStorage.cpp @@ -1,5 +1,7 @@ #include "data/IntermediateStorage.h" +#include + #include "data/graph/Edge.h" #include "utility/logging/logging.h" @@ -31,7 +33,12 @@ void IntermediateStorage::clear() m_nextId = 1; } -void IntermediateStorage::setFilesIncomplete() +size_t IntermediateStorage::getSourceLocationCount() const +{ + return m_sourceLocationNamesToIds.size(); +} + +void IntermediateStorage::setAllFilesIncomplete() { for (StorageFile& file : m_files) { @@ -39,9 +46,21 @@ void IntermediateStorage::setFilesIncomplete() } } -size_t IntermediateStorage::getSourceLocationCount() const +void IntermediateStorage::setFilesWithErrorsIncomplete() { - return m_sourceLocationNamesToIds.size(); + std::set errorFiles; + for (StorageError& error : m_errors) + { + errorFiles.insert(error.filePath); + } + + for (StorageFile& file : m_files) + { + if (errorFiles.find(file.filePath) != errorFiles.end()) + { + file.complete = false; + } + } } Id IntermediateStorage::addNode(int type, const std::string& serializedName) diff --git a/src/lib/data/IntermediateStorage.h b/src/lib/data/IntermediateStorage.h index 0be89f7a..43b4127f 100644 --- a/src/lib/data/IntermediateStorage.h +++ b/src/lib/data/IntermediateStorage.h @@ -16,9 +16,11 @@ public: virtual ~IntermediateStorage(); void clear(); - void setFilesIncomplete(); size_t getSourceLocationCount() const; + void setAllFilesIncomplete(); + void setFilesWithErrorsIncomplete(); + virtual Id addNode(int type, const std::string& serializedName); virtual void addFile(const Id id, const std::string& filePath, const std::string& modificationTime, bool complete); virtual void addSymbol(const Id id, int definitionKind); diff --git a/src/lib/data/indexer/Indexer.h b/src/lib/data/indexer/Indexer.h index 02d50f27..1f2248c5 100644 --- a/src/lib/data/indexer/Indexer.h +++ b/src/lib/data/indexer/Indexer.h @@ -17,7 +17,8 @@ public: virtual std::string getKindString() const; - virtual std::shared_ptr index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister); + virtual std::shared_ptr index( + std::shared_ptr indexerCommand, std::shared_ptr fileRegister); }; template @@ -32,16 +33,21 @@ std::string Indexer::getKindString() const } template -std::shared_ptr Indexer::index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister) +std::shared_ptr Indexer::index( + std::shared_ptr indexerCommand, std::shared_ptr fileRegister) { std::shared_ptr castedCommand = std::dynamic_pointer_cast(indexerCommand); if (!castedCommand) { - LOG_ERROR("Trying to process " + indexerCommand->getKindString() + " indexer command with " + getKindString() + " indexer."); + LOG_ERROR("Trying to process " + indexerCommand->getKindString() + + " indexer command with " + getKindString() + " indexer."); + return std::shared_ptr(); } std::shared_ptr parserClient = std::make_shared(); + parserClient->setCancelOnFatalErrors(indexerCommand->cancelOnFatalErrors()); + std::shared_ptr parser = std::make_shared(parserClient, fileRegister); std::shared_ptr storage = std::make_shared(); @@ -53,10 +59,11 @@ std::shared_ptr Indexer::in if (parserClient->hasFatalErrors()) { - storage->setFilesIncomplete(); + storage->setAllFilesIncomplete(); } else { + storage->setFilesWithErrorsIncomplete(); fileRegister->markIndexingFilesIndexed(); } diff --git a/src/lib/data/indexer/IndexerCommand.cpp b/src/lib/data/indexer/IndexerCommand.cpp index d28633a3..1d13174c 100644 --- a/src/lib/data/indexer/IndexerCommand.cpp +++ b/src/lib/data/indexer/IndexerCommand.cpp @@ -4,10 +4,10 @@ IndexerCommand::IndexerCommand(const FilePath& sourceFilePath, const std::set IndexerCommand::getExcludedPath() const { return m_excludedPaths; } + +bool IndexerCommand::cancelOnFatalErrors() const +{ + return m_cancelOnFatalErrors; +} + +void IndexerCommand::setCancelOnFatalErrors(bool cancelOnFatalErrors) +{ + m_cancelOnFatalErrors = cancelOnFatalErrors; +} diff --git a/src/lib/data/indexer/IndexerCommand.h b/src/lib/data/indexer/IndexerCommand.h index 53b6f30a..74657bfa 100644 --- a/src/lib/data/indexer/IndexerCommand.h +++ b/src/lib/data/indexer/IndexerCommand.h @@ -18,10 +18,15 @@ public: std::set getIndexedPaths() const; std::set getExcludedPath() const; + bool cancelOnFatalErrors() const; + void setCancelOnFatalErrors(bool cancelOnFatalErrors); + private: FilePath m_sourceFilePath; std::set m_indexedPaths; std::set m_excludedPaths; + + bool m_cancelOnFatalErrors; }; #endif // INDEXER_COMMAND_H diff --git a/src/lib/data/parser/ParserClient.cpp b/src/lib/data/parser/ParserClient.cpp index ffffffcd..125cf5fa 100644 --- a/src/lib/data/parser/ParserClient.cpp +++ b/src/lib/data/parser/ParserClient.cpp @@ -73,6 +73,7 @@ std::string ParserClient::addLocationSuffix( ParserClient::ParserClient() : m_hasFatalErrors(false) + , m_cancelOnFatalErrors(false) { } @@ -94,3 +95,13 @@ bool ParserClient::hasFatalErrors() const { return m_hasFatalErrors; } + +bool ParserClient::cancelOnFatalErrors() const +{ + return m_cancelOnFatalErrors; +} + +void ParserClient::setCancelOnFatalErrors(bool cancelOnFatalErrors) +{ + m_cancelOnFatalErrors = cancelOnFatalErrors; +} diff --git a/src/lib/data/parser/ParserClient.h b/src/lib/data/parser/ParserClient.h index 73d601b3..f623903b 100644 --- a/src/lib/data/parser/ParserClient.h +++ b/src/lib/data/parser/ParserClient.h @@ -55,8 +55,12 @@ public: bool hasFatalErrors() const; + bool cancelOnFatalErrors() const; + void setCancelOnFatalErrors(bool cancelOnFatalErrors); + protected: bool m_hasFatalErrors; + bool m_cancelOnFatalErrors; }; #endif // PARSER_CLIENT_H diff --git a/src/lib/data/parser/ParserClientImpl.cpp b/src/lib/data/parser/ParserClientImpl.cpp index 9d56a498..154558f8 100644 --- a/src/lib/data/parser/ParserClientImpl.cpp +++ b/src/lib/data/parser/ParserClientImpl.cpp @@ -18,15 +18,11 @@ ParserClientImpl::~ParserClientImpl() void ParserClientImpl::setStorage(std::shared_ptr storage) { m_storage = storage; - - m_hasFatalErrors = 0; } void ParserClientImpl::resetStorage() { m_storage.reset(); - - m_hasFatalErrors = 0; } Id ParserClientImpl::recordSymbol( diff --git a/src/lib/project/Project.cpp b/src/lib/project/Project.cpp index 00b52838..fd1d2c30 100644 --- a/src/lib/project/Project.cpp +++ b/src/lib/project/Project.cpp @@ -404,10 +404,13 @@ void Project::buildIndex(const std::set& filesToClean, bool fullRefres } std::shared_ptr indexerCommandList = std::make_shared(); + bool cancelIndexingOnFatalErrors = ApplicationSettings::getInstance()->getCancelIndexingOnFatalErrors(); + for (std::shared_ptr sourceGroup: m_sourceGroups) { for (std::shared_ptr command: sourceGroup->getIndexerCommands(fullRefresh)) { + command->setCancelOnFatalErrors(cancelIndexingOnFatalErrors); indexerCommandList->addCommand(command); } } diff --git a/src/lib/settings/ApplicationSettings.cpp b/src/lib/settings/ApplicationSettings.cpp index b906b81c..a573cee9 100644 --- a/src/lib/settings/ApplicationSettings.cpp +++ b/src/lib/settings/ApplicationSettings.cpp @@ -236,6 +236,16 @@ void ApplicationSettings::setIndexerThreadCount(const int count) setValue("indexing/indexer_thread_count", count); } +bool ApplicationSettings::getCancelIndexingOnFatalErrors() const +{ + return getValue("indexing/cancel_on_fatal_errors", true); +} + +void ApplicationSettings::setCancelIndexingOnFatalErrors(bool enabled) +{ + setValue("indexing/cancel_on_fatal_errors", enabled); +} + std::string ApplicationSettings::getJavaPath() const { return getValue("indexing/java/java_path", ""); diff --git a/src/lib/settings/ApplicationSettings.h b/src/lib/settings/ApplicationSettings.h index 78f27563..46e056f1 100644 --- a/src/lib/settings/ApplicationSettings.h +++ b/src/lib/settings/ApplicationSettings.h @@ -70,6 +70,9 @@ public: int getIndexerThreadCount() const; void setIndexerThreadCount(const int count); + bool getCancelIndexingOnFatalErrors() const; + void setCancelIndexingOnFatalErrors(bool enabled); + std::string getJavaPath() const; void setJavaPath(const std::string path); diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp index 86d125ae..9eb0f4e6 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp @@ -285,7 +285,7 @@ bool CxxAstVisitor::TraverseTemplateTemplateParmDecl(clang::TemplateTemplateParm bool CxxAstVisitor::VisitTranslationUnitDecl(clang::TranslationUnitDecl *d) { - return !m_client->hasFatalErrors(); + return !m_client->cancelOnFatalErrors() || !m_client->hasFatalErrors(); } bool CxxAstVisitor::TraverseNestedNameSpecifierLoc(clang::NestedNameSpecifierLoc loc) diff --git a/src/lib_gui/qt/element/QtCodeFileTitleButton.cpp b/src/lib_gui/qt/element/QtCodeFileTitleButton.cpp index 54c77876..b50eff9a 100644 --- a/src/lib_gui/qt/element/QtCodeFileTitleButton.cpp +++ b/src/lib_gui/qt/element/QtCodeFileTitleButton.cpp @@ -56,6 +56,11 @@ void QtCodeFileTitleButton::setModificationTime(const TimePoint modificationTime void QtCodeFileTitleButton::setIsComplete(bool isComplete) { + if (m_isComplete == isComplete) + { + return; + } + m_isComplete = isComplete; setProperty("complete", isComplete); @@ -70,6 +75,8 @@ void QtCodeFileTitleButton::setIsComplete(bool isComplete) { setStyleSheet(""); } + + updateTexts(); } void QtCodeFileTitleButton::setProject(const std::string& name) diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp index 55748014..f6d9aaa4 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp @@ -118,6 +118,10 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row) addHelpButton("Number of parallel threads used to index your projects.\nWhen setting this to 0 Sourcetrail tries to use the ideal thread count for your computer.", layout, row); row++; + // cancel indexing on fatal errors + m_cancelIndexingOnFatalErrors = addCheckBox("Cancel on Fatals", "Cancel indexing on Fatal errors.", + "Cancel indexing of translation units with fatal errors, which result in partly indexed files.", layout, row); + addGap(layout, row); @@ -256,6 +260,7 @@ void QtProjectWizzardContentPreferences::load() m_threads->setCurrentIndex(appSettings->getIndexerThreadCount()); // index and value are the same indexerThreadsChanges(m_threads->currentIndex()); + m_cancelIndexingOnFatalErrors->setChecked(appSettings->getCancelIndexingOnFatalErrors()); if (m_javaPath) { @@ -299,6 +304,7 @@ void QtProjectWizzardContentPreferences::save() if (pluginPort) appSettings->setPluginPort(pluginPort); appSettings->setIndexerThreadCount(m_threads->currentIndex()); // index and value are the same + appSettings->setCancelIndexingOnFatalErrors(m_cancelIndexingOnFatalErrors->isChecked()); if (m_javaPath) { diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h index 539a748a..2df1d1a7 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h @@ -69,6 +69,8 @@ private: QComboBox* m_threads; QLabel* m_threadsInfoLabel; + QCheckBox* m_cancelIndexingOnFatalErrors; + std::shared_ptr m_javaPathDetector; std::shared_ptr m_mavenPathDetector;