QmlJS: Fix Follow under cursor

When trying to jump to a symbol in a qml file the Qml Model may find
the location in a generated .qml file in the build folder.
QtCreator searches in all generated .qrc files to try and find
the source file so it can jump to it instead.

Previously not all auto-generated ".rcc" folders would be found
as only the folders of targets (executables) were searched.
Plugins or Static Libraries were not searched.

With this fix, all projects nodes are searched for the ".rcc" folder
and therefore also finds them for Dynamic / Static libraries and
plugins.

Fixes: QTCREATORBUG-27173
Change-Id: Ic51ac8fbc82c15785cbefd76787942a512ecf3db
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2022-10-25 08:57:49 +02:00
parent fe376af66b
commit 129448d61d
11 changed files with 67 additions and 27 deletions

View File

@@ -81,8 +81,36 @@ static void setupProjectInfoQmlBundles(ModelManagerInterface::ProjectInfo &proje
}
}
static void findAllQrcFiles(const FilePath &filePath, FilePaths &out)
{
filePath.iterateDirectory(
[&out](const FilePath &path) {
out.append(path.canonicalPath());
return true;
},
{{"*.qrc"}, QDir::Files});
}
static FilePaths findGeneratedQrcFiles(const ModelManagerInterface::ProjectInfo &pInfo,
const FilePaths &hiddenRccFolders)
{
FilePaths result;
// Search in Application Directories for directories named ".rcc"
// and add all .qrc files in there to the resource file list.
for (const Utils::FilePath &path : pInfo.applicationDirectories) {
Utils::FilePath generatedQrcDir = path.pathAppended(".rcc");
findAllQrcFiles(generatedQrcDir, result);
}
for (const Utils::FilePath &hiddenRccFolder : hiddenRccFolders) {
findAllQrcFiles(hiddenRccFolder, result);
}
return result;
}
ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
Project *project) const
Project *project, const FilePaths &hiddenRccFolders) const
{
ModelManagerInterface::ProjectInfo projectInfo;
projectInfo.project = project;
@@ -183,6 +211,7 @@ ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
}
setupProjectInfoQmlBundles(projectInfo);
projectInfo.generatedQrcFiles = findGeneratedQrcFiles(projectInfo, hiddenRccFolders);
return projectInfo;
}
@@ -294,7 +323,7 @@ void ModelManager::updateDefaultProjectInfo()
Project *currentProject = SessionManager::startupProject();
setDefaultProject(containsProject(currentProject)
? projectInfo(currentProject)
: defaultProjectInfoForProject(currentProject),
: defaultProjectInfoForProject(currentProject, {}),
currentProject);
}

View File

@@ -32,7 +32,8 @@ protected:
WorkingCopy workingCopyInternal() const override;
void addTaskInternal(const QFuture<void> &result, const QString &msg,
const char *taskId) const override;
ProjectInfo defaultProjectInfoForProject(ProjectExplorer::Project *project) const override;
ProjectInfo defaultProjectInfoForProject(
ProjectExplorer::Project *project, const Utils::FilePaths &hiddenRccFolders) const override;
private:
void updateDefaultProjectInfo();
void loadDefaultQmlTypeDescriptions();