Commit 2fc150b9 authored by Fawzi Mohamed's avatar Fawzi Mohamed

qmljs: scan imports

Change-Id: Ied59f5d56c5816d9da57f23a619d604acec76000
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 7fb87fbb
......@@ -212,7 +212,7 @@ void Document::setLanguage(Language::Enum l)
QString Document::importId() const
{
return path();
return _fileName;
}
QByteArray Document::fingerprint() const
......@@ -501,7 +501,7 @@ void Snapshot::insert(const Document::Ptr &document, bool allowInvalid)
CoreImport cImport;
cImport.importId = document->importId();
cImport.language = document->language();
cImport.possibleExports << Export(ImportKey(ImportType::File, document->path()),
cImport.possibleExports << Export(ImportKey(ImportType::File, fileName),
QString(), true);
cImport.fingerprint = document->fingerprint();
_dependencies.addCoreImport(cImport);
......@@ -512,13 +512,34 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
{
QTC_CHECK(info.fingerprint() == info.calculateFingerprint());
_libraries.insert(QDir::cleanPath(path), info);
if (!info.wasFound()) return;
CoreImport cImport;
cImport.importId = path;
cImport.language = Language::Unknown;
QSet<ImportKey> packages;
foreach (const ModuleApiInfo &moduleInfo, info.moduleApis()) {
ImportKey iKey(ImportType::Library, moduleInfo.uri, moduleInfo.version.majorVersion(),
moduleInfo.version.minorVersion());
cImport.possibleExports << Export(iKey, path, true);
packages.insert(iKey);
}
foreach (const LanguageUtils::FakeMetaObject::ConstPtr &metaO, info.metaObjects()) {
foreach (const LanguageUtils::FakeMetaObject::Export &e, metaO->exports()) {
ImportKey iKey(ImportType::Library, e.package, e.version.majorVersion(),
e.version.minorVersion());
packages.insert(iKey);
}
}
QStringList splitPath = path.split(QLatin1Char('/'));
foreach (const ImportKey &importKey, packages) {
QString requiredPath = QStringList(splitPath.mid(0, splitPath.size() - importKey.splitPath.size()))
.join(QLatin1Char('/'));
cImport.possibleExports << Export(importKey, requiredPath, true);
}
foreach (const QmlDirParser::Component &component, info.components()) {
foreach (const Export &e, cImport.possibleExports)
// renaming of type name not really represented here... fix?
_dependencies.addExport(component.fileName, e.exportName, e.pathRequired);
}
cImport.fingerprint = info.fingerprint();
_dependencies.addCoreImport(cImport);
......
......@@ -201,6 +201,9 @@ public:
bool wasScanned() const
{ return _status != NotScanned; }
bool wasFound() const
{ return _status != NotFound; }
PluginTypeInfoStatus pluginTypeInfoStatus() const
{ return _dumpStatus; }
......
......@@ -40,6 +40,8 @@
namespace QmlJS {
static bool debugImportDependencies = false;
ImportKind::Enum toImportKind(ImportType::Enum type)
{
switch (type) {
......@@ -408,6 +410,40 @@ ImportKey::DirCompareInfo ImportKey::compareDir(const ImportKey &superDir) const
return SameDir;
}
QString ImportKey::toString() const
{
QString res;
switch (type) {
case ImportType::UnknownFile:
case ImportType::File:
res = path();
break;
case ImportType::Directory:
case ImportType::ImplicitDirectory:
res = path() + QLatin1Char('/');
break;
case ImportType::QrcDirectory:
res = QLatin1String("qrc:") + path() + QLatin1Char('/');
break;
case ImportType::QrcFile:
res = QLatin1String("qrc:") + path() + QLatin1Char('/');
break;
case ImportType::Invalid:
res = path();
break;
case ImportType::Library:
res = splitPath.join(QLatin1Char('.'));
break;
}
if (majorVersion != LanguageUtils::ComponentVersion::NoVersion
|| minorVersion != LanguageUtils::ComponentVersion::NoVersion)
return res + QLatin1Char(' ') + QString::number(majorVersion)
+ QLatin1Char('.') + QString::number(minorVersion);
return res;
}
uint qHash(const ImportKey &info)
{
uint res = ::qHash(info.type) ^
......@@ -688,6 +724,12 @@ void ImportDependencies::addCoreImport(const CoreImport &import)
newImport.possibleExports.append(e);
}
m_coreImports.insert(newImport.importId, newImport);
if (debugImportDependencies) {
QDebug dbg(qDebug());
dbg << "added import "<< newImport.importId << " for";
foreach (const Export &e, newImport.possibleExports)
dbg << " " << e.exportName.toString() << "(" << e.pathRequired << ")";
}
}
void ImportDependencies::removeCoreImport(const QString &importId)
......@@ -705,6 +747,8 @@ void ImportDependencies::removeCoreImport(const QString &importId)
cImport.possibleExports = newExports;
else
m_coreImports.remove(importId);
if (debugImportDependencies)
qDebug() << "removed import with id:"<< importId;
}
void ImportDependencies::addExport(const QString &importId, const ImportKey &importKey,
......@@ -719,6 +763,9 @@ void ImportDependencies::addExport(const QString &importId, const ImportKey &imp
}
CoreImport &importValue = m_coreImports[importId];
importValue.possibleExports.append(Export(importKey, requiredPath, false));
if (debugImportDependencies)
qDebug() << "added export "<< importKey.toString() << " for id " <<importId
<< " (" << requiredPath << ")";
}
void ImportDependencies::removeExport(const QString &importId, const ImportKey &importKey,
......@@ -726,28 +773,31 @@ void ImportDependencies::removeExport(const QString &importId, const ImportKey &
{
if (!m_coreImports.contains(importId)) {
qDebug() << "non existing core import for removeExport(" << importId << ", "
<< importKey.path() << ")";
<< importKey.toString() << ")";
} else {
CoreImport &importValue = m_coreImports[importId];
if (!importValue.possibleExports.removeOne(Export(importKey, requiredPath, false))) {
qDebug() << "non existing export for removeExport(" << importId << ", "
<< importKey.path() << ")";
<< importKey.toString() << ")";
}
if (importValue.possibleExports.isEmpty() && importValue.fingerprint.isEmpty())
m_coreImports.remove(importId);
}
if (!m_importCache.contains(importKey)) {
qDebug() << "missing possibleExport for " << importKey.path() << " when removing export of "
qDebug() << "missing possibleExport for " << importKey.toString() << " when removing export of "
<< importId;
} else {
QStringList &cImp = m_importCache[importKey];
if (!cImp.removeOne(importId)) {
qDebug() << "missing possibleExport backpointer for " << importKey.path() << " to "
qDebug() << "missing possibleExport backpointer for " << importKey.toString() << " to "
<< importId;
}
if (cImp.isEmpty())
m_importCache.remove(importKey);
}
if (debugImportDependencies)
qDebug() << "removed export "<< importKey.toString() << " for id " << importId
<< " (" << requiredPath << ")";
}
void ImportDependencies::iterateOnCoreImports(
......@@ -774,6 +824,8 @@ void ImportDependencies::iterateOnLibraryImports(
iter_t i = m_importCache.lowerBound(firstLib);
iter_t end = m_importCache.constEnd();
while (i != end && i.key().type == ImportType::Library) {
if (debugImportDependencies)
qDebug() << "libloop:" << i.key().toString() << i.value();
foreach (const QString &cImportName, i.value()) {
CoreImport cImport = coreImport(cImportName);
if (vContext.languageIsCompatible(cImport.language)) {
......@@ -781,6 +833,9 @@ void ImportDependencies::iterateOnLibraryImports(
if (e.visibleInVContext(vContext) && e.exportName.type == ImportType::Library) {
ImportMatchStrength m = e.exportName.matchImport(i.key(), vContext);
if (m.hasMatch()) {
if (debugImportDependencies)
qDebug() << "import iterate:" << e.exportName.toString()
<< " (" << e.pathRequired << "), id:" << cImport.importId;
if (!iterF(m, e, cImport))
return;
}
......
......@@ -118,6 +118,7 @@ public:
int compare(const ImportKey &other) const;
bool isDirectoryLike() const;
DirCompareInfo compareDir(const ImportKey &other) const;
QString toString() const;
};
uint qHash(const ImportKey &info);
......
......@@ -64,6 +64,7 @@ public:
attachPID(-1),
useTerminal(false),
breakOnMain(false),
continueAfterAttach(false),
multiProcess(false),
languages(AnyLanguage),
qmlServerAddress(QLatin1String("127.0.0.1")),
......@@ -102,6 +103,7 @@ public:
qint64 attachPID;
bool useTerminal;
bool breakOnMain;
bool continueAfterAttach;
bool multiProcess;
DebuggerLanguages languages;
......
......@@ -34,6 +34,7 @@
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <qmljs/qmljsqrcparser.h>
#include <qmljs/qmljsconstants.h>
#include <cplusplus/CppDocument.h>
#include <utils/qtcoverride.h>
......@@ -135,11 +136,22 @@ protected:
QFuture<void> refreshSourceFiles(const QStringList &sourceFiles,
bool emitDocumentOnDiskChanged);
static void parseLoop(QSet<QString> &scannedPaths, QSet<QString> &newLibraries,
WorkingCopy workingCopy, QStringList files, ModelManager *modelManager,
QmlJS::Language::Enum mainLanguage, bool emitDocChangedOnDisk,
Utils::function<bool (qreal)> reportProgress);
static void parse(QFutureInterface<void> &future,
WorkingCopy workingCopy,
QStringList files,
ModelManager *modelManager,
QmlJS::Language::Enum mainLanguage,
bool emitDocChangedOnDisk);
static void importScan(QFutureInterface<void> &future,
WorkingCopy workingCopy,
QStringList paths,
ModelManager *modelManager,
QmlJS::Language::Enum mainLanguage,
bool emitDocChangedOnDisk);
void loadQmlTypeDescriptions();
void loadQmlTypeDescriptions(const QString &path);
......@@ -167,6 +179,7 @@ private:
QmlJS::QmlLanguageBundles m_activeBundles;
QmlJS::QmlLanguageBundles m_extendedBundles;
QmlJS::ViewerContext m_vContext;
QSet<QString> m_scannedPaths;
QTimer *m_updateCppQmlTypesTimer;
QTimer *m_asyncResetTimer;
......
......@@ -43,6 +43,7 @@ const char JS_MIMETYPE[] = "application/javascript";
const char JSON_MIMETYPE[] = "application/json";
const char TASK_INDEX[] = "QmlJSEditor.TaskIndex";
const char TASK_IMPORT_SCAN[] = "QmlJSEditor.TaskImportScan";
const char QML_JS_CODE_STYLE_SETTINGS_ID[] = "A.Code Style";
const char QML_JS_CODE_STYLE_SETTINGS_NAME[] = QT_TRANSLATE_NOOP("QmlJSTools", "Code Style");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment