aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljslinter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qmlcompiler/qqmljslinter.cpp')
-rw-r--r--src/qmlcompiler/qqmljslinter.cpp60
1 files changed, 39 insertions, 21 deletions
diff --git a/src/qmlcompiler/qqmljslinter.cpp b/src/qmlcompiler/qqmljslinter.cpp
index 3031d82bf7..c7b7f4a826 100644
--- a/src/qmlcompiler/qqmljslinter.cpp
+++ b/src/qmlcompiler/qqmljslinter.cpp
@@ -4,6 +4,7 @@
#include "qqmljslinter_p.h"
#include "qqmljslintercodegen_p.h"
+#include "qqmljsutils_p.h"
#include <QtQmlCompiler/private/qqmljsimporter_p.h>
#include <QtQmlCompiler/private/qqmljsimportvisitor_p.h>
@@ -27,6 +28,10 @@
# include <QtCore/qlibrary.h>
#endif
+#if QT_CONFIG(qmlcontextpropertydump)
+# include <QtCore/qsettings.h>
+#endif
+
#include <QtQml/private/qqmljslexer_p.h>
#include <QtQml/private/qqmljsparser_p.h>
#include <QtQml/private/qqmljsengine_p.h>
@@ -471,31 +476,18 @@ static void addJsonWarning(QJsonArray &warnings, const QQmlJS::DiagnosticMessage
QJsonObject jsonFix {
{ "message"_L1, suggestion->fixDescription() },
{ "replacement"_L1, suggestion->replacement() },
- { "isHint"_L1, !suggestion->isAutoApplicable() },
+ { "isAutoApplicable"_L1, suggestion->isAutoApplicable() },
+ { "hint"_L1, suggestion->hint() },
};
convertLocation(suggestion->location(), &jsonFix);
const QString filename = suggestion->filename();
if (!filename.isEmpty())
jsonFix.insert("fileName"_L1, filename);
suggestions << jsonFix;
-
- const QString hint = suggestion->hint();
- if (!hint.isEmpty()) {
- // We need to keep compatibility with the JSON format.
- // Therefore the overly verbose encoding of the hint.
- QJsonObject jsonHint {
- { "message"_L1, hint },
- { "replacement"_L1, QString() },
- { "isHint"_L1, true }
- };
- convertLocation(QQmlJS::SourceLocation(), &jsonHint);
- suggestions << jsonHint;
- }
}
jsonMessage[u"suggestions"] = suggestions;
warnings << jsonMessage;
-
}
void QQmlJSLinter::processMessages(QJsonArray &warnings)
@@ -505,12 +497,41 @@ void QQmlJSLinter::processMessages(QJsonArray &warnings)
});
}
+ContextPropertyInfo QQmlJSLinter::contextPropertiesFor(
+ const QString &filename, QQmlJSResourceFileMapper *mapper,
+ const QQmlJS::HeuristicContextProperties &heuristicContextProperties)
+{
+ ContextPropertyInfo result;
+ if (m_userContextPropertySettings.search(filename).isValid()) {
+ result.userContextProperties =
+ QQmlJS::UserContextProperties{ m_userContextPropertySettings };
+ }
+
+ if (heuristicContextProperties.isValid()) {
+ result.heuristicContextProperties = heuristicContextProperties;
+ return result;
+ }
+
+#if QT_CONFIG(qmlcontextpropertydump)
+ const QString buildPath = QQmlJSUtils::qmlBuildPathFromSourcePath(mapper, filename);
+ if (const auto searchResult = m_heuristicContextPropertySearcher.search(buildPath);
+ searchResult.isValid()) {
+ QSettings settings(searchResult.iniFilePath, QSettings::IniFormat);
+ result.heuristicContextProperties =
+ QQmlJS::HeuristicContextProperties::collectFrom(&settings);
+ }
+#else
+ Q_UNUSED(mapper);
+#endif
+ return result;
+}
+
QQmlJSLinter::LintResult
QQmlJSLinter::lintFile(const QString &filename, const QString *fileContents, const bool silent,
QJsonArray *json, const QStringList &qmlImportPaths,
const QStringList &qmldirFiles, const QStringList &resourceFiles,
const QList<QQmlJS::LoggerCategory> &categories,
- const QQmlJS::HeuristicContextProperties &contextProperties)
+ const QQmlJS::HeuristicContextProperties &heuristicContextProperties)
{
// Make sure that we don't expose an old logger if we return before a new one is created.
m_logger.reset();
@@ -640,12 +661,9 @@ QQmlJSLinter::lintFile(const QString &filename, const QString *fileContents, con
const QString resolvedPath =
(resourcePaths.size() == 1) ? u':' + resourcePaths.first() : filename;
- const QQmlJS::UserContextProperties userContextProperties =
- m_userContextPropertySettings.search(filename).isValid()
- ? QQmlJS::UserContextProperties{ m_userContextPropertySettings }
- : QQmlJS::UserContextProperties{};
QQmlJSLinterCodegen codegen{ &m_importer, resolvedPath, qmldirFiles, m_logger.get(),
- ContextPropertyInfo{ contextProperties, userContextProperties } };
+ contextPropertiesFor(filename, mapper ? &*mapper : nullptr,
+ heuristicContextProperties) };
codegen.setTypeResolver(std::move(typeResolver));
using PassManagerPtr =