diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2023-11-20 17:09:13 +0100 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2023-11-28 12:33:27 +0100 |
commit | da693f932e948c960526140d5701698a53155f23 (patch) | |
tree | 4e052cdd9fe5625756f59b966e6a0afa2d7bcac8 | |
parent | f4c13d1b738d25c563d00c0bc25e720775d985a3 (diff) |
qqmljs.g: add option to disable automatic identifier insertion
Add a RecoveryOption enum that can be passed to QmlFile's constructor to
enable or disable recovery.
Extend DomCreationOption by another value WithRecovery, such that
users of the Dom can enable recovery via the FileToLoad argument of the
Dom's file to load.
Enable the recovery in the qqmlcodemodel for qmlls.
The actual recovery is implemented in a separate commit in the relation
chain.
Task-number: QTBUG-115836
Change-Id: Icb6b115cf667c77c596fa335bc37bb12bf680cce
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | src/qml/parser/qqmljs.g | 7 | ||||
-rw-r--r-- | src/qmldom/qqmldomconstants_p.h | 1 | ||||
-rw-r--r-- | src/qmldom/qqmldomexternalitems.cpp | 5 | ||||
-rw-r--r-- | src/qmldom/qqmldomexternalitems_p.h | 4 | ||||
-rw-r--r-- | src/qmldom/qqmldomtop.cpp | 5 | ||||
-rw-r--r-- | src/qmlls/qqmlcodemodel.cpp | 1 | ||||
-rw-r--r-- | tests/auto/qmlls/utils/tst_qmlls_utils.cpp | 1 |
7 files changed, 21 insertions, 3 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index 0b7a38c4a5..80225a87dc 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -302,6 +302,12 @@ public: inline int errorColumnNumber() const { return diagnosticMessage().loc.startColumn; } + inline bool identifierInsertion() const + { return m_enableIdentifierInsertion; } + + inline void enableIdentifierInsertion() + { m_enableIdentifierInsertion = true; } + protected: bool parse(int startToken); @@ -390,6 +396,7 @@ protected: CoverExpressionType coverExpressionType = CE_Invalid; QList<DiagnosticMessage> diagnostic_messages; + bool m_enableIdentifierInsertion = false; }; } // end of namespace QQmlJS diff --git a/src/qmldom/qqmldomconstants_p.h b/src/qmldom/qqmldomconstants_p.h index 475af43d00..139d7ccd5d 100644 --- a/src/qmldom/qqmldomconstants_p.h +++ b/src/qmldom/qqmldomconstants_p.h @@ -387,6 +387,7 @@ enum DomCreationOption : char { None = 0, WithSemanticAnalysis = 1, WithScriptExpressions = 2, + WithRecovery = 4 }; Q_DECLARE_FLAGS(DomCreationOptions, DomCreationOption); diff --git a/src/qmldom/qqmldomexternalitems.cpp b/src/qmldom/qqmldomexternalitems.cpp index 4411d583df..9f839c5fac 100644 --- a/src/qmldom/qqmldomexternalitems.cpp +++ b/src/qmldom/qqmldomexternalitems.cpp @@ -315,7 +315,8 @@ QmlFile::QmlFile(const QmlFile &o) m_astComments = std::make_shared<AstComments>(*m_astComments); } -QmlFile::QmlFile(QString filePath, QString code, QDateTime lastDataUpdateAt, int derivedFrom) +QmlFile::QmlFile(QString filePath, QString code, QDateTime lastDataUpdateAt, int derivedFrom, + RecoveryOption option) : ExternalOwningItem(filePath, lastDataUpdateAt, Paths::qmlFilePath(filePath), derivedFrom, code), m_engine(new QQmlJS::Engine), @@ -325,6 +326,8 @@ QmlFile::QmlFile(QString filePath, QString code, QDateTime lastDataUpdateAt, int QQmlJS::Lexer lexer(m_engine.get()); lexer.setCode(code, /*lineno = */ 1, /*qmlMode=*/true); QQmlJS::Parser parser(m_engine.get()); + if (option == EnableParserRecovery) + parser.enableIdentifierInsertion(); m_isValid = parser.parse(); const auto diagnostics = parser.diagnosticMessages(); for (const DiagnosticMessage &msg : diagnostics) { diff --git a/src/qmldom/qqmldomexternalitems_p.h b/src/qmldom/qqmldomexternalitems_p.h index 80ff7895ef..615b387f3d 100644 --- a/src/qmldom/qqmldomexternalitems_p.h +++ b/src/qmldom/qqmldomexternalitems_p.h @@ -248,10 +248,12 @@ public: constexpr static DomType kindValue = DomType::QmlFile; DomType kind() const override { return kindValue; } + enum RecoveryOption { DisableParserRecovery, EnableParserRecovery }; + QmlFile(const QmlFile &o); QmlFile(QString filePath = QString(), QString code = QString(), QDateTime lastDataUpdate = QDateTime::fromMSecsSinceEpoch(0, QTimeZone::UTC), - int derivedFrom = 0); + int derivedFrom = 0, RecoveryOption option = DisableParserRecovery); static ErrorGroups myParsingErrors(); bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override; // iterates the *direct* subpaths, returns false if a quick end was requested diff --git a/src/qmldom/qqmldomtop.cpp b/src/qmldom/qqmldomtop.cpp index ead620ca2d..ad2a663ccd 100644 --- a/src/qmldom/qqmldomtop.cpp +++ b/src/qmldom/qqmldomtop.cpp @@ -412,7 +412,10 @@ void DomUniverse::execQueue() if (!skipParse) { QDateTime now(QDateTime::currentDateTimeUtc()); if (t.kind == DomType::QmlFile) { - auto qmlFile = std::make_shared<QmlFile>(canonicalPath, code, contentDate); + auto qmlFile = std::make_shared<QmlFile>(canonicalPath, code, contentDate, 0, + t.file.options().testFlag(WithRecovery) + ? QmlFile::EnableParserRecovery + : QmlFile::DisableParserRecovery); std::shared_ptr<DomEnvironment> envPtr; if (auto ptr = t.file.environment().lock()) envPtr = std::move(ptr); diff --git a/src/qmlls/qqmlcodemodel.cpp b/src/qmlls/qqmlcodemodel.cpp index a5f589a979..58c835ca78 100644 --- a/src/qmlls/qqmlcodemodel.cpp +++ b/src/qmlls/qqmlcodemodel.cpp @@ -184,6 +184,7 @@ void QQmlCodeModel::indexDirectory(const QString &path, int depthLeft) DomCreationOptions options; options.setFlag(DomCreationOption::WithScriptExpressions); options.setFlag(DomCreationOption::WithSemanticAnalysis); + options.setFlag(DomCreationOption::WithRecovery); FileToLoad fileToLoad = FileToLoad::fromFileSystem(newCurrent.ownerAs<DomEnvironment>(), fPath, options); if (!fileToLoad.canonicalPath().isEmpty()) { diff --git a/tests/auto/qmlls/utils/tst_qmlls_utils.cpp b/tests/auto/qmlls/utils/tst_qmlls_utils.cpp index 466a036c8e..155481fe64 100644 --- a/tests/auto/qmlls/utils/tst_qmlls_utils.cpp +++ b/tests/auto/qmlls/utils/tst_qmlls_utils.cpp @@ -2551,6 +2551,7 @@ void tst_qmlls_utils::completions() QQmlJS::Dom::DomCreationOptions options; options.setFlag(QQmlJS::Dom::DomCreationOption::WithSemanticAnalysis); options.setFlag(QQmlJS::Dom::DomCreationOption::WithScriptExpressions); + options.setFlag(QQmlJS::Dom::DomCreationOption::WithRecovery); auto [env, file] = createEnvironmentAndLoadFile(filePath, options); |