From c9da771625f68c27149a477b58bc2baf8841914f Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Tue, 23 Jul 2024 10:47:04 +0200 Subject: [PATCH] QmlJS: Fix requesting context help Import versions as well as versionless imports can confuse the help engine when performing context help lookups, which leads in some cases to falling back to the wrong help items. Remove the version for looking up help items. Fixes: QTCREATORBUG-31280 Change-Id: Ida765369f52804186ca005ceec23cd9d795220c5 Reviewed-by: Fabian Kosmale Reviewed-by: Semih Yavuz --- src/plugins/qmljseditor/qmljshoverhandler.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/plugins/qmljseditor/qmljshoverhandler.cpp b/src/plugins/qmljseditor/qmljshoverhandler.cpp index 650592ff485..bdaad5b153a 100644 --- a/src/plugins/qmljseditor/qmljshoverhandler.cpp +++ b/src/plugins/qmljseditor/qmljshoverhandler.cpp @@ -123,12 +123,15 @@ static inline QString getModuleName(const ScopeChain &scopeChain, const Document bool QmlJSHoverHandler::setQmlTypeHelp(const ScopeChain &scopeChain, const Document::Ptr &qmlDocument, const ObjectValue *value, const QStringList &qName) { - QString moduleName = getModuleName(scopeChain, qmlDocument, value); + const QString moduleName = getModuleName(scopeChain, qmlDocument, value); + static const QRegularExpression anyVersion("((-1|\\d+)\\.-1)|(\\d+\\.\\d+)$"); QStringList helpIdCandidates; QStringList helpIdPieces(qName); - helpIdPieces.prepend(moduleName); + QString strippedModuleName = moduleName; + strippedModuleName.remove(anyVersion); + helpIdPieces.prepend(strippedModuleName); helpIdPieces.prepend("QML"); helpIdCandidates += helpIdPieces.join('.'); @@ -151,8 +154,8 @@ bool QmlJSHoverHandler::setQmlTypeHelp(const ScopeChain &scopeChain, const Docum const HelpItem::Links links = helpItem.links(); // Check if the module name contains a major version. - QRegularExpression version("^([^\\d]*)(\\d+)\\.*\\d*$"); - QRegularExpressionMatch m = version.match(moduleName); + static QRegularExpression version("^([^\\d]*)(\\d+)\\.*\\d*$"); + const QRegularExpressionMatch m = version.match(moduleName); if (m.hasMatch()) { QMap filteredUrlMap; const QString maj = m.captured(2);