diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 018feae7..0e5a0d21 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -155,6 +155,7 @@ add_files( data/DefinitionType.cpp data/DefinitionType.h data/ErrorCountInfo.h + data/ErrorInfo.h data/HierarchyCache.cpp data/HierarchyCache.h data/IntermediateStorage.cpp diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 685cb636..63238362 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -43,7 +43,7 @@ bool Project::load(const FilePath& projectSettingsFile) { m_storage->startParsing(); m_storage->finishParsing(); - MessageFinishedParsing(0, 0, 0).dispatch(); + MessageFinishedParsing(0, 0, 0, true).dispatch(); } else { diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index fb4d0a2a..ff0fb2b4 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -28,8 +28,8 @@ const uint CodeController::s_lineRadius = 2; void CodeController::handleMessage(MessageActivateAll* message) { - std::vector errorMessages; - std::vector snippets = getSnippetsForErrorLocations(&errorMessages); + std::vector errors; + std::vector snippets = getSnippetsForErrorLocations(&errors); StorageStats stats = m_storageAccess->getStorageStats(); CodeSnippetParams statsSnippet; @@ -80,7 +80,7 @@ void CodeController::handleMessage(MessageActivateAll* message) snippets.insert(snippets.begin(), statsSnippet); CodeView* view = getView(); - view->setErrorMessages(errorMessages); + view->setErrorInfos(errors); view->showCodeSnippets(snippets, std::vector()); showContents(message); @@ -95,7 +95,7 @@ void CodeController::handleMessage(MessageActivateLocalSymbols* message) void CodeController::handleMessage(MessageActivateTokens* message) { CodeView* view = getView(); - view->setErrorMessages(std::vector()); + view->setErrorInfos(std::vector()); std::vector activeTokenIds = message->tokenIds; Id declarationId = 0; // 0 means that no token is found. @@ -162,7 +162,14 @@ void CodeController::handleMessage(MessageChangeFileView* message) case MessageChangeFileView::FILE_SNIPPETS: if (message->needsData) { - view->addCodeSnippets(getSnippetsForActiveTokenLocationsInFile(message->locationFile), false); + if (message->showErrors) + { + view->addCodeSnippets(getSnippetsForFile(message->locationFile), false); + } + else + { + view->addCodeSnippets(getSnippetsForActiveTokenLocationsInFile(message->locationFile), false); + } } view->setFileState(message->filePath, CodeView::FILE_SNIPPETS); break; @@ -181,8 +188,8 @@ void CodeController::handleMessage(MessageChangeFileView* message) if (message->showErrors) { - std::vector errorMessages; - TokenLocationCollection errorCollection = m_storageAccess->getErrorTokenLocations(&errorMessages); + std::vector errors; + TokenLocationCollection errorCollection = m_storageAccess->getErrorTokenLocations(&errors); params.locationFile = std::make_shared(*errorCollection.findTokenLocationFileByPath(message->filePath)); params.locationFile->isWholeCopy = true; } @@ -225,11 +232,11 @@ void CodeController::handleMessage(MessageScrollCode* message) void CodeController::handleMessage(MessageShowErrors* message) { - std::vector errorMessages; - std::vector snippets = getSnippetsForErrorLocations(&errorMessages); + std::vector errors; + std::vector snippets = getSnippetsForErrorLocations(&errors); CodeView* view = getView(); - view->setErrorMessages(errorMessages); + view->setErrorInfos(errors); view->showCodeSnippets(snippets, std::vector()); showContents(message); @@ -256,8 +263,8 @@ void CodeController::handleMessage(MessageShowScope* message) if (message->showErrors) { - std::vector errorMessages; - std::vector errorSnippets = getSnippetsForErrorLocations(&errorMessages); + std::vector errors; + std::vector errorSnippets = getSnippetsForErrorLocations(&errors); for (const CodeSnippetParams& error : errorSnippets) { @@ -556,17 +563,30 @@ std::shared_ptr CodeController::getTokenLocationOfParentScope } std::vector CodeController::getSnippetsForErrorLocations( - std::vector* errorMessages) const + std::vector* errors) const { - TokenLocationCollection errorCollection = m_storageAccess->getErrorTokenLocations(errorMessages); + TokenLocationCollection errorCollection = m_storageAccess->getErrorTokenLocations(errors); std::vector snippets; errorCollection.forEachTokenLocationFile( [&](std::shared_ptr file) -> void { - std::vector fileSnippets = getSnippetsForFile(file); - snippets.insert(snippets.end(), fileSnippets.begin(), fileSnippets.end()); + if (snippets.size() < 10) + { + std::vector fileSnippets = getSnippetsForFile(file); + snippets.insert(snippets.end(), fileSnippets.begin(), fileSnippets.end()); + } + else + { + CodeSnippetParams params; + params.locationFile = file; + params.refCount = file->getUnscopedStartTokenLocationCount(); + params.modificationTime = m_storageAccess->getFileModificationTime(file->getFilePath()); + + params.isCollapsed = true; + snippets.push_back(params); + } } ); diff --git a/src/lib/component/controller/CodeController.h b/src/lib/component/controller/CodeController.h index 96b952d0..d43ed736 100644 --- a/src/lib/component/controller/CodeController.h +++ b/src/lib/component/controller/CodeController.h @@ -70,7 +70,7 @@ private: TokenLocation* location, std::shared_ptr context, SnippetMerger& fileScopedMerger, std::map>& mergers) const; std::shared_ptr getTokenLocationOfParentScope(const TokenLocation* location, std::shared_ptr context) const; - std::vector getSnippetsForErrorLocations(std::vector* errorMessages) const; + std::vector getSnippetsForErrorLocations(std::vector* errors) const; std::vector getProjectDescription(TokenLocationFile* locationFile) const; diff --git a/src/lib/component/controller/StatusBarController.cpp b/src/lib/component/controller/StatusBarController.cpp index 547619f3..4e290285 100644 --- a/src/lib/component/controller/StatusBarController.cpp +++ b/src/lib/component/controller/StatusBarController.cpp @@ -29,13 +29,13 @@ void StatusBarController::handleMessage(MessageFinishedParsing* message) getView()->setErrorCount(errorCount); std::string status = message->getStatusStr(); - status += " " + std::to_string(errorCount.total) + " error" + (errorCount.total != 1 ? "s" : ""); + status += "; " + std::to_string(errorCount.total) + " error" + (errorCount.total != 1 ? "s" : ""); if (errorCount.fatal > 0) { status += " (" + std::to_string(errorCount.fatal) + " fatal)"; } - MessageStatus(status, errorCount.total > 0).dispatch(); + MessageStatus(status, false).dispatch(); } void StatusBarController::handleMessage(MessageShowErrors* message) diff --git a/src/lib/component/view/CodeView.h b/src/lib/component/view/CodeView.h index d4b86aa9..1d16df87 100644 --- a/src/lib/component/view/CodeView.h +++ b/src/lib/component/view/CodeView.h @@ -3,6 +3,7 @@ #include +#include "data/ErrorInfo.h" #include "utility/file/FilePath.h" #include "component/view/helper/CodeSnippetParams.h" @@ -29,7 +30,7 @@ public: virtual void clear() = 0; virtual void setActiveTokenIds(const std::vector& activeTokenIds) = 0; - virtual void setErrorMessages(const std::vector& errorMessages) = 0; + virtual void setErrorInfos(const std::vector& errorInfos) = 0; virtual void showCodeSnippets(const std::vector& snippets, const std::vector& activeTokenIds) = 0; virtual void addCodeSnippets(const std::vector& snippets, bool insert) = 0; diff --git a/src/lib/data/ErrorInfo.h b/src/lib/data/ErrorInfo.h new file mode 100644 index 00000000..1d60d913 --- /dev/null +++ b/src/lib/data/ErrorInfo.h @@ -0,0 +1,29 @@ +#ifndef ERROR_INFO_H +#define ERROR_INFO_H + +#include "utility/file/FilePath.h" +#include "utility/types.h" + +struct ErrorInfo +{ + ErrorInfo() + : id(0) + , isFatal(false) + { + } + + ErrorInfo(const std::string& message, const FilePath& filePath, Id id, bool isFatal) + : message(message) + , filePath(filePath) + , id(id) + , isFatal(isFatal) + { + } + + std::string message; + FilePath filePath; + Id id; + bool isFatal; +}; + +#endif // ERROR_INFO_H diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index 55e9f9fc..7a982984 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -643,17 +643,17 @@ std::shared_ptr Storage::getTokenLocationsForLinesInFile( return m_sqliteStorage.getTokenLocationsForFile(filePath)->getFilteredByLines(firstLineNumber, lastLineNumber); } -TokenLocationCollection Storage::getErrorTokenLocations(std::vector* errorMessages) const +TokenLocationCollection Storage::getErrorTokenLocations(std::vector* errors) const { TokenLocationCollection errorCollection; - std::vector errors = m_sqliteStorage.getAllErrors(); - for (size_t i = 0; i < errors.size(); i++) + std::vector storageErrors = m_sqliteStorage.getAllErrors(); + for (size_t i = 0; i < storageErrors.size(); i++) { - const StorageError& error = errors[i]; + const StorageError& error = storageErrors[i]; errorCollection.addTokenLocation( i, i, error.filePath, error.lineNumber, error.columnNumber, error.lineNumber, error.columnNumber); - errorMessages->push_back(error.message); + errors->push_back(ErrorInfo(error.message, error.filePath, i, error.fatal)); } return errorCollection; diff --git a/src/lib/data/Storage.h b/src/lib/data/Storage.h index 29642de2..d5ba53e2 100644 --- a/src/lib/data/Storage.h +++ b/src/lib/data/Storage.h @@ -75,7 +75,7 @@ public: const std::string& filePath, uint firstLineNumber, uint lastLineNumber ) const; - virtual TokenLocationCollection getErrorTokenLocations(std::vector* errorMessages) const; + virtual TokenLocationCollection getErrorTokenLocations(std::vector* errors) const; virtual std::shared_ptr getCommentLocationsInFile(const FilePath& filePath) const; virtual std::shared_ptr getFileContent(const FilePath& filePath) const; diff --git a/src/lib/data/access/StorageAccess.h b/src/lib/data/access/StorageAccess.h index 32a6879e..dcc4d4ce 100644 --- a/src/lib/data/access/StorageAccess.h +++ b/src/lib/data/access/StorageAccess.h @@ -11,6 +11,7 @@ #include "data/graph/Node.h" #include "data/search/SearchMatch.h" #include "data/ErrorCountInfo.h" +#include "data/ErrorInfo.h" #include "data/StorageStats.h" struct FileInfo; @@ -56,7 +57,7 @@ public: virtual std::shared_ptr getTokenLocationsForLinesInFile( const std::string& filePath, uint firstLineNumber, uint lastLineNumber) const = 0; - virtual TokenLocationCollection getErrorTokenLocations(std::vector* errorMessages) const = 0; + virtual TokenLocationCollection getErrorTokenLocations(std::vector* errors) const = 0; virtual std::shared_ptr getCommentLocationsInFile(const FilePath& filePath) const = 0; virtual std::shared_ptr getFileContent(const FilePath& filePath) const = 0; diff --git a/src/lib/data/access/StorageAccessProxy.cpp b/src/lib/data/access/StorageAccessProxy.cpp index 91d3bf31..10449780 100644 --- a/src/lib/data/access/StorageAccessProxy.cpp +++ b/src/lib/data/access/StorageAccessProxy.cpp @@ -225,11 +225,11 @@ std::shared_ptr StorageAccessProxy::getTokenLocationsForLines return std::make_shared(""); } -TokenLocationCollection StorageAccessProxy::getErrorTokenLocations(std::vector* errorMessages) const +TokenLocationCollection StorageAccessProxy::getErrorTokenLocations(std::vector* errors) const { if (hasSubject()) { - return m_subject->getErrorTokenLocations(errorMessages); + return m_subject->getErrorTokenLocations(errors); } return TokenLocationCollection(); diff --git a/src/lib/data/access/StorageAccessProxy.h b/src/lib/data/access/StorageAccessProxy.h index d5083b60..b80687b8 100644 --- a/src/lib/data/access/StorageAccessProxy.h +++ b/src/lib/data/access/StorageAccessProxy.h @@ -44,7 +44,7 @@ public: const std::string& filePath, uint firstLineNumber, uint lastLineNumber ) const; - virtual TokenLocationCollection getErrorTokenLocations(std::vector* errorMessages) const; + virtual TokenLocationCollection getErrorTokenLocations(std::vector* errors) const; virtual std::shared_ptr getCommentLocationsInFile(const FilePath& filePath) const; virtual std::shared_ptr getFileContent(const FilePath& filePath) const; diff --git a/src/lib/utility/messaging/type/MessageFinishedParsing.h b/src/lib/utility/messaging/type/MessageFinishedParsing.h index e47b2f9c..599b6b26 100644 --- a/src/lib/utility/messaging/type/MessageFinishedParsing.h +++ b/src/lib/utility/messaging/type/MessageFinishedParsing.h @@ -12,10 +12,11 @@ class MessageFinishedParsing : public Message { public: - MessageFinishedParsing(size_t fileCount, size_t totalFileCount, float parseTime) + MessageFinishedParsing(size_t fileCount, size_t totalFileCount, float parseTime, bool loadedOnly = false) : fileCount(fileCount) , totalFileCount(totalFileCount) , parseTime(parseTime) + , loadedOnly(loadedOnly) { } @@ -31,6 +32,11 @@ public: std::string getStatusStr() const { + if (loadedOnly) + { + return "Finished loading"; + } + std::stringstream ss; ss << "Finished analysis: "; ss << fileCount << "/" << totalFileCount << " files; "; @@ -41,6 +47,8 @@ public: int minutes = int(secondsLeft / 60); secondsLeft -= minutes * 60; int seconds = int(secondsLeft); + secondsLeft -= seconds; + int milliSeconds = secondsLeft * 1000; if (hours > 9) { @@ -51,7 +59,12 @@ public: ss << std::setw(2) << std::setfill('0') << hours; } ss << ":" << std::setw(2) << std::setfill('0') << minutes; - ss << ":" << std::setw(2) << std::setfill('0') << seconds << ". "; + ss << ":" << std::setw(2) << std::setfill('0') << seconds; + + if (!hours && !minutes) + { + ss << ":" << std::setw(3) << std::setfill('0') << milliSeconds; + } return ss.str(); } @@ -64,6 +77,7 @@ public: size_t fileCount; size_t totalFileCount; float parseTime; + bool loadedOnly; }; #endif // MESSAGE_FINISHED_PARSING_H diff --git a/src/lib_gui/qt/element/QtCodeArea.cpp b/src/lib_gui/qt/element/QtCodeArea.cpp index 5d10d09c..492588b0 100644 --- a/src/lib_gui/qt/element/QtCodeArea.cpp +++ b/src/lib_gui/qt/element/QtCodeArea.cpp @@ -423,7 +423,7 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event) m_eventPosition = event->pos(); setIDECursorPosition(); } - else if (!m_fileWidget->getErrorMessages().size()) + else if (!m_fileWidget->hasErrors()) { QTextCursor cursor = this->cursorForPosition(event->pos()); std::vector annotations = getNonScopeAnnotationsForPosition(cursor.position()); @@ -471,7 +471,7 @@ void QtCodeArea::mouseMoveEvent(QMouseEvent* event) setHoveredAnnotations(annotations); - const std::vector& errorMessages = m_fileWidget->getErrorMessages(); + std::vector errorMessages = m_fileWidget->getErrorMessages(); if (annotations.size() == 1 && errorMessages.size() > annotations[0]->tokenId) { QToolTip::showText(event->globalPos(), QString::fromStdString(errorMessages[annotations[0]->tokenId])); diff --git a/src/lib_gui/qt/element/QtCodeFile.cpp b/src/lib_gui/qt/element/QtCodeFile.cpp index 75f348e8..c2d892af 100644 --- a/src/lib_gui/qt/element/QtCodeFile.cpp +++ b/src/lib_gui/qt/element/QtCodeFile.cpp @@ -139,14 +139,14 @@ const std::vector& QtCodeFile::getFocusedTokenIds() const return m_parent->getFocusedTokenIds(); } -const std::vector& QtCodeFile::getErrorMessages() const +std::vector QtCodeFile::getErrorMessages() const { return m_parent->getErrorMessages(); } bool QtCodeFile::hasErrors() const { - return getErrorMessages().size() > 0; + return m_parent->hasErrors();; } void QtCodeFile::addCodeSnippet(const CodeSnippetParams& params) @@ -472,7 +472,19 @@ void QtCodeFile::updateRefCount(int refCount) { if (refCount > 0) { - m_referenceCount->setText(QString::fromStdString(std::to_string(refCount) + (refCount == 1 ? " reference" : " references"))); + QString label = hasErrors() ? "error" : "reference"; + if (refCount > 1) + { + label += "s"; + } + + size_t fatalErrorCount = m_parent->getFatalErrorCountForFile(m_filePath); + if (fatalErrorCount > 0) + { + label += " (" + QString::number(fatalErrorCount) + " fatal)"; + } + + m_referenceCount->setText(QString::number(refCount) + " " + label); m_referenceCount->show(); } else diff --git a/src/lib_gui/qt/element/QtCodeFile.h b/src/lib_gui/qt/element/QtCodeFile.h index c96a2501..c90d950d 100644 --- a/src/lib_gui/qt/element/QtCodeFile.h +++ b/src/lib_gui/qt/element/QtCodeFile.h @@ -14,6 +14,7 @@ #include "utility/messaging/type/MessageWindowFocus.h" #include "qt/utility/QtThreadedFunctor.h" +#include "data/ErrorInfo.h" #include "component/view/helper/CodeSnippetParams.h" class QLabel; @@ -42,7 +43,7 @@ public: const std::vector& getActiveLocalSymbolIds() const; const std::vector& getFocusedTokenIds() const; - const std::vector& getErrorMessages() const; + std::vector getErrorMessages() const; bool hasErrors() const; void addCodeSnippet(const CodeSnippetParams& params); diff --git a/src/lib_gui/qt/element/QtCodeFileList.cpp b/src/lib_gui/qt/element/QtCodeFileList.cpp index a169f2f4..9b5965f5 100644 --- a/src/lib_gui/qt/element/QtCodeFileList.cpp +++ b/src/lib_gui/qt/element/QtCodeFileList.cpp @@ -108,14 +108,37 @@ void QtCodeFileList::setFocusedTokenIds(const std::vector& focusedTokenIds) m_focusedTokenIds = focusedTokenIds; } -const std::vector& QtCodeFileList::getErrorMessages() const +std::vector QtCodeFileList::getErrorMessages() const { - return m_errorMessages; + std::vector errorMessages; + for (const ErrorInfo& error : m_errorInfos) + { + errorMessages.push_back(error.message); + } + return errorMessages; } -void QtCodeFileList::setErrorMessages(const std::vector& errorMessages) +void QtCodeFileList::setErrorInfos(const std::vector& errorInfos) { - m_errorMessages = errorMessages; + m_errorInfos = errorInfos; +} + +bool QtCodeFileList::hasErrors() const +{ + return m_errorInfos.size() > 0; +} + +size_t QtCodeFileList::getFatalErrorCountForFile(const FilePath& filePath) const +{ + size_t fatalErrorCount = 0; + for (const ErrorInfo& error : m_errorInfos) + { + if (error.filePath == filePath && error.isFatal) + { + fatalErrorCount++; + } + } + return fatalErrorCount; } void QtCodeFileList::showActiveTokenIds() diff --git a/src/lib_gui/qt/element/QtCodeFileList.h b/src/lib_gui/qt/element/QtCodeFileList.h index 950b6155..68ebf646 100644 --- a/src/lib_gui/qt/element/QtCodeFileList.h +++ b/src/lib_gui/qt/element/QtCodeFileList.h @@ -11,6 +11,7 @@ #include "utility/TimePoint.h" #include "utility/types.h" +#include "data/ErrorInfo.h" #include "component/view/helper/CodeSnippetParams.h" class QtCodeFile; @@ -45,8 +46,11 @@ public: const std::vector& getFocusedTokenIds() const; void setFocusedTokenIds(const std::vector& focusedTokenIds); - const std::vector& getErrorMessages() const; - void setErrorMessages(const std::vector& errorMessages); + std::vector getErrorMessages() const; + void setErrorInfos(const std::vector& errorInfos); + + bool hasErrors() const; + size_t getFatalErrorCountForFile(const FilePath& filePath) const; void showActiveTokenIds(); @@ -82,7 +86,7 @@ private: std::vector m_activeTokenIds; std::vector m_activeLocalSymbolIds; std::vector m_focusedTokenIds; - std::vector m_errorMessages; + std::vector m_errorInfos; QtCodeFile* m_scrollToFile; int m_value; diff --git a/src/lib_gui/qt/element/QtStatusBar.cpp b/src/lib_gui/qt/element/QtStatusBar.cpp index 0de93913..47e95ca2 100644 --- a/src/lib_gui/qt/element/QtStatusBar.cpp +++ b/src/lib_gui/qt/element/QtStatusBar.cpp @@ -69,8 +69,8 @@ void QtStatusBar::setErrorCount(ErrorCountInfo errorCount) if (errorCount.total > 0) { m_errorButton.setText( - QString::number(errorCount.total) + " error" + (errorCount.total > 1 ? "s" : "") + - (errorCount.fatal > 0 ? "(" + QString::number(errorCount.fatal) + " fatal)" : "")); + QString::number(errorCount.total) + " error" + (errorCount.total > 1 ? "s" : "") + + (errorCount.fatal > 0 ? " (" + QString::number(errorCount.fatal) + " fatal)" : "")); m_errorButton.show(); } else diff --git a/src/lib_gui/qt/view/QtCodeView.cpp b/src/lib_gui/qt/view/QtCodeView.cpp index 94e7b265..7d786518 100644 --- a/src/lib_gui/qt/view/QtCodeView.cpp +++ b/src/lib_gui/qt/view/QtCodeView.cpp @@ -57,9 +57,9 @@ void QtCodeView::setActiveTokenIds(const std::vector& activeTokenIds) m_activeTokenIds = activeTokenIds; } -void QtCodeView::setErrorMessages(const std::vector& errorMessages) +void QtCodeView::setErrorInfos(const std::vector& errorInfos) { - m_errorMessages = errorMessages; + m_errorInfos = errorInfos; } void QtCodeView::showCodeSnippets(const std::vector& snippets, const std::vector& activeTokenIds) @@ -134,7 +134,7 @@ void QtCodeView::doShowCodeSnippets(const std::vector& snippe m_widget->clearCodeSnippets(); m_widget->setActiveTokenIds(activeTokenIds); - m_widget->setErrorMessages(m_errorMessages); + m_widget->setErrorInfos(m_errorInfos); for (const CodeSnippetParams& params : snippets) { diff --git a/src/lib_gui/qt/view/QtCodeView.h b/src/lib_gui/qt/view/QtCodeView.h index 9ffaef0b..d8192e11 100644 --- a/src/lib_gui/qt/view/QtCodeView.h +++ b/src/lib_gui/qt/view/QtCodeView.h @@ -29,7 +29,7 @@ public: virtual void clear(); virtual void setActiveTokenIds(const std::vector& activeTokenIds); - virtual void setErrorMessages(const std::vector& errorMessages); + virtual void setErrorInfos(const std::vector& errorInfos); virtual void showCodeSnippets(const std::vector& snippets, const std::vector& activeTokenIds); virtual void addCodeSnippets(const std::vector& snippets, bool insert); @@ -88,7 +88,7 @@ private: QtCodeFileList* m_widget; std::vector m_activeTokenIds; - std::vector m_errorMessages; + std::vector m_errorInfos; }; # endif // QT_CODE_VIEW_H