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 <fabian.kosmale@qt.io>
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
This commit is contained in:
Christian Stenger
2024-07-23 10:47:04 +02:00
parent 370c2d7787
commit c9da771625

View File

@@ -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<QString, QUrl> filteredUrlMap;
const QString maj = m.captured(2);