forked from qt-creator/qt-creator
QmlJs: disambiguate help lookup
The help system used to be confused by types from QtControls2, since they have often the same name and version as the ones in QtControls. This patch resolve the issue by looking for a number in the module name, and then using the url found as helpId. Task-number: QTCREATORBUG-16851 Change-Id: I48196d90b0fea5edf50751900864a39075894866 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
#include "qmljseditordocument.h"
|
#include "qmljseditordocument.h"
|
||||||
#include "qmlexpressionundercursor.h"
|
#include "qmlexpressionundercursor.h"
|
||||||
|
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/helpmanager.h>
|
#include <coreplugin/helpmanager.h>
|
||||||
@@ -49,6 +50,8 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QStringRef>
|
#include <QStringRef>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QRegularExpressionMatch>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace QmlJS;
|
using namespace QmlJS;
|
||||||
@@ -143,30 +146,57 @@ bool QmlJSHoverHandler::setQmlTypeHelp(const ScopeChain &scopeChain, const Docum
|
|||||||
const ObjectValue *value, const QStringList &qName)
|
const ObjectValue *value, const QStringList &qName)
|
||||||
{
|
{
|
||||||
QString moduleName = getModuleName(scopeChain, qmlDocument, value);
|
QString moduleName = getModuleName(scopeChain, qmlDocument, value);
|
||||||
|
|
||||||
|
QMap<QString, QUrl> urlMap;
|
||||||
|
|
||||||
QString helpId;
|
QString helpId;
|
||||||
do {
|
do {
|
||||||
QStringList helpIdPieces(qName);
|
QStringList helpIdPieces(qName);
|
||||||
helpIdPieces.prepend(moduleName);
|
helpIdPieces.prepend(moduleName);
|
||||||
helpIdPieces.prepend(QLatin1String("QML"));
|
helpIdPieces.prepend(QLatin1String("QML"));
|
||||||
helpId = helpIdPieces.join(QLatin1Char('.'));
|
helpId = helpIdPieces.join(QLatin1Char('.'));
|
||||||
if (!HelpManager::linksForIdentifier(helpId).isEmpty())
|
urlMap = HelpManager::linksForIdentifier(helpId);
|
||||||
|
if (!urlMap.isEmpty())
|
||||||
break;
|
break;
|
||||||
if (helpIdPieces.size() > 3) {
|
if (helpIdPieces.size() > 3) {
|
||||||
QString lm = helpIdPieces.value(2);
|
QString lm = helpIdPieces.value(2);
|
||||||
helpIdPieces.removeAt(2);
|
helpIdPieces.removeAt(2);
|
||||||
helpId = helpIdPieces.join(QLatin1Char('.'));
|
helpId = helpIdPieces.join(QLatin1Char('.'));
|
||||||
if (!HelpManager::linksForIdentifier(helpId).isEmpty())
|
urlMap = HelpManager::linksForIdentifier(helpId);
|
||||||
|
if (!urlMap.isEmpty())
|
||||||
break;
|
break;
|
||||||
helpIdPieces.replace(1, lm);
|
helpIdPieces.replace(1, lm);
|
||||||
if (!HelpManager::linksForIdentifier(helpId).isEmpty())
|
urlMap = HelpManager::linksForIdentifier(helpId);
|
||||||
|
if (!urlMap.isEmpty())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
helpIdPieces.removeAt(1);
|
helpIdPieces.removeAt(1);
|
||||||
helpId = helpIdPieces.join(QLatin1Char('.'));
|
helpId = helpIdPieces.join(QLatin1Char('.'));
|
||||||
if (!HelpManager::linksForIdentifier(helpId).isEmpty())
|
urlMap = HelpManager::linksForIdentifier(helpId);
|
||||||
|
if (!urlMap.isEmpty())
|
||||||
break;
|
break;
|
||||||
return false;
|
return false;
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
|
// Check if the module name contains a major version.
|
||||||
|
QRegularExpression version("^([^\\d]*)(\\d+)\\.*\\d*$");
|
||||||
|
QRegularExpressionMatch m = version.match(moduleName);
|
||||||
|
if (m.hasMatch()) {
|
||||||
|
QMap<QString, QUrl> filteredUrlMap;
|
||||||
|
QStringRef maj = m.capturedRef(2);
|
||||||
|
for (auto x = urlMap.begin(); x != urlMap.end(); ++x) {
|
||||||
|
QString urlModuleName = x.value().path().split('/')[1];
|
||||||
|
if (urlModuleName.contains(maj))
|
||||||
|
filteredUrlMap.insert(x.key(), x.value());
|
||||||
|
}
|
||||||
|
if (!filteredUrlMap.isEmpty()) {
|
||||||
|
// Use the url as helpId, to disambiguate different versions
|
||||||
|
helpId = filteredUrlMap.first().toString();
|
||||||
|
const HelpItem helpItem(helpId, qName.join(QLatin1Char('.')), HelpItem::QmlComponent, filteredUrlMap);
|
||||||
|
setLastHelpItemIdentified(helpItem);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
setLastHelpItemIdentified(HelpItem(helpId, qName.join(QLatin1Char('.')), HelpItem::QmlComponent));
|
setLastHelpItemIdentified(HelpItem(helpId, qName.join(QLatin1Char('.')), HelpItem::QmlComponent));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user