McuSupport: Support prioritizing import paths

Some QtQuick import paths in QtMCUs contain incomplete modules and
Used for other purposes but it shadows the correct import path

With this patch it will be possible to reshuffle the import by any
import provider

Fixes: QTCREATORBUG-29681
Change-Id: I5a17df6ca2587ae88643b1ca08f9e84998d51cc2
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Yasser Grimes
2024-01-05 20:37:58 +02:00
parent fd6e45c407
commit 5aeeb74488
4 changed files with 34 additions and 0 deletions

View File

@@ -1125,6 +1125,11 @@ public:
[[maybe_unused]] const Document *context,
[[maybe_unused]] ValueOwner *valueOwner,
[[maybe_unused]] Snapshot *snapshot) {}
virtual Utils::FilePaths prioritizeImportPaths([[maybe_unused]] const Document *context,
const Utils::FilePaths &importPaths)
{
return importPaths;
}
};
} // namespace QmlJS

View File

@@ -219,6 +219,7 @@ Context::ImportsPerDocument LinkPrivate::linkImports()
document.data(),
m_valueOwner,
&m_snapshot);
m_importPaths = provider->prioritizeImportPaths(document.data(), m_importPaths);
}
populateImportedTypes(imports, document);

View File

@@ -119,6 +119,30 @@ void McuSupportImportProvider::loadBuiltins(ImportsPerDocument *importsPerDocume
import.info = ImportInfo::moduleImport("qul", {1, 0}, QString());
getInterfacesImport(context->fileName(), importsPerDocument, import, valueOwner, snapshot);
imports->append(import);
}
FilePaths McuSupportImportProvider::prioritizeImportPaths(const Document *context,
const FilePaths &importPaths)
{
if (!context)
return importPaths;
const std::optional<FilePath> cmakeFilesPathOpt = getTargetBuildFolder(context->fileName());
if (!cmakeFilesPathOpt)
return importPaths;
FilePaths ret;
// qmltocpp uses an incomplete QtQuick folder present in the build folder
// to avoid taking precedence over the correct qul_install/include/*/StyleDefault
// move the import path to be last
std::copy_if(importPaths.cbegin(),
importPaths.cend(),
std::back_inserter(ret),
[cmakeFilesPathOpt](const FilePath &path) { return path != *cmakeFilesPathOpt; });
// nothing was removed
if (ret.size() == importPaths.size())
return importPaths;
ret.push_back(*cmakeFilesPathOpt);
return ret;
};
void McuSupportImportProvider::getInterfacesImport(const FilePath &path,
@@ -156,6 +180,7 @@ std::optional<FilePath> McuSupportImportProvider::getFileModule(const FilePath &
const FilePath &inputFile) const
{
const auto doc = QJsonDocument::fromJson(inputFile.fileContents().value_or(""));
if (!doc.isObject())
return {};

View File

@@ -29,6 +29,9 @@ public:
ValueOwner *valueOwner,
Snapshot *snapshot) override;
virtual Utils::FilePaths prioritizeImportPaths(const Document *context,
const Utils::FilePaths &importPaths) override;
// Add to the interfaces needed for a document
// path: opened qml document
// importsPerDocument: imports available in the document (considered imported)