diff options
author | Christian Kandeler <[email protected]> | 2019-02-25 17:45:39 +0100 |
---|---|---|
committer | Christian Kandeler <[email protected]> | 2019-03-04 09:52:13 +0000 |
commit | d0db212575909ca18244bdfc99b952dffcd0e902 (patch) | |
tree | f0fbfb40bc34b20a5f4539b6936c8854e78433ee /src/libs/utils/fileinprojectfinder.h | |
parent | b0e125ac11b1ad80717366a1270412d6b6b1be41 (diff) |
Resolve ambiguous results of searches for relative file paths
Qt Creator extracts file names from the output of external processes in
various places, for instance from compilers during the build. It often
happens that such file names are not absolute, so they cannot be
directly opened in an editor when the user clicks on their
representation in some widget. That's why they are processed by the
FileInProjectFinder facility first.
This patch enhances the FileInProjectFinder to be able to return more
than one candidate for a relative file path, and allows the user to
choose between these candidates where possible. This way, we won't open
a random file anymore when a project contains more than one file with
the same name.
Fixes: QTCREATORBUG-13623
Change-Id: Id19c9eace3e6b3dbde89f6528e6d02b55872d747
Reviewed-by: hjk <[email protected]>
Diffstat (limited to 'src/libs/utils/fileinprojectfinder.h')
-rw-r--r-- | src/libs/utils/fileinprojectfinder.h | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/libs/utils/fileinprojectfinder.h b/src/libs/utils/fileinprojectfinder.h index 2b1dc940902..ac8cd0a588c 100644 --- a/src/libs/utils/fileinprojectfinder.h +++ b/src/libs/utils/fileinprojectfinder.h @@ -55,7 +55,7 @@ public: void addMappedPath(const FileName &localFilePath, const QString &remoteFilePath); - QString findFile(const QUrl &fileUrl, bool *success = nullptr) const; + FileNameList findFile(const QUrl &fileUrl, bool *success = nullptr) const; bool findFileOrDirectory(const QString &originalPath, FileHandler fileHandler = nullptr, DirectoryHandler directoryHandler = nullptr) const; @@ -71,17 +71,17 @@ private: }; struct CacheEntry { - QString path; + QStringList paths; int matchLength = 0; }; class QrcUrlFinder { public: - QString find(const QUrl &fileUrl) const; + FileNameList find(const QUrl &fileUrl) const; void setProjectFiles(const FileNameList &projectFiles); private: FileNameList m_allQrcFiles; - mutable QHash<QUrl, QString> m_fileCache; + mutable QHash<QUrl, FileNameList> m_fileCache; mutable QHash<FileName, QSharedPointer<QrcParser>> m_parserCache; }; @@ -92,11 +92,11 @@ private: QStringList filesWithSameFileName(const QString &fileName) const; QStringList pathSegmentsWithSameName(const QString &path) const; - bool handleSuccess(const QString &originalPath, const QString &found, int confidence, + bool handleSuccess(const QString &originalPath, const QStringList &found, int confidence, const char *where) const; static int commonPostFixLength(const QString &candidatePath, const QString &filePathToFind); - static QString bestMatch(const QStringList &filePaths, const QString &filePathToFind); + static QStringList bestMatches(const QStringList &filePaths, const QString &filePathToFind); FileName m_projectDir; FileName m_sysroot; @@ -108,4 +108,6 @@ private: QrcUrlFinder m_qrcUrlFinder; }; +QTCREATOR_UTILS_EXPORT FileName chooseFileFromList(const FileNameList &candidates); + } // namespace Utils |