diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2023-08-28 11:13:18 +0200 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2023-09-04 21:25:27 +0200 |
commit | 3e4fb204b0cc14248090860cafe9b0755eed4a4b (patch) | |
tree | 20253de5537e10baa7b1c288743b4f9a6fc07b7f /src | |
parent | 3b85db07dc5c63bdd326a77670f92af885fdef73 (diff) |
qmlls: show fix suggestions and enable quick fixes
Display the fix suggestions from qmllint in qmlls instead of just
showing the warning.
For example,
'Unqualified access: xxx is accessible in this scope because you are
handling a signal at 18:10. Use a function instead.'
sounds so much more helpful than the previous 'Unqualified access'.
Add an ending '.' in QQmlJSFixSuggestion's messages where missing.
Enable quick-fixes in VS Code and QtC by labeling quickfixes as
quickfixes. Everything that is not labelled a quickfix might need a
special language client implementation to work.
Also, add a test for quickfixes: it seems someone broke the quick
fix functionality in qmlls by mistake by relabeling a quickfix to
'refactor.rewrite'.
Cherry-picking notes: This commit had to take into account that
the tst_qmlls_modules improvements were not picked back.
Fix the test to avoid duplicate publish notifications handlers and
cache the notification as it is just fired once.
Task-number: QTBUG-115213
Change-Id: I350e23901b97d16a60bb39fdb4ab566b0d7fbdfb
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 50a7560b784f16e4d8d697ce62bede8aa56d75f6)
Diffstat (limited to 'src')
-rw-r--r-- | src/qmlcompiler/qqmljsimportvisitor.cpp | 31 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljstypepropagator.cpp | 10 | ||||
-rw-r--r-- | src/qmlls/qqmllintsuggestions.cpp | 3 |
3 files changed, 21 insertions, 23 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index da1b966b4b..a016456a14 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -830,12 +830,12 @@ void QQmlJSImportVisitor::checkRequiredProperties() if (requiredScope != scope) { if (!prevRequiredScope.isNull()) { auto sourceScope = prevRequiredScope->baseType(); - suggestion = QQmlJSFixSuggestion { - "%1:%2:%3: Property marked as required in %4"_L1 - .arg(sourceScope->filePath()) - .arg(sourceScope->sourceLocation().startLine) - .arg(sourceScope->sourceLocation().startColumn) - .arg(requiredScopeName), + suggestion = QQmlJSFixSuggestion{ + "%1:%2:%3: Property marked as required in %4."_L1 + .arg(sourceScope->filePath()) + .arg(sourceScope->sourceLocation().startLine) + .arg(sourceScope->sourceLocation().startColumn) + .arg(requiredScopeName), sourceScope->sourceLocation() }; suggestion->setFilename(sourceScope->filePath()); @@ -962,12 +962,12 @@ void QQmlJSImportVisitor::checkSignal( const qsizetype newLength = m_logger->code().indexOf(u'\n', location.end()) - location.offset; - fix = QQmlJSFixSuggestion { - "Implicitly defining %1 as signal handler in Connections is deprecated. " - "Create a function instead"_L1.arg(handlerName), - QQmlJS::SourceLocation(location.offset, newLength, location.startLine, - location.startColumn), - "function %1(%2) { ... }"_L1.arg(handlerName, handlerParameters.join(u", ")) + fix = QQmlJSFixSuggestion{ + "Implicitly defining %1 as signal handler in Connections is deprecated. " + "Create a function instead."_L1.arg(handlerName), + QQmlJS::SourceLocation(location.offset, newLength, location.startLine, + location.startColumn), + "function %1(%2) { ... }"_L1.arg(handlerName, handlerParameters.join(u", ")) }; } @@ -1370,11 +1370,8 @@ bool QQmlJSImportVisitor::visit(QQmlJS::AST::StringLiteral *sl) templateString += c; } - QQmlJSFixSuggestion suggestion = { - "Use a template literal instead"_L1, - sl->literalToken, - u"`" % templateString % u"`" - }; + QQmlJSFixSuggestion suggestion = { "Use a template literal instead."_L1, sl->literalToken, + u"`" % templateString % u"`" }; suggestion.setAutoApplicable(); m_logger->log(QStringLiteral("String contains unescaped line terminator which is " "deprecated."), diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp index 5d145bb0e5..cd3bb47e33 100644 --- a/src/qmlcompiler/qqmljstypepropagator.cpp +++ b/src/qmlcompiler/qqmljstypepropagator.cpp @@ -374,11 +374,11 @@ void QQmlJSTypePropagator::handleUnqualifiedAccess(const QString &name, bool isM QQmlJS::SourceLocation fixLocation = location; fixLocation.length = 0; - suggestion = QQmlJSFixSuggestion { - name + " is a member of a parent element.\n You can qualify the access " - "with its id to avoid this warning:\n"_L1, - fixLocation, - (id.isEmpty() ? u"<id>."_s : (id + u'.')) + suggestion = QQmlJSFixSuggestion{ + name + + " is a member of a parent element.\n You can qualify the access " + "with its id to avoid this warning.\n"_L1, + fixLocation, (id.isEmpty() ? u"<id>."_s : (id + u'.')) }; if (id.isEmpty()) diff --git a/src/qmlls/qqmllintsuggestions.cpp b/src/qmlls/qqmllintsuggestions.cpp index 474372ce52..ceded7df0a 100644 --- a/src/qmlls/qqmllintsuggestions.cpp +++ b/src/qmlls/qqmllintsuggestions.cpp @@ -75,7 +75,8 @@ static void codeActionHandler( edit.documentChanges = edits; CodeAction action; - action.kind = u"refactor.rewrite"_s.toUtf8(); + // VS Code and QtC ignore everything that is not a 'quickfix'. + action.kind = u"quickfix"_s.toUtf8(); action.edit = edit; action.title = message.toUtf8(); |