Commit 8c17e3b3 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: Fix regression for import paths

The imports paths used by the sub component manger and meta info system
were not correctly resolved. The main reason was that the textDocument in
the text modifiers are just plain text buffers and do not containt
any url for the document.

This patch removes importPaths() from the TextModifier.
The ViewerContext can be stored in the TextToModelMerger and
does not have to be recreated when needed.

Change-Id: I17281caee23ddd51f6e36d5346bc3bd7c53005e8
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent b66155cf
......@@ -58,8 +58,6 @@ public:
virtual void deactivateChangeSignals();
virtual void reactivateChangeSignals();
virtual QStringList importPaths() const;
virtual bool renameId(const QString & /* oldId */, const QString & /* newId */) { return false; }
public slots:
......
......@@ -73,8 +73,6 @@ public:
virtual void deactivateChangeSignals();
virtual void reactivateChangeSignals();
virtual QStringList importPaths() const;
virtual bool renameId(const QString & /* oldId */, const QString & /* newId */) { return false; }
protected:
......
......@@ -203,6 +203,8 @@ public:
QString pathForImport(const Import &import);
QStringList importDirectories() const;
signals:
void errorsChanged(const QList<RewriterView::Error> &errors);
......
......@@ -84,7 +84,6 @@ public:
virtual void reactivateChangeSignals() = 0;
static QmlJS::Snapshot qmljsSnapshot();
virtual QStringList importPaths() const = 0;
virtual bool renameId(const QString &oldId, const QString &newId) = 0;
......
......@@ -128,6 +128,3 @@ void ComponentTextModifier::reactivateChangeSignals()
void ComponentTextModifier::contentsChange(int /*position*/, int /*charsRemoved*/, int /*charsAdded*/)
{
}
QStringList ComponentTextModifier::importPaths() const
{ return m_originalModifier->importPaths(); }
......@@ -61,6 +61,8 @@
#include "invalididexception.h"
#include "textmodifier.h"
#include <qmljs/qmljsmodelmanagerinterface.h>
/*!
\defgroup CoreModel
*/
......@@ -1823,6 +1825,9 @@ QString Model::pathForImport(const Import &import)
QStringList Model::importPaths() const
{
if (rewriterView())
return rewriterView()->importDirectories();
QStringList importPathList;
QString documentDirectoryPath = QFileInfo(fileUrl().toLocalFile()).absolutePath();
......@@ -1830,10 +1835,6 @@ QStringList Model::importPaths() const
if (!documentDirectoryPath.isEmpty())
importPathList.append(documentDirectoryPath);
if (textModifier()) {
importPathList.append(textModifier()->importPaths());
}
return importPathList;
}
......
......@@ -196,17 +196,3 @@ void PlainTextEditModifier::reactivateChangeSignals()
emit textChanged();
}
}
QStringList PlainTextEditModifier::importPaths() const
{
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
if (modelManager && textDocument()) {
QString documentFilePath = textDocument()->baseUrl().toLocalFile();
if (!documentFilePath.isEmpty()) {
QmlJS::Document::Ptr qmljsDocument = modelManager->snapshot().document(documentFilePath);
return modelManager->defaultVContext(QmlJS::Language::Qml, qmljsDocument, true).paths;
}
}
return QStringList();
}
......@@ -745,6 +745,11 @@ QString RewriterView::pathForImport(const Import &import)
return QString();
}
QStringList RewriterView::importDirectories() const
{
return m_textToModelMerger->vContext().paths;
}
void RewriterView::qmlTextChanged()
{
if (inErrorState())
......
......@@ -715,7 +715,7 @@ void TextToModelMerger::setupImports(const Document::Ptr &doc,
if (!import->fileName.isEmpty()) {
const QString strippedFileName = stripQuotes(import->fileName.toString());
const Import newImport = Import::createFileImport(strippedFileName,
version, as, m_rewriterView->textModifier()->importPaths());
version, as, m_rewriterView->importDirectories());
if (!existingImports.removeOne(newImport))
differenceHandler.modelMissesImport(newImport);
......@@ -727,7 +727,7 @@ void TextToModelMerger::setupImports(const Document::Ptr &doc,
}
const Import newImport =
Import::createLibraryImport(importUri, version, as, m_rewriterView->textModifier()->importPaths());
Import::createLibraryImport(importUri, version, as, m_rewriterView->importDirectories());
if (!existingImports.removeOne(newImport))
differenceHandler.modelMissesImport(newImport);
......@@ -833,9 +833,8 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
// qDebug() << "TextToModelMerger::load with data:" << data;
const QUrl url = m_rewriterView->model()->fileUrl();
const QStringList importPaths = m_rewriterView->textModifier()->importPaths();
setActive(true);
setActive(true);
try {
Snapshot snapshot = m_rewriterView->textModifier()->qmljsSnapshot();
......@@ -853,8 +852,8 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
return false;
}
snapshot.insert(doc);
QmlJS::ViewerContext vContext = QmlJS::ModelManagerInterface::instance()->defaultVContext(Language::Qml, doc, true);
ReadingContext ctxt(snapshot, doc, vContext);
m_vContext = QmlJS::ModelManagerInterface::instance()->defaultVContext(Language::Qml, doc, true);
ReadingContext ctxt(snapshot, doc, m_vContext);
m_scopeChain = QSharedPointer<const ScopeChain>(
new ScopeChain(ctxt.scopeChain()));
m_document = doc;
......@@ -867,7 +866,7 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
}
setupImports(doc, differenceHandler);
setupPossibleImports(snapshot, vContext);
setupPossibleImports(snapshot, m_vContext);
if (m_rewriterView->model()->imports().isEmpty()) {
const QmlJS::DiagnosticMessage diagnosticMessage(QmlJS::Severity::Error, AST::SourceLocation(0, 0, 0, 0), QCoreApplication::translate("QmlDesigner::TextToModelMerger", "No import statements found"));
......
......@@ -72,6 +72,9 @@ public:
const QmlJS::Document *document() const
{ return m_document.data(); }
const QmlJS::ViewerContext &vContext() const
{ return m_vContext; }
protected:
void setActive(bool active);
......@@ -145,6 +148,7 @@ private:
QTimer m_setupTimer;
QSet<ModelNode> m_setupComponentList;
QSet<ModelNode> m_setupCustomParserList;
QmlJS::ViewerContext m_vContext;
};
class DifferenceHandler
......
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