diff --git a/src/libs/qmljs/qmljscheck.cpp b/src/libs/qmljs/qmljscheck.cpp index 7ee01be8e8ab43db7f132aa360e7fa3eb60ead21..996d8de4ab559a0378b3f000d57fe6a6ea278802 100644 --- a/src/libs/qmljs/qmljscheck.cpp +++ b/src/libs/qmljs/qmljscheck.cpp @@ -187,6 +187,7 @@ QList<DiagnosticMessage> Check::operator()() { _messages.clear(); Node::accept(_doc->ast(), this); + _messages.append(_link.diagnosticMessages()); return _messages; } diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp index 24d417baa87886238828b3fd008b19c3f0564014..24c4b0bc759ed2fa07714e4a88c6024ec2629eec 100644 --- a/src/libs/qmljs/qmljslink.cpp +++ b/src/libs/qmljs/qmljslink.cpp @@ -8,6 +8,7 @@ #include <QtCore/QFileInfo> #include <QtCore/QDir> #include <QtCore/QDebug> +#include <QtCore/QCoreApplication> using namespace QmlJS; using namespace QmlJS::Interpreter; @@ -33,6 +34,11 @@ Interpreter::Engine *Link::engine() return _context->engine(); } +QList<DiagnosticMessage> Link::diagnosticMessages() const +{ + return _diagnosticMessages; +} + void Link::scopeChainAt(Document::Ptr doc, const QList<Node *> &astPath) { ScopeChain &scopeChain = _context->scopeChain(); @@ -234,10 +240,21 @@ void Link::importFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, importNamespace->setProperty(targetName, importedDoc->bind()->rootObjectValue()); } else { - // error! + _diagnosticMessages.append(DiagnosticMessage( + DiagnosticMessage::Error, import->fileNameToken, + QCoreApplication::translate("QmlJS::Link", "could not find file or directory"))); } } +static SourceLocation locationFromRange(const SourceLocation &start, + const SourceLocation &end) +{ + return SourceLocation(start.offset, + end.end() - start.begin(), + start.startLine, + start.startColumn); +} + /* import Qt 4.6 import Qt 4.6 as Xxx @@ -266,13 +283,20 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A const QString versionString = doc->source().mid(import->versionToken.offset, import->versionToken.length); const int dotIdx = versionString.indexOf(QLatin1Char('.')); if (dotIdx == -1) { - // only major (which is probably invalid, but let's handle it anyway) - majorVersion = versionString.toInt(); - minorVersion = 0; // ### TODO: Check with magic version numbers above + _diagnosticMessages.append(DiagnosticMessage( + DiagnosticMessage::Error, import->versionToken, + QCoreApplication::translate("QmlJS::Link", "expected two numbers separated by a dot"))); + return; } else { majorVersion = versionString.left(dotIdx).toInt(); minorVersion = versionString.mid(dotIdx + 1).toInt(); } + } else { + _diagnosticMessages.append(DiagnosticMessage( + DiagnosticMessage::Error, + locationFromRange(import->firstSourceLocation(), import->lastSourceLocation()), + QCoreApplication::translate("QmlJS::Link", "package import requires a version number"))); + return; } // if the package is in the meta type system, use it @@ -280,6 +304,7 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A foreach (QmlObjectValue *object, engine()->metaTypeSystem().staticTypesForImport(package, majorVersion, minorVersion)) { namespaceObject->setProperty(object->className(), object); } + return; } else { // check the filesystem QStringList localImportPaths = _importPaths; @@ -309,9 +334,14 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A } } - break; + return; } } + + _diagnosticMessages.append(DiagnosticMessage( + DiagnosticMessage::Error, + locationFromRange(import->firstSourceLocation(), import->lastSourceLocation()), + QCoreApplication::translate("QmlJS::Link", "package not found"))); } UiQualifiedId *Link::qualifiedTypeNameId(Node *node) diff --git a/src/libs/qmljs/qmljslink.h b/src/libs/qmljs/qmljslink.h index b12e0aa46fe4e72fabb95660563c0357caee1ccd..87ca0ad2d6887fd429ee1a8d57e249e32beae3ee 100644 --- a/src/libs/qmljs/qmljslink.h +++ b/src/libs/qmljs/qmljslink.h @@ -26,6 +26,8 @@ public: // Get the scope chain for the currentObject inside doc. void scopeChainAt(Document::Ptr doc, const QList<AST::Node *> &astPath = QList<AST::Node *>()); + QList<DiagnosticMessage> diagnosticMessages() const; + private: Interpreter::Engine *engine(); @@ -52,6 +54,8 @@ private: Interpreter::Context *_context; QMultiHash<QString, Document::Ptr> _documentByPath; const QStringList _importPaths; + + QList<DiagnosticMessage> _diagnosticMessages; }; } // namespace QmlJS