diff --git a/bin/test/data/log/test_log.txt b/bin/test/data/log/test_log.txt index 0debded1..59996dfc 100644 --- a/bin/test/data/log/test_log.txt +++ b/bin/test/data/log/test_log.txt @@ -53,7 +53,7 @@ TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8 TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8 TextAccess.cpp WARNING: Line numbers start with one, is 0 TextAccess.cpp WARNING: Line numbers start with one, is 0 -TokenLocationCollection.cpp ERROR: Can't create TokenLocation with wrong boundaries. -TokenLocationCollection.cpp ERROR: Can't create TokenLocation with wrong boundaries. +TokenLocationCollection.cpp ERROR: TokenLocation has wrong boundaries: file.c 2:3 2:1 +TokenLocationCollection.cpp ERROR: TokenLocation has wrong boundaries: file.c 4:1 1:10 SolutionParserVisualStudio.cpp INFO: Found 24 additional include paths SolutionParserVisualStudio.cpp INFO: Found 450 code files diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 53a447ed..87f84fbb 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -116,6 +116,8 @@ void Application::createAndLoadProject(const FilePath& projectSettingsFilePath) void Application::loadProject(const FilePath& projectSettingsFilePath) { + m_componentManager->clearComponents(); + bool reparse = false; Project::ProjectState state = m_project->load(projectSettingsFilePath); diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index e0a82a31..7364b9d1 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -142,8 +142,6 @@ void Project::parseCode() return; } - std::shared_ptr projSettings = ProjectSettings::getInstance(); - m_fileManager.fetchFilePaths(m_storage->getInfoOnAllFiles()); std::set addedFilePaths = m_fileManager.getAddedFilePaths(); std::set updatedFilePaths = m_fileManager.getUpdatedFilePaths(); @@ -164,7 +162,10 @@ void Project::parseCode() filesToParse.insert(filesToParse.end(), addedFilePaths.begin(), addedFilePaths.end()); filesToParse.insert(filesToParse.end(), updatedFilePaths.begin(), updatedFilePaths.end()); - std::shared_ptr fileRegister = std::make_shared(&m_fileManager); + + int indexerThreadCount = ApplicationSettings::getInstance()->getIndexerThreadCount(); + + std::shared_ptr fileRegister = std::make_shared(&m_fileManager, indexerThreadCount > 1); fileRegister->setFilePaths(filesToParse); std::shared_ptr taskParallel = std::make_shared(); @@ -177,7 +178,7 @@ void Project::parseCode() std::shared_ptr storageMutex = std::make_shared(); - for (int i = 0; i < ApplicationSettings::getInstance()->getIndexerThreadCount(); i++) + for (int i = 0; i < indexerThreadCount; i++) { taskParallel->addTask(std::make_shared( m_storage.get(), diff --git a/src/lib/component/ComponentManager.cpp b/src/lib/component/ComponentManager.cpp index a6b7341e..7d3fdb18 100644 --- a/src/lib/component/ComponentManager.cpp +++ b/src/lib/component/ComponentManager.cpp @@ -2,6 +2,7 @@ #include "component/controller/NetworkFactory.h" +#include "component/controller/Controller.h" #include "component/view/CodeView.h" #include "component/view/CompositeView.h" #include "component/view/GraphView.h" @@ -51,6 +52,19 @@ void ComponentManager::setup(ViewLayout* viewLayout) m_components.push_back(featureComponent); } +void ComponentManager::clearComponents() +{ + for (std::shared_ptr component : m_components) + { + Controller* controller = component->getController(); + + if (controller) + { + controller->clear(); + } + } +} + void ComponentManager::refreshViews() { for (std::shared_ptr component : m_components) diff --git a/src/lib/component/ComponentManager.h b/src/lib/component/ComponentManager.h index 5195b2cc..13b07317 100644 --- a/src/lib/component/ComponentManager.h +++ b/src/lib/component/ComponentManager.h @@ -23,6 +23,7 @@ public: void setup(ViewLayout* viewLayout); + void clearComponents(); void refreshViews(); private: diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index 0166a04a..d72f54a9 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -103,8 +103,12 @@ void CodeController::handleMessage(MessageActivateTokens* message) } std::vector activeTokenIds = message->tokenIds; - Id declarationId = 0; // 0 means that no token is found. + if (!activeTokenIds.size()) + { + return; + } + Id declarationId = 0; // 0 means that no token is found. if (!message->isAggregation) { activeTokenIds = m_storageAccess->getActiveTokenIdsForId(activeTokenIds[0], &declarationId); @@ -306,6 +310,13 @@ CodeView* CodeController::getView() return Controller::getView(); } +void CodeController::clear() +{ + getView()->clear(); + + m_collection.reset(); +} + void CodeController::showContents(MessageBase* message) { if (!message->isReplayed()) diff --git a/src/lib/component/controller/CodeController.h b/src/lib/component/controller/CodeController.h index 55f98ef2..96ff7c58 100644 --- a/src/lib/component/controller/CodeController.h +++ b/src/lib/component/controller/CodeController.h @@ -61,6 +61,9 @@ private: virtual void handleMessage(MessageShowScope* message); CodeView* getView(); + + virtual void clear(); + void showContents(MessageBase* message); std::vector getSnippetsForActiveTokenLocations( diff --git a/src/lib/component/controller/Controller.h b/src/lib/component/controller/Controller.h index 4a4d9080..4e546e52 100644 --- a/src/lib/component/controller/Controller.h +++ b/src/lib/component/controller/Controller.h @@ -11,13 +11,14 @@ public: void setComponent(Component* component); + virtual void clear() = 0; + protected: template - ViewType* getView() const; + ViewType* getView() const; private: Component* m_component; - }; @@ -25,8 +26,11 @@ template ViewType* Controller::getView() const { if (m_component) + { return m_component->getView(); - return NULL; + } + + return nullptr; } #endif // CONTROLLER_H diff --git a/src/lib/component/controller/FeatureController.cpp b/src/lib/component/controller/FeatureController.cpp index 8838e9e2..bc4b4e6a 100644 --- a/src/lib/component/controller/FeatureController.cpp +++ b/src/lib/component/controller/FeatureController.cpp @@ -19,6 +19,10 @@ FeatureController::~FeatureController() { } +void FeatureController::clear() +{ +} + void FeatureController::handleMessage(MessageActivateEdge* message) { if (message->isAggregation()) @@ -61,9 +65,15 @@ void FeatureController::handleMessage(MessageActivateFile* message) } else { - MessageActivateTokens m(message, std::vector()); - m.unknownNames.push_back(message->filePath.fileName()); - m.dispatchImmediately(); + MessageChangeFileView msg( + message->filePath, + MessageChangeFileView::FILE_MAXIMIZED, + true, + true + ); + msg.setIsReplayed(message->isReplayed()); + msg.setKeepContent(message->keepContent()); + msg.dispatchImmediately(); } } diff --git a/src/lib/component/controller/FeatureController.h b/src/lib/component/controller/FeatureController.h index 739fe751..ad975a03 100644 --- a/src/lib/component/controller/FeatureController.h +++ b/src/lib/component/controller/FeatureController.h @@ -34,6 +34,8 @@ public: FeatureController(StorageAccess* storageAccess); ~FeatureController(); + virtual void clear(); + private: virtual void handleMessage(MessageActivateEdge* message); virtual void handleMessage(MessageActivateFile* message); diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index d271c353..25005bb0 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -186,6 +186,7 @@ void GraphController::clear() m_activeEdgeIds.clear(); m_graph.reset(); + getView()->clear(); } diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index dda20bdb..30c4b2a0 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -58,7 +58,7 @@ private: GraphView* getView() const; - void clear(); + virtual void clear(); void createDummyGraphForTokenIds(const std::vector& tokenIds, const std::shared_ptr graph); std::shared_ptr createDummyNodeTopDown(Node* node, Id parentId); diff --git a/src/lib/component/controller/IDECommunicationController.cpp b/src/lib/component/controller/IDECommunicationController.cpp index e3479bc1..9fb17749 100644 --- a/src/lib/component/controller/IDECommunicationController.cpp +++ b/src/lib/component/controller/IDECommunicationController.cpp @@ -24,6 +24,10 @@ IDECommunicationController::~IDECommunicationController() { } +void IDECommunicationController::clear() +{ +} + void IDECommunicationController::handleIncomingMessage(const std::string& message) { if (m_enabled == false) diff --git a/src/lib/component/controller/IDECommunicationController.h b/src/lib/component/controller/IDECommunicationController.h index f0a8b531..55d48fde 100644 --- a/src/lib/component/controller/IDECommunicationController.h +++ b/src/lib/component/controller/IDECommunicationController.h @@ -20,6 +20,8 @@ public: IDECommunicationController(StorageAccess* storageAccess); virtual ~IDECommunicationController(); + virtual void clear(); + void handleIncomingMessage(const std::string& message); bool getEnabled() const; diff --git a/src/lib/component/controller/RefreshController.cpp b/src/lib/component/controller/RefreshController.cpp index 8f880cc2..22bb45e8 100644 --- a/src/lib/component/controller/RefreshController.cpp +++ b/src/lib/component/controller/RefreshController.cpp @@ -13,6 +13,10 @@ RefreshController::~RefreshController() { } +void RefreshController::clear() +{ +} + void RefreshController::handleMessage(MessageAutoRefreshChanged* message) { m_autoRefreshEnabled = message->enabled; diff --git a/src/lib/component/controller/RefreshController.h b/src/lib/component/controller/RefreshController.h index ae19f909..a5e62b7a 100644 --- a/src/lib/component/controller/RefreshController.h +++ b/src/lib/component/controller/RefreshController.h @@ -17,6 +17,8 @@ public: RefreshController(); virtual ~RefreshController(); + virtual void clear(); + private: virtual void handleMessage(MessageAutoRefreshChanged* message); virtual void handleMessage(MessageWindowFocus* message); diff --git a/src/lib/component/controller/SearchController.cpp b/src/lib/component/controller/SearchController.cpp index d4b22424..7095dbd9 100644 --- a/src/lib/component/controller/SearchController.cpp +++ b/src/lib/component/controller/SearchController.cpp @@ -79,3 +79,8 @@ SearchView* SearchController::getView() { return Controller::getView(); } + +void SearchController::clear() +{ + getView()->setMatches(std::vector()); +} diff --git a/src/lib/component/controller/SearchController.h b/src/lib/component/controller/SearchController.h index e7ec49c6..3644166b 100644 --- a/src/lib/component/controller/SearchController.h +++ b/src/lib/component/controller/SearchController.h @@ -36,6 +36,8 @@ private: SearchView* getView(); + virtual void clear(); + StorageAccess* m_storageAccess; }; diff --git a/src/lib/component/controller/StatusBarController.cpp b/src/lib/component/controller/StatusBarController.cpp index 4e290285..15c32bc9 100644 --- a/src/lib/component/controller/StatusBarController.cpp +++ b/src/lib/component/controller/StatusBarController.cpp @@ -18,6 +18,12 @@ StatusBarView* StatusBarController::getView() return Controller::getView(); } +void StatusBarController::clear() +{ + getView()->setErrorCount(ErrorCountInfo()); + getView()->showMessage("", false, false); +} + void StatusBarController::handleMessage(MessageClearErrorCount* message) { getView()->setErrorCount(ErrorCountInfo()); diff --git a/src/lib/component/controller/StatusBarController.h b/src/lib/component/controller/StatusBarController.h index ba722e26..60320819 100644 --- a/src/lib/component/controller/StatusBarController.h +++ b/src/lib/component/controller/StatusBarController.h @@ -27,6 +27,8 @@ public: StatusBarView* getView(); + virtual void clear(); + private: virtual void handleMessage(MessageClearErrorCount* message); virtual void handleMessage(MessageFinishedParsing* message); diff --git a/src/lib/component/controller/UndoRedoController.cpp b/src/lib/component/controller/UndoRedoController.cpp index ebd9f605..fe9ee3f6 100644 --- a/src/lib/component/controller/UndoRedoController.cpp +++ b/src/lib/component/controller/UndoRedoController.cpp @@ -22,6 +22,15 @@ UndoRedoView* UndoRedoController::getView() return Controller::getView(); } +void UndoRedoController::clear() +{ + m_list.clear(); + m_iterator = m_list.begin(); + + getView()->setUndoButtonEnabled(false); + getView()->setRedoButtonEnabled(false); +} + UndoRedoController::Command::Command(std::shared_ptr message, Order order, bool replayLastOnly) : message(message) , order(order) @@ -143,11 +152,6 @@ void UndoRedoController::handleMessage(MessageGraphNodeMove* message) processCommand(command); } -void UndoRedoController::handleMessage(MessageLoadProject* message) -{ - clear(); -} - void UndoRedoController::handleMessage(MessageRedo* message) { if (m_iterator == m_list.end()) @@ -326,6 +330,11 @@ void UndoRedoController::replayCommands(std::list::iterator it) void UndoRedoController::processCommand(Command command) { + if (command.order != Command::ORDER_ACTIVATE && m_iterator == m_list.begin()) + { + return; + } + if (command.order == Command::ORDER_ACTIVATE && command.message->keepContent()) { command.order = Command::ORDER_ADAPT; @@ -369,15 +378,6 @@ void UndoRedoController::processCommand(Command command) } } -void UndoRedoController::clear() -{ - m_list.clear(); - m_iterator = m_list.end(); - - getView()->setUndoButtonEnabled(false); - getView()->setRedoButtonEnabled(false); -} - bool UndoRedoController::sameMessageTypeAsLast(MessageBase* message) const { if (!m_list.size() || m_list.begin() == m_iterator) diff --git a/src/lib/component/controller/UndoRedoController.h b/src/lib/component/controller/UndoRedoController.h index c88dc20c..1c5e5bc3 100644 --- a/src/lib/component/controller/UndoRedoController.h +++ b/src/lib/component/controller/UndoRedoController.h @@ -15,7 +15,6 @@ #include "utility/messaging/type/MessageGraphNodeBundleSplit.h" #include "utility/messaging/type/MessageGraphNodeExpand.h" #include "utility/messaging/type/MessageGraphNodeMove.h" -#include "utility/messaging/type/MessageLoadProject.h" #include "utility/messaging/type/MessageRedo.h" #include "utility/messaging/type/MessageRefresh.h" #include "utility/messaging/type/MessageScrollCode.h" @@ -41,7 +40,6 @@ class UndoRedoController , public MessageListener , public MessageListener , public MessageListener - , public MessageListener , public MessageListener , public MessageListener , public MessageListener @@ -56,6 +54,8 @@ public: UndoRedoView* getView(); + virtual void clear(); + private: struct Command { @@ -83,7 +83,6 @@ private: virtual void handleMessage(MessageGraphNodeBundleSplit* message); virtual void handleMessage(MessageGraphNodeExpand* message); virtual void handleMessage(MessageGraphNodeMove* message); - virtual void handleMessage(MessageLoadProject* message); virtual void handleMessage(MessageRedo* message); virtual void handleMessage(MessageRefresh* message); virtual void handleMessage(MessageScrollCode* message); @@ -97,8 +96,6 @@ private: void processCommand(Command command); - void clear(); - bool sameMessageTypeAsLast(MessageBase* message) const; MessageBase* lastMessage() const; diff --git a/src/lib/data/PersistentStorage.cpp b/src/lib/data/PersistentStorage.cpp index d45835e6..edd9df41 100644 --- a/src/lib/data/PersistentStorage.cpp +++ b/src/lib/data/PersistentStorage.cpp @@ -869,9 +869,7 @@ std::shared_ptr PersistentStorage::getTokenLocationsFor for (Id fileId: fileIds) { StorageFile storageFile = m_sqliteStorage.getFileById(fileId); - collection->addTokenLocationFileAsPlainCopy( - m_sqliteStorage.getTokenLocationsForFile(storageFile.filePath).get() - ); + collection->addTokenLocationFile(m_sqliteStorage.getTokenLocationsForFile(storageFile.filePath)); } std::vector locations = m_sqliteStorage.getTokenLocationsForElementIds(nonFileIds); @@ -923,16 +921,14 @@ std::shared_ptr PersistentStorage::getTokenLocationsFor std::shared_ptr PersistentStorage::getTokenLocationsForFile(const std::string& filePath) const { - std::shared_ptr locationFile = m_sqliteStorage.getTokenLocationsForFile(filePath); - locationFile->isWholeCopy = true; - return locationFile; + return m_sqliteStorage.getTokenLocationsForFile(filePath); } std::shared_ptr PersistentStorage::getTokenLocationsForLinesInFile( const std::string& filePath, uint firstLineNumber, uint lastLineNumber ) const { - return m_sqliteStorage.getTokenLocationsForFile(filePath)->getFilteredByLines(firstLineNumber, lastLineNumber); + return getTokenLocationsForFile(filePath)->getFilteredByLines(firstLineNumber, lastLineNumber); } std::shared_ptr PersistentStorage::getErrorTokenLocations(std::vector* errors) const diff --git a/src/lib/data/SqliteStorage.cpp b/src/lib/data/SqliteStorage.cpp index 21b49b9f..3678da9a 100644 --- a/src/lib/data/SqliteStorage.cpp +++ b/src/lib/data/SqliteStorage.cpp @@ -504,6 +504,8 @@ std::shared_ptr SqliteStorage::getTokenLocationsForFile(const loc->setType(intToLocationType(location.type)); } + ret->isWholeCopy = true; + return ret; } @@ -661,7 +663,7 @@ void SqliteStorage::setupTables() ); // TODO: move to createIndexesForAnalysis() or prepareForAnalysis - m_database.execDML( // used for checking for duplicates during code analysis + m_database.execDML( // used for checking for duplicates during code analysis "CREATE INDEX IF NOT EXISTS edge_multipart_index ON edge(type, source_node_id, target_node_id);" ); diff --git a/src/lib/data/location/TokenLocationCollection.cpp b/src/lib/data/location/TokenLocationCollection.cpp index 9eacfe01..dc07a645 100644 --- a/src/lib/data/location/TokenLocationCollection.cpp +++ b/src/lib/data/location/TokenLocationCollection.cpp @@ -67,13 +67,21 @@ TokenLocation* TokenLocationCollection::addTokenLocation( { if (startLineNumber > endLineNumber || (startLineNumber == endLineNumber && startColumnNumber > endColumnNumber)) { - LOG_ERROR("Can't create TokenLocation with wrong boundaries."); + LOG_ERROR_STREAM(<< "TokenLocation has wrong boundaries: "<< filePath.str() << " " + << startLineNumber << ":" << startColumnNumber << " " + << endLineNumber << ":" << endColumnNumber); return nullptr; } + TokenLocation* location = findTokenLocationById(locationId); + if (location) + { + return location; + } + TokenLocationFile* file = createTokenLocationFile(filePath); - TokenLocation* location = - file->addTokenLocation(locationId, tokenId, startLineNumber, startColumnNumber, endLineNumber, endColumnNumber); + location = file->addTokenLocation( + locationId, tokenId, startLineNumber, startColumnNumber, endLineNumber, endColumnNumber); m_locations.emplace(location->getId(), location); return location; @@ -98,6 +106,37 @@ void TokenLocationCollection::removeTokenLocation(TokenLocation* location) } } +TokenLocationFile* TokenLocationCollection::addTokenLocationFile(std::shared_ptr locationFile) +{ + TokenLocationFile* file = findTokenLocationFileByPath(locationFile->getFilePath()); + if (file) + { + LOG_ERROR("TokenLocationFile with same path already exists."); + return file; + } + + m_files.emplace(locationFile->getFilePath(), locationFile); + locationFile->forEachTokenLocation( + [this, &file](TokenLocation* tokenLocation) -> void + { + m_locations.emplace(tokenLocation->getId(), tokenLocation); + } + ); + return locationFile.get(); +} + +void TokenLocationCollection::removeTokenLocationFile(TokenLocationFile* file) +{ + file->forEachTokenLocation( + [&](TokenLocation* location) + { + m_locations.erase(location->getId()); + } + ); + + m_files.erase(file->getFilePath()); +} + TokenLocation* TokenLocationCollection::findTokenLocationById(Id id) const { std::map::const_iterator it = m_locations.find(id); @@ -115,7 +154,8 @@ TokenLocationFile* TokenLocationCollection::findTokenLocationFileByPath(const Fi return getTokenLocationFileByPath(filePath).get(); } -void TokenLocationCollection::forEachTokenLocationFile(std::function)> func) const +void TokenLocationCollection::forEachTokenLocationFile( + std::function)> func) const { for (const TokenLocationFilePairType& file : m_files) { @@ -139,18 +179,6 @@ void TokenLocationCollection::forEachTokenLocation(std::functionforEachTokenLocation( - [&](TokenLocation* location) - { - m_locations.erase(location->getId()); - } - ); - - m_files.erase(file->getFilePath()); -} - TokenLocationFile* TokenLocationCollection::addTokenLocationFileAsPlainCopy(const TokenLocationFile* locationFile) { TokenLocationFile* file = createTokenLocationFile(locationFile->getFilePath()); @@ -161,7 +189,6 @@ TokenLocationFile* TokenLocationCollection::addTokenLocationFileAsPlainCopy(cons m_locations.emplace(copy->getId(), copy); } ); - file->isWholeCopy = true; return file; } diff --git a/src/lib/data/location/TokenLocationCollection.h b/src/lib/data/location/TokenLocationCollection.h index 4b1f40cd..d5fa81a3 100644 --- a/src/lib/data/location/TokenLocationCollection.h +++ b/src/lib/data/location/TokenLocationCollection.h @@ -38,6 +38,9 @@ public: unsigned int endLineNumber, unsigned int endColumnNumber); void removeTokenLocation(TokenLocation* location); + TokenLocationFile* addTokenLocationFile(std::shared_ptr locationFile); + void removeTokenLocationFile(TokenLocationFile* file); + TokenLocation* findTokenLocationById(Id id) const; TokenLocationFile* findTokenLocationFileByPath(const FilePath& filePath) const; @@ -45,8 +48,6 @@ public: void forEachTokenLocationLine(std::function func) const; void forEachTokenLocation(std::function func) const; - void removeTokenLocationFile(TokenLocationFile* file); - TokenLocationFile* addTokenLocationFileAsPlainCopy(const TokenLocationFile* locationFile); TokenLocation* addTokenLocationAsPlainCopy(const TokenLocation* location); diff --git a/src/lib/data/location/TokenLocationFile.cpp b/src/lib/data/location/TokenLocationFile.cpp index 759ff410..74b44331 100644 --- a/src/lib/data/location/TokenLocationFile.cpp +++ b/src/lib/data/location/TokenLocationFile.cpp @@ -57,14 +57,41 @@ TokenLocation* TokenLocationFile::addTokenLocation( unsigned int endLineNumber, unsigned int endColumnNumber) { TokenLocationLine* line = createTokenLocationLine(startLineNumber); - TokenLocation* start = line->addStartTokenLocation(locationId, tokenId, startColumnNumber); - if (startLineNumber != endLineNumber) + // Check if a TokenLocation with the same start and end was already added. + TokenLocation* start = nullptr; + line->forEachStartTokenLocation( + [&](TokenLocation* startLocation) + { + if (start) + { + return; + } + + TokenLocation* endLocation = startLocation->getEndTokenLocation(); + + if (startLocation->getTokenId() == tokenId && + startLocation->getColumnNumber() == startColumnNumber && + endLocation && + endLocation->getLineNumber() == endLineNumber && + endLocation->getColumnNumber() == endColumnNumber) + { + start = startLocation; + } + } + ); + + if (!start) { - line = createTokenLocationLine(endLineNumber); - } + start = line->addStartTokenLocation(locationId, tokenId, startColumnNumber); - line->addEndTokenLocation(start, endColumnNumber); + if (startLineNumber != endLineNumber) + { + line = createTokenLocationLine(endLineNumber); + } + + line->addEndTokenLocation(start, endColumnNumber); + } return start; } @@ -132,7 +159,7 @@ TokenLocation* TokenLocationFile::addTokenLocationAsPlainCopy(const TokenLocatio TokenLocationLine* line = createTokenLocationLine(lineNumber); // Check whether this location was already added or if the other TokenLocation was added. - TokenLocation* otherLocation = line->getTokenLocationByIdAndType(location->getId(), location->getType()); + TokenLocation* otherLocation = line->getTokenLocationById(location->getId()); if (otherLocation) { if (otherLocation->isStartTokenLocation() == location->isStartTokenLocation()) @@ -150,7 +177,7 @@ TokenLocation* TokenLocationFile::addTokenLocationAsPlainCopy(const TokenLocatio TokenLocationLine* otherLine = findTokenLocationLine(otherLineNumber); if (otherLine) { - otherLocation = otherLine->getTokenLocationByIdAndType(location->getId(), location->getType()); + otherLocation = otherLine->getTokenLocationById(location->getId()); } } } diff --git a/src/lib/data/location/TokenLocationLine.cpp b/src/lib/data/location/TokenLocationLine.cpp index c6da5d49..aa9b8814 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::getTokenLocationByIdAndType(Id id, LocationType type) const +TokenLocation* TokenLocationLine::getTokenLocationById(Id id) const { for (const TokenLocationPairType& p : m_locations) { - if (p.second->getId() == id && p.second->getType() == type) + if (p.second->getId() == id) { return p.second.get(); } diff --git a/src/lib/data/location/TokenLocationLine.h b/src/lib/data/location/TokenLocationLine.h index 30c08dda..42d63ce3 100644 --- a/src/lib/data/location/TokenLocationLine.h +++ b/src/lib/data/location/TokenLocationLine.h @@ -7,8 +7,6 @@ #include #include -#include "data/location/LocationType.h" - #include "utility/file/FilePath.h" #include "utility/types.h" @@ -36,7 +34,7 @@ public: TokenLocation* addEndTokenLocation(TokenLocation* start, unsigned int columnNumber); void removeTokenLocation(TokenLocation* location); - TokenLocation* getTokenLocationByIdAndType(Id id, LocationType type) const; + TokenLocation* getTokenLocationById(Id id) const; void forEachTokenLocation(std::function func) const; void forEachStartTokenLocation(std::function func) const; diff --git a/src/lib/utility/file/FileRegister.cpp b/src/lib/utility/file/FileRegister.cpp index d679b10f..e7a03c48 100644 --- a/src/lib/utility/file/FileRegister.cpp +++ b/src/lib/utility/file/FileRegister.cpp @@ -3,8 +3,9 @@ #include "utility/file/FileManager.h" #include "utility/file/FileSystem.h" -FileRegister::FileRegister(const FileManager* fileManager) +FileRegister::FileRegister(const FileManager* fileManager, bool randomizeParseOrder) : m_fileManager(fileManager) + , m_randomizeParseOrder(randomizeParseOrder) { } @@ -144,7 +145,14 @@ FilePath FileRegister::consumeSourceFile() if (paths.size()) { - path = paths[rand() % paths.size()]; + if (m_randomizeParseOrder) + { + path = paths[rand() % paths.size()]; + } + else + { + path = paths[0]; + } std::lock_guard lock(m_sourceFileMutex); m_sourceFilePaths[path] = STATE_PARSING; diff --git a/src/lib/utility/file/FileRegister.h b/src/lib/utility/file/FileRegister.h index f8950f22..401204c5 100644 --- a/src/lib/utility/file/FileRegister.h +++ b/src/lib/utility/file/FileRegister.h @@ -17,7 +17,7 @@ class FileManager; class FileRegister { public: - explicit FileRegister(const FileManager* fileManager); + explicit FileRegister(const FileManager* fileManager, bool randomizeParseOrder); void setFilePaths(const std::vector& filePaths); @@ -49,6 +49,7 @@ private: }; const FileManager* m_fileManager; + bool m_randomizeParseOrder; mutable std::unordered_map m_projectFiles; mutable std::mutex m_projectFilesMutex; diff --git a/src/lib_gui/qt/element/QtCodeFile.cpp b/src/lib_gui/qt/element/QtCodeFile.cpp index eb50e5b8..a5266d81 100644 --- a/src/lib_gui/qt/element/QtCodeFile.cpp +++ b/src/lib_gui/qt/element/QtCodeFile.cpp @@ -405,19 +405,6 @@ void QtCodeFile::clickedTitleBar() void QtCodeFile::clickedTitle() { MessageActivateFile(m_filePath).dispatch(); - - // TODO: check if external file and maximize instead - - // MessageChangeFileView msg( - // message->filePath, - // MessageChangeFileView::FILE_MAXIMIZED, - // true, - // false, - // nullptr - // ); - // msg.setIsReplayed(message->isReplayed()); - // msg.setKeepContent(message->keepContent()); - // msg.dispatch(); } void QtCodeFile::editProject() diff --git a/src/test/CxxParserTestSuite.h b/src/test/CxxParserTestSuite.h index f4b16fdd..c54279ae 100644 --- a/src/test/CxxParserTestSuite.h +++ b/src/test/CxxParserTestSuite.h @@ -2779,7 +2779,7 @@ public: void test_cxx_parser_parses_multiple_files() { TestFileManager fm; - std::shared_ptr fr = std::make_shared(&fm); + std::shared_ptr fr = std::make_shared(&fm, false); TestParserClient client; CxxParser parser(&client, fr); @@ -3094,7 +3094,7 @@ private: m_args.languageStandard = "1z"; TestFileManager fm; - std::shared_ptr fr = std::make_shared(&fm); + std::shared_ptr fr = std::make_shared(&fm, false); std::shared_ptr client = std::make_shared(); CxxParser parser(client.get(), fr); parser.parseFile("input.cc", TextAccess::createFromString(code), m_args);