Commit 285e2ffb authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Only collect linker errors for the current file being checked.

Avoids bug where import errors would show up in all files.

Reviewed-by: Roberto Raggi
parent 7c04d11f
......@@ -174,7 +174,7 @@ Check::Check(Document::Ptr doc, const Snapshot &snapshot, const QStringList &imp
: _doc(doc)
, _snapshot(snapshot)
, _context(&_engine)
, _link(&_context, snapshot, importPaths)
, _link(&_context, doc, snapshot, importPaths)
, _scopeBuilder(doc, &_context)
{
}
......
......@@ -1305,7 +1305,7 @@ Context::~Context()
void Context::build(const QList<Node *> &astPath, QmlJS::Document::Ptr doc,
const QmlJS::Snapshot &snapshot, const QStringList &importPaths)
{
Link link(this, snapshot, importPaths);
Link link(this, doc, snapshot, importPaths);
link.scopeChainAt(doc, astPath);
}
......
......@@ -14,9 +14,10 @@ using namespace QmlJS;
using namespace QmlJS::Interpreter;
using namespace QmlJS::AST;
Link::Link(Context *context, const Snapshot &snapshot,
Link::Link(Context *context, const Document::Ptr &doc, const Snapshot &snapshot,
const QStringList &importPaths)
: _snapshot(snapshot)
: _doc(doc)
, _snapshot(snapshot)
, _context(context)
, _importPaths(importPaths)
{
......@@ -240,9 +241,8 @@ void Link::importFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc,
importNamespace->setProperty(targetName, importedDoc->bind()->rootObjectValue());
} else {
_diagnosticMessages.append(DiagnosticMessage(
DiagnosticMessage::Error, import->fileNameToken,
QCoreApplication::translate("QmlJS::Link", "could not find file or directory")));
error(doc, import->fileNameToken,
QCoreApplication::translate("QmlJS::Link", "could not find file or directory"));
}
}
......@@ -283,19 +283,16 @@ 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) {
_diagnosticMessages.append(DiagnosticMessage(
DiagnosticMessage::Error, import->versionToken,
QCoreApplication::translate("QmlJS::Link", "expected two numbers separated by a dot")));
error(doc, 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")));
error(doc, locationFromRange(import->firstSourceLocation(), import->lastSourceLocation()),
QCoreApplication::translate("QmlJS::Link", "package import requires a version number"));
return;
}
......@@ -339,10 +336,8 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A
}
}
_diagnosticMessages.append(DiagnosticMessage(
DiagnosticMessage::Error,
locationFromRange(import->firstSourceLocation(), import->lastSourceLocation()),
QCoreApplication::translate("QmlJS::Link", "package not found")));
error(doc, locationFromRange(import->firstSourceLocation(), import->lastSourceLocation()),
QCoreApplication::translate("QmlJS::Link", "package not found"));
}
UiQualifiedId *Link::qualifiedTypeNameId(Node *node)
......@@ -354,3 +349,9 @@ UiQualifiedId *Link::qualifiedTypeNameId(Node *node)
else
return 0;
}
void Link::error(const Document::Ptr &doc, const AST::SourceLocation &loc, const QString &message)
{
if (doc->fileName() == _doc->fileName())
_diagnosticMessages.append(DiagnosticMessage(DiagnosticMessage::Error, loc, message));
}
......@@ -20,7 +20,8 @@ class Link
{
public:
// Link all documents in snapshot
Link(Interpreter::Context *context, const Snapshot &snapshot, const QStringList &importPaths);
Link(Interpreter::Context *context, const Document::Ptr &doc, const Snapshot &snapshot,
const QStringList &importPaths);
~Link();
// Get the scope chain for the currentObject inside doc.
......@@ -49,7 +50,10 @@ private:
AST::UiImport *import);
void importObject(Bind *bind, const QString &name, Interpreter::ObjectValue *object, NameId *targetNamespace);
void error(const Document::Ptr &doc, const AST::SourceLocation &loc, const QString &message);
private:
Document::Ptr _doc;
Snapshot _snapshot;
Interpreter::Context *_context;
QMultiHash<QString, Document::Ptr> _documentByPath;
......
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