forked from qt-creator/qt-creator
QmlJS: Stop suggesting versions for imports if possible
Fixes: QTCREATORBUG-28649 Change-Id: I918b229855c18519800a54a73b56eaffa40524e5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include <QRegularExpression>
|
||||
#include <QTextStream>
|
||||
#include <QHash>
|
||||
|
||||
@@ -186,8 +187,10 @@ QString QmlBundle::toString(const QString &indent)
|
||||
}
|
||||
|
||||
QStringList QmlBundle::maybeReadTrie(Trie &trie, Utils::JsonObjectValue *config,
|
||||
const QString &path, const QString &propertyName, bool required)
|
||||
const QString &path, const QString &propertyName,
|
||||
bool required, bool stripVersions)
|
||||
{
|
||||
static const QRegularExpression versionNumberAtEnd("^(.+)( \\d+\\.\\d+)$");
|
||||
QStringList res;
|
||||
if (!config->hasMember(propertyName)) {
|
||||
if (required)
|
||||
@@ -202,7 +205,13 @@ QStringList QmlBundle::maybeReadTrie(Trie &trie, Utils::JsonObjectValue *config,
|
||||
for (Utils::JsonValue *v : elements) {
|
||||
Utils::JsonStringValue *impStr = ((v != nullptr) ? v->toString() : nullptr);
|
||||
if (impStr != nullptr) {
|
||||
trie.insert(impStr->value());
|
||||
QString value = impStr->value();
|
||||
if (stripVersions) {
|
||||
const QRegularExpressionMatch match = versionNumberAtEnd.match(value);
|
||||
if (match.hasMatch())
|
||||
value = match.captured(1);
|
||||
}
|
||||
trie.insert(value);
|
||||
} else {
|
||||
res.append(QString::fromLatin1("Expected all elements of array in property \"%1\" "
|
||||
"to be strings in QmlBundle at %2.")
|
||||
@@ -217,7 +226,7 @@ QStringList QmlBundle::maybeReadTrie(Trie &trie, Utils::JsonObjectValue *config,
|
||||
return res;
|
||||
}
|
||||
|
||||
bool QmlBundle::readFrom(QString path, QStringList *errors)
|
||||
bool QmlBundle::readFrom(QString path, bool stripVersions, QStringList *errors)
|
||||
{
|
||||
Utils::JsonMemoryPool pool;
|
||||
|
||||
@@ -249,8 +258,8 @@ bool QmlBundle::readFrom(QString path, QStringList *errors)
|
||||
}
|
||||
errs << maybeReadTrie(m_searchPaths, config, path, QLatin1String("searchPaths"));
|
||||
errs << maybeReadTrie(m_installPaths, config, path, QLatin1String("installPaths"));
|
||||
errs << maybeReadTrie(m_supportedImports, config, path, QLatin1String("supportedImports")
|
||||
, true);
|
||||
errs << maybeReadTrie(m_supportedImports, config, path, QLatin1String("supportedImports"),
|
||||
true, stripVersions);
|
||||
errs << maybeReadTrie(m_implicitImports, config, path, QLatin1String("implicitImports"));
|
||||
if (errors)
|
||||
(*errors) << errs;
|
||||
|
||||
@@ -53,14 +53,15 @@ public:
|
||||
bool writeTo(const QString &path) const;
|
||||
bool writeTo(QTextStream &stream, const QString &indent = QString()) const;
|
||||
QString toString(const QString &indent = QString());
|
||||
bool readFrom(QString path, QStringList *errors);
|
||||
bool readFrom(QString path, bool stripVersions, QStringList *errors);
|
||||
bool operator==(const QmlBundle &o) const;
|
||||
bool operator!=(const QmlBundle &o) const;
|
||||
private:
|
||||
static void printEscaped(QTextStream &s, const QString &str);
|
||||
static void writeTrie(QTextStream &stream, const Trie &t, const QString &indent);
|
||||
QStringList maybeReadTrie(Trie &trie, Utils::JsonObjectValue *config, const QString &path,
|
||||
const QString &propertyName, bool required = false);
|
||||
const QString &propertyName, bool required = false,
|
||||
bool stripVersions = false);
|
||||
|
||||
QString m_name;
|
||||
Trie m_searchPaths;
|
||||
|
||||
Reference in New Issue
Block a user