From f72f7808629df293c5d869c95e8ce04ed98d409c Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Fri, 4 May 2018 12:25:37 +0200 Subject: [PATCH] logic: fixed handling case insensitive filepath matches when activating a symbol via editor plugin --- .../controller/IDECommunicationController.cpp | 10 +++---- src/lib/data/access/StorageAccess.h | 2 ++ src/lib/data/access/StorageAccessProxy.cpp | 10 +++++++ src/lib/data/access/StorageAccessProxy.h | 2 ++ src/lib/data/storage/PersistentStorage.cpp | 28 +++++++++++++++---- src/lib/data/storage/PersistentStorage.h | 3 ++ src/lib/utility/file/FilePath.cpp | 5 ++++ src/lib/utility/file/FilePath.h | 1 + 8 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/lib/component/controller/IDECommunicationController.cpp b/src/lib/component/controller/IDECommunicationController.cpp index 722adbc1..84bb9a06 100644 --- a/src/lib/component/controller/IDECommunicationController.cpp +++ b/src/lib/component/controller/IDECommunicationController.cpp @@ -84,10 +84,11 @@ void IDECommunicationController::handleSetActiveTokenMessage( { const unsigned int cursorColumn = message.column; - const FilePath filePath = message.filePath.getCanonical(); + const Id fileId = m_storageAccess->getNodeIdForFileNode(message.filePath.getCanonical()); + const FileInfo fileInfo = m_storageAccess->getFileInfoForFileId(fileId); + const FilePath filePath = fileInfo.path; - if (FileSystem::getFileInfoForPath(filePath).lastWriteTime - == m_storageAccess->getFileInfoForFilePath(filePath).lastWriteTime) + if (FileSystem::getFileInfoForPath(filePath).lastWriteTime == fileInfo.lastWriteTime) { // file was not modified std::shared_ptr sourceLocationFile = m_storageAccess->getSourceLocationsForLinesInFile( @@ -110,7 +111,7 @@ void IDECommunicationController::handleSetActiveTokenMessage( } ); - if (selectedLocationIds.size() > 0) + if (!selectedLocationIds.empty()) { MessageStatus( L"Activating source location from plug-in succeeded: " + filePath.wstr() + L", row: " + @@ -123,7 +124,6 @@ void IDECommunicationController::handleSetActiveTokenMessage( } } - Id fileId = m_storageAccess->getNodeIdForFileNode(filePath); if (fileId > 0) { MessageActivateFile(filePath, message.row).dispatchImmediately(); diff --git a/src/lib/data/access/StorageAccess.h b/src/lib/data/access/StorageAccess.h index 3fab07b7..4650a11e 100644 --- a/src/lib/data/access/StorageAccess.h +++ b/src/lib/data/access/StorageAccess.h @@ -79,6 +79,8 @@ public: virtual std::shared_ptr getFileContent(const FilePath& filePath) const = 0; + virtual FileInfo getFileInfoForFileId(Id id) const = 0; + virtual FileInfo getFileInfoForFilePath(const FilePath& filePath) const = 0; virtual std::vector getFileInfosForFilePaths(const std::vector& filePaths) const = 0; diff --git a/src/lib/data/access/StorageAccessProxy.cpp b/src/lib/data/access/StorageAccessProxy.cpp index 276a14e6..d8de0de0 100644 --- a/src/lib/data/access/StorageAccessProxy.cpp +++ b/src/lib/data/access/StorageAccessProxy.cpp @@ -303,6 +303,16 @@ std::shared_ptr StorageAccessProxy::getFileContent(const FilePath& f return nullptr; } +FileInfo StorageAccessProxy::getFileInfoForFileId(Id id) const +{ + if (hasSubject()) + { + return m_subject->getFileInfoForFileId(id); + } + + return FileInfo(); +} + FileInfo StorageAccessProxy::getFileInfoForFilePath(const FilePath& filePath) const { if (hasSubject()) diff --git a/src/lib/data/access/StorageAccessProxy.h b/src/lib/data/access/StorageAccessProxy.h index 96c1edb1..148e6199 100644 --- a/src/lib/data/access/StorageAccessProxy.h +++ b/src/lib/data/access/StorageAccessProxy.h @@ -63,6 +63,8 @@ public: virtual std::shared_ptr getCommentLocationsInFile(const FilePath& filePath) const override; virtual std::shared_ptr getFileContent(const FilePath& filePath) const override; + + virtual FileInfo getFileInfoForFileId(Id id) const override; virtual FileInfo getFileInfoForFilePath(const FilePath& filePath) const override; virtual std::vector getFileInfosForFilePaths(const std::vector& filePaths) const override; diff --git a/src/lib/data/storage/PersistentStorage.cpp b/src/lib/data/storage/PersistentStorage.cpp index 76d6383e..635baf29 100644 --- a/src/lib/data/storage/PersistentStorage.cpp +++ b/src/lib/data/storage/PersistentStorage.cpp @@ -295,6 +295,7 @@ void PersistentStorage::clearCaches() m_fileIndex.clear(); m_fileNodeIds.clear(); + m_lowerCasefileNodeIds.clear(); m_fileNodePaths.clear(); m_fileNodeComplete.clear(); m_fileNodeIndexed.clear(); @@ -429,7 +430,7 @@ void PersistentStorage::optimizeMemory() Id PersistentStorage::getNodeIdForFileNode(const FilePath& filePath) const { - return m_sqliteIndexStorage.getFileByPath(filePath.wstr()).id; + return getFileNodeId(filePath); } Id PersistentStorage::getNodeIdForNameHierarchy(const NameHierarchy& nameHierarchy) const @@ -1473,9 +1474,15 @@ std::shared_ptr PersistentStorage::getFileContent(const FilePath& fi return m_sqliteIndexStorage.getFileContentByPath(filePath.wstr()); } +FileInfo PersistentStorage::getFileInfoForFileId(Id id) const +{ + StorageFile storageFile = m_sqliteIndexStorage.getFirstById(id); + return FileInfo(FilePath(storageFile.filePath), storageFile.modificationTime); +} + FileInfo PersistentStorage::getFileInfoForFilePath(const FilePath& filePath) const { - return FileInfo(filePath, m_sqliteIndexStorage.getFileByPath(filePath.wstr()).modificationTime); + return getFileInfoForFileId(getFileNodeId(filePath)); } std::vector PersistentStorage::getFileInfosForFilePaths(const std::vector& filePaths) const @@ -2064,11 +2071,19 @@ Id PersistentStorage::getFileNodeId(const FilePath& filePath) const return 0; } - std::map::const_iterator it = m_fileNodeIds.find(filePath); - - if (it != m_fileNodeIds.end()) { - return it->second; + std::map::const_iterator it = m_fileNodeIds.find(filePath); + if (it != m_fileNodeIds.end()) + { + return it->second; + } + } + { + std::map::const_iterator it = m_lowerCasefileNodeIds.find(filePath.getLowerCase()); + if (it != m_lowerCasefileNodeIds.end()) + { + return it->second; + } } return 0; @@ -2703,6 +2718,7 @@ void PersistentStorage::buildFilePathMaps() const FilePath path(file.filePath); m_fileNodeIds.emplace(path, file.id); + m_lowerCasefileNodeIds.emplace(path.getLowerCase(), file.id); m_fileNodePaths.emplace(file.id, path); m_fileNodeComplete.emplace(file.id, file.complete); m_fileNodeIndexed.emplace(file.id, file.indexed); diff --git a/src/lib/data/storage/PersistentStorage.h b/src/lib/data/storage/PersistentStorage.h index a5109bc2..06f6c224 100644 --- a/src/lib/data/storage/PersistentStorage.h +++ b/src/lib/data/storage/PersistentStorage.h @@ -119,6 +119,8 @@ public: virtual std::shared_ptr getFileContent(const FilePath& filePath) const override; + virtual FileInfo getFileInfoForFileId(Id id) const override; + virtual FileInfo getFileInfoForFilePath(const FilePath& filePath) const override; virtual std::vector getFileInfosForFilePaths(const std::vector& filePaths) const override; @@ -200,6 +202,7 @@ private: SqliteBookmarkStorage m_sqliteBookmarkStorage; std::map m_fileNodeIds; + std::map m_lowerCasefileNodeIds; std::map m_fileNodePaths; std::map m_fileNodeComplete; std::map m_fileNodeIndexed; diff --git a/src/lib/utility/file/FilePath.cpp b/src/lib/utility/file/FilePath.cpp index e3e863f3..f23fe80d 100644 --- a/src/lib/utility/file/FilePath.cpp +++ b/src/lib/utility/file/FilePath.cpp @@ -337,6 +337,11 @@ FilePath FilePath::getConcatenated(const std::wstring& other) const return path; } +FilePath FilePath::getLowerCase() const +{ + return FilePath(utility::toLowerCase(wstr())); +} + bool FilePath::contains(const FilePath& other) const { if (!isDirectory()) diff --git a/src/lib/utility/file/FilePath.h b/src/lib/utility/file/FilePath.h index 631a0557..0f328ab3 100644 --- a/src/lib/utility/file/FilePath.h +++ b/src/lib/utility/file/FilePath.h @@ -44,6 +44,7 @@ public: FilePath getConcatenated(const FilePath& other) const; FilePath& concatenate(const std::wstring& other); FilePath getConcatenated(const std::wstring& other) const; + FilePath getLowerCase() const; std::vector expandEnvironmentVariables() const; bool contains(const FilePath& other) const;