diff options
| author | Maximilian Goldstein <max.goldstein@qt.io> | 2021-12-13 13:19:33 +0100 |
|---|---|---|
| committer | Maximilian Goldstein <max.goldstein@qt.io> | 2021-12-13 18:20:38 +0100 |
| commit | f5dc8ef19f4a92b307da38598955efd89922fc7e (patch) | |
| tree | 7f06a61974c5db3f21c8c583877e434464cf6084 /src | |
| parent | e83fd85cce26823c6289a32fd5f7a0fa87639407 (diff) | |
qqmljscompiler: Allow for reading file contents from memory
This is necessary in order for the qmllint library to provide linting
in memory. This in turn is used by our LSP.
Pick-to: 6.3
Change-Id: Ice01c16b4d9ff90cddac87c8840dc5556981f9d5
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
| -rw-r--r-- | src/qmlcompiler/qqmljscompiler.cpp | 12 | ||||
| -rw-r--r-- | src/qmlcompiler/qqmljscompiler_p.h | 6 | ||||
| -rw-r--r-- | src/qmllint/qqmllinter.cpp | 3 |
3 files changed, 14 insertions, 7 deletions
diff --git a/src/qmlcompiler/qqmljscompiler.cpp b/src/qmlcompiler/qqmljscompiler.cpp index 79fa6a69ff..f9448f38ac 100644 --- a/src/qmlcompiler/qqmljscompiler.cpp +++ b/src/qmlcompiler/qqmljscompiler.cpp @@ -201,20 +201,24 @@ private: bool qCompileQmlFile(const QString &inputFileName, QQmlJSSaveFunction saveFunction, QQmlJSAotCompiler *aotCompiler, QQmlJSCompileError *error, - bool storeSourceLocation, QV4::Compiler::CodegenWarningInterface *interface) + bool storeSourceLocation, QV4::Compiler::CodegenWarningInterface *interface, + const QString *fileContents) { QmlIR::Document irDocument(/*debugMode*/false); return qCompileQmlFile(irDocument, inputFileName, saveFunction, aotCompiler, error, - storeSourceLocation, interface); + storeSourceLocation, interface, fileContents); } bool qCompileQmlFile(QmlIR::Document &irDocument, const QString &inputFileName, QQmlJSSaveFunction saveFunction, QQmlJSAotCompiler *aotCompiler, QQmlJSCompileError *error, bool storeSourceLocation, - QV4::Compiler::CodegenWarningInterface *interface) + QV4::Compiler::CodegenWarningInterface *interface, const QString *fileContents) { QString sourceCode; - { + + if (fileContents != nullptr) { + sourceCode = *fileContents; + } else { QFile f(inputFileName); if (!f.open(QIODevice::ReadOnly)) { error->message = QLatin1String("Error opening ") + inputFileName + QLatin1Char(':') + f.errorString(); diff --git a/src/qmlcompiler/qqmljscompiler_p.h b/src/qmlcompiler/qqmljscompiler_p.h index 15b7f3062f..d92f75f524 100644 --- a/src/qmlcompiler/qqmljscompiler_p.h +++ b/src/qmlcompiler/qqmljscompiler_p.h @@ -124,12 +124,14 @@ bool qCompileQmlFile(const QString &inputFileName, QQmlJSSaveFunction saveFuncti QQmlJSAotCompiler *aotCompiler, QQmlJSCompileError *error, bool storeSourceLocation = false, QV4::Compiler::CodegenWarningInterface *interface = - QV4::Compiler::defaultCodegenWarningInterface()); + QV4::Compiler::defaultCodegenWarningInterface(), + const QString *fileContents = nullptr); bool qCompileQmlFile(QmlIR::Document &irDocument, const QString &inputFileName, QQmlJSSaveFunction saveFunction, QQmlJSAotCompiler *aotCompiler, QQmlJSCompileError *error, bool storeSourceLocation = false, QV4::Compiler::CodegenWarningInterface *interface = - QV4::Compiler::defaultCodegenWarningInterface()); + QV4::Compiler::defaultCodegenWarningInterface(), + const QString *fileContents = nullptr); bool qCompileJSFile(const QString &inputFileName, const QString &inputFileUrl, QQmlJSSaveFunction saveFunction, QQmlJSCompileError *error); diff --git a/src/qmllint/qqmllinter.cpp b/src/qmllint/qqmllinter.cpp index feefa3e1a4..8692dec480 100644 --- a/src/qmllint/qqmllinter.cpp +++ b/src/qmllint/qqmllinter.cpp @@ -242,7 +242,8 @@ bool QQmlLinter::lintFile(const QString &filename, const QString *fileContents, QLoggingCategory::setFilterRules(u"qt.qml.compiler=false"_qs); CodegenWarningInterface interface(m_logger.get()); - qCompileQmlFile(filename, saveFunction, &codegen, &error, true, &interface); + qCompileQmlFile(filename, saveFunction, &codegen, &error, true, &interface, + fileContents); success &= !m_logger->hasWarnings() && !m_logger->hasErrors(); |
