diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index 76556e1a..0166a04a 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -29,7 +29,8 @@ const uint CodeController::s_lineRadius = 2; void CodeController::handleMessage(MessageActivateAll* message) { std::vector errors; - std::vector snippets = getSnippetsForErrorLocations(&errors); + m_collection = m_storageAccess->getErrorTokenLocations(&errors); + std::vector snippets = getSnippetsForCollection(m_collection); StorageStats stats = m_storageAccess->getStorageStats(); CodeSnippetParams statsSnippet; @@ -79,6 +80,7 @@ void CodeController::handleMessage(MessageActivateAll* message) snippets.insert(snippets.begin(), statsSnippet); CodeView* view = getView(); + view->clear(); view->setErrorInfos(errors); view->showCodeSnippets(snippets, std::vector()); @@ -94,19 +96,17 @@ void CodeController::handleMessage(MessageActivateLocalSymbols* message) void CodeController::handleMessage(MessageActivateTokens* message) { CodeView* view = getView(); - view->setErrorInfos(std::vector()); + + if (!message->keepContent()) + { + view->clear(); + } std::vector activeTokenIds = message->tokenIds; Id declarationId = 0; // 0 means that no token is found. if (!message->isAggregation) { - if (activeTokenIds.size() != 1) - { - view->clear(); - return; - } - activeTokenIds = m_storageAccess->getActiveTokenIdsForId(activeTokenIds[0], &declarationId); } @@ -114,18 +114,17 @@ void CodeController::handleMessage(MessageActivateTokens* message) { view->showFirstActiveSnippet(activeTokenIds, message->isLast()); } - - if (message->keepContent()) + else if (message->keepContent()) { view->showActiveTokenIds(activeTokenIds); } else { - std::shared_ptr collection = m_storageAccess->getTokenLocationsForTokenIds(activeTokenIds); - view->showCodeSnippets(getSnippetsForActiveTokenLocations(collection.get(), declarationId), activeTokenIds); + m_collection = m_storageAccess->getTokenLocationsForTokenIds(activeTokenIds); + view->showCodeSnippets(getSnippetsForActiveTokenLocations(m_collection.get(), declarationId), activeTokenIds); - size_t fileCount = collection->getTokenLocationFileCount(); - size_t referenceCount = collection->getTokenLocationCount(); + size_t fileCount = m_collection->getTokenLocationFileCount(); + size_t referenceCount = m_collection->getTokenLocationCount(); std::stringstream ss; ss << message->tokenIds.size() << ' '; @@ -158,14 +157,8 @@ void CodeController::handleMessage(MessageChangeFileView* message) case MessageChangeFileView::FILE_SNIPPETS: if (message->needsData) { - if (message->showErrors) - { - view->addCodeSnippets(getSnippetsForFile(message->locationFile), false); - } - else - { - view->addCodeSnippets(getSnippetsForActiveTokenLocationsInFile(message->locationFile), false); - } + view->addCodeSnippets(getSnippetsForFile( + m_collection->getTokenLocationFileByPath(message->filePath), !message->showErrors), false); } view->setFileState(message->filePath, CodeView::FILE_SNIPPETS); break; @@ -184,14 +177,26 @@ void CodeController::handleMessage(MessageChangeFileView* message) if (message->showErrors) { - std::vector errors; - TokenLocationCollection errorCollection = m_storageAccess->getErrorTokenLocations(&errors); - params.locationFile = std::make_shared(*errorCollection.findTokenLocationFileByPath(message->filePath)); + params.locationFile = m_collection->getTokenLocationFileByPath(message->filePath); params.locationFile->isWholeCopy = true; } else { - params.locationFile = m_storageAccess->getTokenLocationsForFile(message->filePath.str()); + std::shared_ptr file = + m_storageAccess->getTokenLocationsForFile(message->filePath.str()); + + TokenLocationFile* activeLocations = m_collection->findTokenLocationFileByPath(message->filePath); + if (activeLocations) + { + activeLocations->forEachTokenLocation( + [&file](TokenLocation* location) + { + file->addTokenLocationAsPlainCopy(location); + } + ); + } + + params.locationFile = file; } getView()->showCodeFile(params); @@ -229,9 +234,11 @@ void CodeController::handleMessage(MessageScrollCode* message) void CodeController::handleMessage(MessageShowErrors* message) { std::vector errors; - std::vector snippets = getSnippetsForErrorLocations(&errors); + m_collection = m_storageAccess->getErrorTokenLocations(&errors); + std::vector snippets = getSnippetsForCollection(m_collection); CodeView* view = getView(); + view->clear(); view->setErrorInfos(errors); view->showCodeSnippets(snippets, std::vector()); @@ -241,10 +248,10 @@ void CodeController::handleMessage(MessageShowErrors* message) void CodeController::handleMessage(MessageSearchFullText* message) { CodeView* view = getView(); - view->setErrorInfos(std::vector()); + view->clear(); - std::vector snippets = getSnippetsForFullTextSearch(message->searchTerm, message->caseSensitive); - view->showCodeSnippets(snippets, std::vector()); + m_collection = m_storageAccess->getFullTextSearchLocations(message->searchTerm, message->caseSensitive); + view->showCodeSnippets(getSnippetsForCollection(m_collection, true), std::vector()); showContents(message); } @@ -261,7 +268,8 @@ void CodeController::handleMessage(MessageShowScope* message) return; } - std::vector snippets = getSnippetsForActiveTokenLocations(collection.get(), 0); + std::vector snippets = + getSnippetsForFile(collection->getTokenLocationFiles().begin()->second, true); if (snippets.size() != 1) { LOG_ERROR("MessageShowScope didn't result in one single snippet to be created"); @@ -270,15 +278,21 @@ void CodeController::handleMessage(MessageShowScope* message) if (message->showErrors) { - std::vector errors; - std::vector errorSnippets = getSnippetsForErrorLocations(&errors); - - for (const CodeSnippetParams& error : errorSnippets) + snippets[0].locationFile = m_collection->getTokenLocationFileByPath(snippets[0].locationFile->getFilePath()); + } + else + { + TokenLocationFile* activeLocations = + m_collection->findTokenLocationFileByPath(snippets[0].locationFile->getFilePath()); + if (activeLocations) { - if (error.locationFile->getFilePath() == snippets[0].locationFile->getFilePath()) - { - snippets[0].locationFile = error.locationFile; - } + std::shared_ptr file = snippets[0].locationFile; + activeLocations->forEachTokenLocation( + [&file](TokenLocation* location) + { + file->addTokenLocationAsPlainCopy(location); + } + ); } } @@ -331,7 +345,7 @@ std::vector CodeController::getSnippetsForActiveTokenLocation (isDefinitionFile && definitionFileCount < 3) || (!isDefinitionFile && isDeclarationFile && declarationFileCount < 3)) { - std::vector fileSnippets = getSnippetsForActiveTokenLocationsInFile(file); + std::vector fileSnippets = getSnippetsForFile(file, true); for (CodeSnippetParams& snippet : fileSnippets) { @@ -369,43 +383,48 @@ std::vector CodeController::getSnippetsForActiveTokenLocation return snippets; } -std::vector CodeController::getSnippetsForActiveTokenLocationsInFile( - std::shared_ptr activeTokenLocations -) const { - std::shared_ptr fileLocations = m_storageAccess->getTokenLocationsForFile(activeTokenLocations->getFilePath().str()); - - std::vector fileSnippets = getSnippetsForFile(activeTokenLocations, fileLocations); - - if (!activeTokenLocations->isWholeCopy) - { - for (CodeSnippetParams& params : fileSnippets) - { - params.locationFile = fileLocations->getFilteredByLines(params.startLineNumber, params.endLineNumber); - } - } - - return fileSnippets; -} - -std::vector CodeController::getSnippetsForFile( - std::shared_ptr activeTokenLocations +std::vector CodeController::getSnippetsForCollection( + std::shared_ptr collection, bool addTokenLocations ) const { - return getSnippetsForFile( - activeTokenLocations, - m_storageAccess->getTokenLocationsForFile(activeTokenLocations->getFilePath().str()) + std::vector snippets; + + collection->forEachTokenLocationFile( + [&](std::shared_ptr file) -> void + { + if (snippets.size() < 10) + { + std::vector fileSnippets = getSnippetsForFile(file, addTokenLocations); + snippets.insert(snippets.end(), fileSnippets.begin(), fileSnippets.end()); + } + else + { + CodeSnippetParams params; + params.locationFile = file; + params.refCount = file->getUnscopedStartTokenLocationCount(); + + params.isCollapsed = true; + snippets.push_back(params); + } + } ); + + addModificationTimes(snippets); + + return snippets; } std::vector CodeController::getSnippetsForFile( - std::shared_ptr activeTokenLocations, - const std::shared_ptr fileLocations + std::shared_ptr activeTokenLocations, bool addTokenLocations ) const { std::shared_ptr textAccess = m_storageAccess->getFileContent(activeTokenLocations->getFilePath()); std::shared_ptr scopeLocations = std::make_shared(activeTokenLocations->getFilePath().str()); + std::shared_ptr fileLocations = + m_storageAccess->getTokenLocationsForFile(activeTokenLocations->getFilePath().str()); + fileLocations->forEachStartTokenLocation( [&](TokenLocation* startLoc) -> void { @@ -461,14 +480,16 @@ std::vector CodeController::getSnippetsForFile( const int snippetExpandRange = ApplicationSettings::getInstance()->getCodeSnippetExpandRange(); std::vector snippets; - std::shared_ptr file = m_storageAccess->getTokenLocationsForFile(activeTokenLocations->getFilePath().str()); + std::shared_ptr file = + m_storageAccess->getTokenLocationsForFile(activeTokenLocations->getFilePath().str()); for (const SnippetMerger::Range& range: ranges) { CodeSnippetParams params; params.locationFile = activeTokenLocations; params.refCount = activeTokenLocations->getUnscopedStartTokenLocationCount(); params.startLineNumber = std::max(1, range.start.row - (range.start.strong ? 0 : snippetExpandRange)); - params.endLineNumber = std::min(textAccess->getLineCount(), range.end.row + (range.end.strong ? 0 : snippetExpandRange)); + params.endLineNumber = + std::min(textAccess->getLineCount(), range.end.row + (range.end.strong ? 0 : snippetExpandRange)); std::shared_ptr tempFile = file->getFilteredByLines(params.startLineNumber, params.endLineNumber); TokenLocationLine* firstUsedLine = nullptr; @@ -525,6 +546,24 @@ std::vector CodeController::getSnippetsForFile( snippets.push_back(params); } + if (addTokenLocations && !activeTokenLocations->isWholeCopy) + { + for (CodeSnippetParams& params : snippets) + { + std::shared_ptr lines = + fileLocations->getFilteredByLines(params.startLineNumber, params.endLineNumber); + + params.locationFile->forEachTokenLocation( + [&lines](TokenLocation* location) + { + lines->addTokenLocationAsPlainCopy(location); + } + ); + + params.locationFile = lines; + } + } + return snippets; } @@ -605,79 +644,6 @@ std::shared_ptr CodeController::getTokenLocationOfParentScope return file; } -std::vector CodeController::getSnippetsForFullTextSearch( - const std::string& searchTerm, bool caseSensitive) const -{ - std::shared_ptr collection = - m_storageAccess->getFullTextSearchLocations(searchTerm, caseSensitive); - - std::vector snippets; - snippets.reserve(collection->getTokenLocationFileCount()); - - collection->forEachTokenLocationFile( - [&](std::shared_ptr file) -> void - { - //CodeSnippetParams params; - //params.locationFile = file; - //params.startLineNumber = 1; - - //std::shared_ptr textAccess = m_storageAccess->getFileContent(file->getFilePath()); - //params.code = textAccess->getText(); - - //snippets.push_back(params); - - //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.isCollapsed = true; - //snippets.push_back(params); - //} - } - ); - - addModificationTimes(snippets); - return snippets; -} - -std::vector CodeController::getSnippetsForErrorLocations( - std::vector* errors) const -{ - TokenLocationCollection errorCollection = m_storageAccess->getErrorTokenLocations(errors); - - std::vector snippets; - - errorCollection.forEachTokenLocationFile( - [&](std::shared_ptr file) -> void - { - 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.isCollapsed = true; - snippets.push_back(params); - } - } - ); - - addModificationTimes(snippets); - - return snippets; -} - std::vector CodeController::getProjectDescription(TokenLocationFile* locationFile) const { std::string description = ProjectSettings::getInstance()->getDescription(); diff --git a/src/lib/component/controller/CodeController.h b/src/lib/component/controller/CodeController.h index be61a6ac..55f98ef2 100644 --- a/src/lib/component/controller/CodeController.h +++ b/src/lib/component/controller/CodeController.h @@ -23,6 +23,7 @@ #include "component/view/CodeView.h" class StorageAccess; +class TokenLocation; class TokenLocationCollection; class TokenLocationFile; @@ -64,23 +65,23 @@ private: std::vector getSnippetsForActiveTokenLocations( const TokenLocationCollection* collection, Id declarationId) const; - std::vector getSnippetsForActiveTokenLocationsInFile( - std::shared_ptr) const; + std::vector getSnippetsForCollection( + std::shared_ptr collection, bool addTokenLocations = false) const; std::vector getSnippetsForFile( - std::shared_ptr activeTokenLocations, std::shared_ptr fileLocations) const; - std::vector getSnippetsForFile(std::shared_ptr file) const; - std::vector getSnippetsForFullTextSearch(const std::string& searchTerm, bool caseSensitive) const; - std::shared_ptr buildMergerHierarchy( - 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::shared_ptr file, bool addTokenLocations = false) const; - std::vector getSnippetsForErrorLocations(std::vector* errors) const; + std::shared_ptr buildMergerHierarchy( + 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 getProjectDescription(TokenLocationFile* locationFile) const; void addModificationTimes(std::vector& snippets) const; StorageAccess* m_storageAccess; + mutable std::shared_ptr m_collection; }; #endif // CODE_CONTROLLER_H diff --git a/src/lib/data/PersistentStorage.cpp b/src/lib/data/PersistentStorage.cpp index 1c60f59c..d45835e6 100644 --- a/src/lib/data/PersistentStorage.cpp +++ b/src/lib/data/PersistentStorage.cpp @@ -450,7 +450,7 @@ std::shared_ptr PersistentStorage::getFullTextSearchLoc if ( addHit ) { collection->addTokenLocation( - i, + collection->getTokenLocationCount(), 0, filepath, location.startLineNumber, @@ -935,16 +935,17 @@ std::shared_ptr PersistentStorage::getTokenLocationsForLinesI return m_sqliteStorage.getTokenLocationsForFile(filePath)->getFilteredByLines(firstLineNumber, lastLineNumber); } -TokenLocationCollection PersistentStorage::getErrorTokenLocations(std::vector* errors) const +std::shared_ptr PersistentStorage::getErrorTokenLocations(std::vector* errors) const { - TokenLocationCollection errorCollection; + std::shared_ptr errorCollection = std::make_shared(); std::vector storageErrors = m_sqliteStorage.getAllErrors(); for (size_t i = 0; i < storageErrors.size(); i++) { const StorageError& error = storageErrors[i]; - errorCollection.addTokenLocation( - i, i, error.filePath, error.lineNumber, error.columnNumber, error.lineNumber, error.columnNumber); + errorCollection->addTokenLocation( + i, i, error.filePath, error.lineNumber, error.columnNumber, error.lineNumber, error.columnNumber + )->setType(LOCATION_ERROR); errors->push_back(ErrorInfo(error.message, error.filePath, i, error.fatal)); } diff --git a/src/lib/data/PersistentStorage.h b/src/lib/data/PersistentStorage.h index 180033fe..be76dc39 100644 --- a/src/lib/data/PersistentStorage.h +++ b/src/lib/data/PersistentStorage.h @@ -104,7 +104,7 @@ public: const std::string& filePath, uint firstLineNumber, uint lastLineNumber ) const; - virtual TokenLocationCollection getErrorTokenLocations(std::vector* errors) const; + virtual std::shared_ptr 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 56d023e0..a2bde00e 100644 --- a/src/lib/data/access/StorageAccess.h +++ b/src/lib/data/access/StorageAccess.h @@ -59,7 +59,7 @@ public: virtual std::shared_ptr getTokenLocationsForLinesInFile( const std::string& filePath, uint firstLineNumber, uint lastLineNumber) const = 0; - virtual TokenLocationCollection getErrorTokenLocations(std::vector* errors) const = 0; + virtual std::shared_ptr 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 2ceb965b..4fc9f27d 100644 --- a/src/lib/data/access/StorageAccessProxy.cpp +++ b/src/lib/data/access/StorageAccessProxy.cpp @@ -218,14 +218,14 @@ std::shared_ptr StorageAccessProxy::getTokenLocationsForLines return std::make_shared(""); } -TokenLocationCollection StorageAccessProxy::getErrorTokenLocations(std::vector* errors) const +std::shared_ptr StorageAccessProxy::getErrorTokenLocations(std::vector* errors) const { if (hasSubject()) { return m_subject->getErrorTokenLocations(errors); } - return TokenLocationCollection(); + return std::make_shared(); } std::shared_ptr StorageAccessProxy::getCommentLocationsInFile(const FilePath& filePath) const diff --git a/src/lib/data/access/StorageAccessProxy.h b/src/lib/data/access/StorageAccessProxy.h index 241d987c..eeb35ef4 100644 --- a/src/lib/data/access/StorageAccessProxy.h +++ b/src/lib/data/access/StorageAccessProxy.h @@ -47,7 +47,7 @@ public: const std::string& filePath, uint firstLineNumber, uint lastLineNumber ) const; - virtual TokenLocationCollection getErrorTokenLocations(std::vector* errors) const; + virtual std::shared_ptr 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/location/LocationType.cpp b/src/lib/data/location/LocationType.cpp index 2cbbff42..ea932f05 100644 --- a/src/lib/data/location/LocationType.cpp +++ b/src/lib/data/location/LocationType.cpp @@ -12,6 +12,8 @@ int locationTypeToInt(LocationType type) return 2; case LOCATION_FULLTEXT: return 3; + case LOCATION_ERROR: + return 4; } } @@ -27,6 +29,8 @@ LocationType intToLocationType(int value) return LOCATION_LOCAL_SYMBOL; case 3: return LOCATION_FULLTEXT; + case 4: + return LOCATION_ERROR; } return LOCATION_TOKEN; } diff --git a/src/lib/data/location/LocationType.h b/src/lib/data/location/LocationType.h index fea30ebb..52ca50be 100644 --- a/src/lib/data/location/LocationType.h +++ b/src/lib/data/location/LocationType.h @@ -6,7 +6,8 @@ enum LocationType LOCATION_TOKEN, LOCATION_SCOPE, LOCATION_LOCAL_SYMBOL, - LOCATION_FULLTEXT + LOCATION_FULLTEXT, + LOCATION_ERROR }; int locationTypeToInt(LocationType type); diff --git a/src/lib/data/location/TokenLocationCollection.cpp b/src/lib/data/location/TokenLocationCollection.cpp index 1f8e146f..9eacfe01 100644 --- a/src/lib/data/location/TokenLocationCollection.cpp +++ b/src/lib/data/location/TokenLocationCollection.cpp @@ -22,6 +22,22 @@ const TokenLocationCollection::TokenLocationFileMapType& TokenLocationCollection return m_files; } +const std::map& TokenLocationCollection::getTokenLocations() const +{ + return m_locations; +} + +std::shared_ptr TokenLocationCollection::getTokenLocationFileByPath(const FilePath& filePath) const +{ + std::map>::const_iterator it = m_files.find(filePath); + if (it != m_files.end()) + { + return it->second; + } + + return nullptr; +} + size_t TokenLocationCollection::getTokenLocationFileCount() const { return m_files.size(); @@ -39,11 +55,6 @@ size_t TokenLocationCollection::getTokenLocationLineCount() const return count; } -const std::map& TokenLocationCollection::getTokenLocations() const -{ - return m_locations; -} - size_t TokenLocationCollection::getTokenLocationCount() const { return m_locations.size(); @@ -101,13 +112,7 @@ TokenLocation* TokenLocationCollection::findTokenLocationById(Id id) const TokenLocationFile* TokenLocationCollection::findTokenLocationFileByPath(const FilePath& filePath) const { - std::map>::const_iterator it = m_files.find(filePath); - if (it != m_files.end()) - { - return it->second.get(); - } - - return nullptr; + return getTokenLocationFileByPath(filePath).get(); } void TokenLocationCollection::forEachTokenLocationFile(std::function)> func) const diff --git a/src/lib/data/location/TokenLocationCollection.h b/src/lib/data/location/TokenLocationCollection.h index fe2beca7..4b1f40cd 100644 --- a/src/lib/data/location/TokenLocationCollection.h +++ b/src/lib/data/location/TokenLocationCollection.h @@ -24,11 +24,12 @@ public: ~TokenLocationCollection(); const TokenLocationFileMapType& getTokenLocationFiles() const; - size_t getTokenLocationFileCount() const; - - size_t getTokenLocationLineCount() const; - const std::map& getTokenLocations() const; + + std::shared_ptr getTokenLocationFileByPath(const FilePath& filePath) const; + + size_t getTokenLocationFileCount() const; + size_t getTokenLocationLineCount() const; size_t getTokenLocationCount() const; TokenLocation* addTokenLocation( diff --git a/src/lib/data/location/TokenLocationFile.cpp b/src/lib/data/location/TokenLocationFile.cpp index 577fcaf5..759ff410 100644 --- a/src/lib/data/location/TokenLocationFile.cpp +++ b/src/lib/data/location/TokenLocationFile.cpp @@ -128,11 +128,11 @@ void TokenLocationFile::forEachEndTokenLocation(std::functiongetTokenLocationLine()->getLineNumber(); + unsigned int lineNumber = location->getLineNumber(); TokenLocationLine* line = createTokenLocationLine(lineNumber); // Check whether this location was already added or if the other TokenLocation was added. - TokenLocation* otherLocation = line->getTokenLocationById(location->getId()); + TokenLocation* otherLocation = line->getTokenLocationByIdAndType(location->getId(), location->getType()); if (otherLocation) { if (otherLocation->isStartTokenLocation() == location->isStartTokenLocation()) @@ -144,13 +144,13 @@ TokenLocation* TokenLocationFile::addTokenLocationAsPlainCopy(const TokenLocatio else { // Look for the other location in it's line. - unsigned int otherLineNumber = location->getOtherTokenLocation()->getTokenLocationLine()->getLineNumber(); + unsigned int otherLineNumber = location->getOtherTokenLocation()->getLineNumber(); if (lineNumber != otherLineNumber) { TokenLocationLine* otherLine = findTokenLocationLine(otherLineNumber); if (otherLine) { - otherLocation = otherLine->getTokenLocationById(location->getId()); + otherLocation = otherLine->getTokenLocationByIdAndType(location->getId(), location->getType()); } } } diff --git a/src/lib/data/location/TokenLocationLine.cpp b/src/lib/data/location/TokenLocationLine.cpp index aa9b8814..c6da5d49 100644 --- a/src/lib/data/location/TokenLocationLine.cpp +++ b/src/lib/data/location/TokenLocationLine.cpp @@ -71,11 +71,11 @@ void TokenLocationLine::removeTokenLocation(TokenLocation* location) LOG_ERROR("TokenLocation can't be removed, it's not part of the TokenLocationLine."); } -TokenLocation* TokenLocationLine::getTokenLocationById(Id id) const +TokenLocation* TokenLocationLine::getTokenLocationByIdAndType(Id id, LocationType type) const { for (const TokenLocationPairType& p : m_locations) { - if (p.second->getId() == id) + if (p.second->getId() == id && p.second->getType() == type) { return p.second.get(); } diff --git a/src/lib/data/location/TokenLocationLine.h b/src/lib/data/location/TokenLocationLine.h index 42d63ce3..30c08dda 100644 --- a/src/lib/data/location/TokenLocationLine.h +++ b/src/lib/data/location/TokenLocationLine.h @@ -7,6 +7,8 @@ #include #include +#include "data/location/LocationType.h" + #include "utility/file/FilePath.h" #include "utility/types.h" @@ -34,7 +36,7 @@ public: TokenLocation* addEndTokenLocation(TokenLocation* start, unsigned int columnNumber); void removeTokenLocation(TokenLocation* location); - TokenLocation* getTokenLocationById(Id id) const; + TokenLocation* getTokenLocationByIdAndType(Id id, LocationType type) const; void forEachTokenLocation(std::function func) const; void forEachStartTokenLocation(std::function func) const; diff --git a/src/lib/utility/messaging/type/MessageChangeFileView.h b/src/lib/utility/messaging/type/MessageChangeFileView.h index 7bea9cde..47139286 100644 --- a/src/lib/utility/messaging/type/MessageChangeFileView.h +++ b/src/lib/utility/messaging/type/MessageChangeFileView.h @@ -1,11 +1,10 @@ #ifndef MESSAGE_CHANGE_FILE_VIEW_H #define MESSAGE_CHANGE_FILE_VIEW_H +#include "utility/file/FilePath.h" #include "utility/messaging/Message.h" #include "utility/types.h" -#include "data/location/TokenLocationFile.h" - class MessageChangeFileView : public Message { @@ -21,14 +20,12 @@ public: const FilePath filePath, FileState state, bool needsData, - bool showErrors, - std::shared_ptr locationFile + bool showErrors ) : filePath(filePath) , state(state) , needsData(needsData) , showErrors(showErrors) - , locationFile(locationFile) { } @@ -57,8 +54,6 @@ public: bool needsData; bool showErrors; - - std::shared_ptr locationFile; }; #endif // MESSAGE_CHANGE_FILE_VIEW_H diff --git a/src/lib_gui/qt/element/QtCodeArea.cpp b/src/lib_gui/qt/element/QtCodeArea.cpp index 95d9bf01..365d05be 100644 --- a/src/lib_gui/qt/element/QtCodeArea.cpp +++ b/src/lib_gui/qt/element/QtCodeArea.cpp @@ -433,10 +433,10 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event) m_eventPosition = event->pos(); setIDECursorPosition(); } - else if (!m_fileWidget->hasErrors()) + else { QTextCursor cursor = this->cursorForPosition(event->pos()); - std::vector annotations = getNonScopeAnnotationsForPosition(cursor.position()); + std::vector annotations = getInteractiveAnnotationsForPosition(cursor.position()); activateTokenLocations(annotations); activateLocalSymbols(annotations); @@ -464,7 +464,7 @@ void QtCodeArea::mouseMoveEvent(QMouseEvent* event) QTextCursor cursor = this->cursorForPosition(event->pos()); - std::vector annotations = getNonScopeAnnotationsForPosition(cursor.position()); + std::vector annotations = getInteractiveAnnotationsForPosition(cursor.position()); bool same = annotations.size() == m_hoveredAnnotations.size(); if (same) @@ -541,13 +541,15 @@ void QtCodeArea::setIDECursorPosition() MessageMoveIDECursor(m_locationFile->getFilePath().str(), lineColumn.first, lineColumn.second).dispatch(); } -std::vector QtCodeArea::getNonScopeAnnotationsForPosition(int pos) const +std::vector QtCodeArea::getInteractiveAnnotationsForPosition(int pos) const { std::vector annotations; for (const Annotation& annotation : m_annotations) { - if (annotation.locationType != LOCATION_SCOPE && pos >= annotation.start && pos <= annotation.end) + const LocationType& type = annotation.locationType; + if ((type == LOCATION_TOKEN || type == LOCATION_LOCAL_SYMBOL || type == LOCATION_ERROR) + && pos >= annotation.start && pos <= annotation.end) { annotations.push_back(&annotation); } @@ -674,7 +676,6 @@ void QtCodeArea::createAnnotations(std::shared_ptr locationFi annotation.locationId = startLocation->getId(); annotation.locationType = startLocation->getType(); - annotation.isError = false; annotation.isActive = false; annotation.isFocused = false; @@ -690,8 +691,6 @@ void QtCodeArea::annotateText() const std::vector& activeLocalSymbolIds = m_fileWidget->getActiveLocalSymbolIds(); const std::vector& focusIds = m_fileWidget->getFocusedTokenIds(); - bool isError = m_fileWidget->hasErrors(); - bool needsUpdate = false; for (Annotation& annotation: m_annotations) { @@ -705,8 +704,6 @@ void QtCodeArea::annotateText() ); annotation.isFocused = std::find(focusIds.begin(), focusIds.end(), annotation.tokenId) != focusIds.end(); - annotation.isError = isError; - const AnnotationColor& newColor = getAnnotationColorForAnnotation(annotation); if ((newColor.text != oldColor.text || !m_wasAnnotated)) { @@ -933,7 +930,7 @@ const QtCodeArea::AnnotationColor& QtCodeArea::getAnnotationColorForAnnotation(c { i = 6; } - else if (annotation.isError) + else if (annotation.locationType == LOCATION_ERROR) { i = 9; } diff --git a/src/lib_gui/qt/element/QtCodeArea.h b/src/lib_gui/qt/element/QtCodeArea.h index 0b756aa7..0f3f3267 100644 --- a/src/lib_gui/qt/element/QtCodeArea.h +++ b/src/lib_gui/qt/element/QtCodeArea.h @@ -126,7 +126,6 @@ private: Id locationId; LocationType locationType; - bool isError; bool isActive; bool isFocused; @@ -141,7 +140,7 @@ private: std::string text; }; - std::vector getNonScopeAnnotationsForPosition(int pos) const; + std::vector getInteractiveAnnotationsForPosition(int pos) const; void activateTokenLocations(const std::vector& annotations); void activateLocalSymbols(const std::vector& annotations); diff --git a/src/lib_gui/qt/element/QtCodeFile.cpp b/src/lib_gui/qt/element/QtCodeFile.cpp index b8d41ae1..eb50e5b8 100644 --- a/src/lib_gui/qt/element/QtCodeFile.cpp +++ b/src/lib_gui/qt/element/QtCodeFile.cpp @@ -431,8 +431,7 @@ void QtCodeFile::clickedMinimizeButton() const m_filePath, MessageChangeFileView::FILE_MINIMIZED, false, - hasErrors(), - nullptr + hasErrors() ).dispatch(); } @@ -442,8 +441,7 @@ void QtCodeFile::clickedSnippetButton() const m_filePath, MessageChangeFileView::FILE_SNIPPETS, (m_locationFile != nullptr), - hasErrors(), - m_locationFile + hasErrors() ).dispatch(); } @@ -453,8 +451,7 @@ void QtCodeFile::clickedMaximizeButton() const m_filePath, MessageChangeFileView::FILE_MAXIMIZED, (m_fileSnippet == nullptr), - hasErrors(), - nullptr + hasErrors() ).dispatch(); } @@ -471,8 +468,7 @@ void QtCodeFile::requestSnippets() const m_filePath, MessageChangeFileView::FILE_SNIPPETS, (m_locationFile != nullptr), - hasErrors(), - m_locationFile + hasErrors() ); msg.setIsReplayed(true); diff --git a/src/lib_gui/qt/view/QtCodeView.cpp b/src/lib_gui/qt/view/QtCodeView.cpp index 831c9a3e..7576c4d7 100644 --- a/src/lib_gui/qt/view/QtCodeView.cpp +++ b/src/lib_gui/qt/view/QtCodeView.cpp @@ -51,6 +51,9 @@ void QtCodeView::refreshView() void QtCodeView::clear() { m_clearFunctor(); + + m_errorInfos.clear(); + m_activeTokenIds.clear(); } void QtCodeView::setActiveTokenIds(const std::vector& activeTokenIds) @@ -134,9 +137,9 @@ void QtCodeView::doClear() void QtCodeView::doShowCodeSnippets(const std::vector& snippets, const std::vector& activeTokenIds) { - m_widget->clearCodeSnippets(); + setActiveTokenIds(activeTokenIds); - m_widget->setActiveTokenIds(activeTokenIds); + m_widget->setActiveTokenIds(m_activeTokenIds); m_widget->setErrorInfos(m_errorInfos); for (const CodeSnippetParams& params : snippets)