Commit 08163f3b authored by Fawzi Mohamed's avatar Fawzi Mohamed

qmljs: better defaults, more uniform handling of paths

Uniform handling of the different qml dialects.

Now paths for a given document prefer the project of that document.

For Qt the following sequence is used:
- Qt of the project of the document
- Qt of the active target
- Qt used to run creator

Currently all paths of the open projects are still merged, but that
can be changed.

Change-Id: Iacf28d63184c05e2bcdfe0210ec472d2bf140d66
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 0ee87049
......@@ -177,7 +177,7 @@ public:
void updateLibraryInfo(const QString &path, const QmlJS::LibraryInfo &info);
void emitDocumentChangedOnDisk(QmlJS::Document::Ptr doc);
void updateQrcFile(const QString &path);
ProjectInfo projectInfoForPath(QString path);
ProjectInfo projectInfoForPath(QString path) const;
QStringList importPaths() const;
QmlJS::QmlLanguageBundles activeBundles() const;
......@@ -188,17 +188,16 @@ public:
CppDataHash cppData() const;
LibraryInfo builtins(const Document::Ptr &doc) const;
virtual ViewerContext completeVContext(const ViewerContext &vCtx,
const Document::Ptr &doc = Document::Ptr(0)) const;
virtual ViewerContext defaultVContext(bool autoComplete = true,
const Document::Ptr &doc = Document::Ptr(0)) const;
virtual void setDefaultVContext(const ViewerContext &vContext);
ViewerContext completeVContext(const ViewerContext &vCtx,
const Document::Ptr &doc = Document::Ptr(0)) const;
ViewerContext defaultVContext(Language::Enum language = Language::Qml,
const Document::Ptr &doc = Document::Ptr(0),
bool autoComplete = true) const;
void setDefaultVContext(const ViewerContext &vContext);
virtual ProjectInfo defaultProjectInfo() const;
// Blocks until all parsing threads are done. Used for testing.
void joinAllThreads();
virtual ModelManagerInterface::ProjectInfo defaultProjectInfo() const;
public slots:
virtual void resetCodeModel();
void removeProjectInfo(ProjectExplorer::Project *project);
......@@ -256,7 +255,7 @@ private:
QStringList m_defaultImportPaths;
QmlJS::QmlLanguageBundles m_activeBundles;
QmlJS::QmlLanguageBundles m_extendedBundles;
QmlJS::ViewerContext m_vContext;
QHash<Language::Enum, QmlJS::ViewerContext> m_defaultVContexts;
bool m_shouldScanImports;
QSet<QString> m_scannedPaths;
......
......@@ -76,4 +76,10 @@ bool ViewerContext::languageIsCompatible(Language::Enum l) const
return true;
}
void ViewerContext::maybeAddPath(const QString &path)
{
if (!path.isEmpty() && !paths.contains(path))
paths.append(path);
}
} // namespace QmlJS
......@@ -42,8 +42,10 @@ class QMLJS_EXPORT ViewerContext
public:
enum Flags {
Complete,
AddAllPathsAndDefaultSelectors,
AddAllPaths,
AddQtPath
AddDefaultPaths,
AddDefaultPathsAndSelectors
};
ViewerContext();
......@@ -52,6 +54,7 @@ public:
Flags flags = AddAllPaths);
bool languageIsCompatible(Language::Enum l) const;
void maybeAddPath(const QString &path);
QStringList selectors;
QStringList paths;
......
......@@ -103,7 +103,7 @@ static inline bool checkIfDerivedFromItem(const QString &fileName)
snapshot.insert(document);
QmlJS::Link link(snapshot, modelManager->defaultVContext(), QmlJS::ModelManagerInterface::instance()->builtins(document));
QmlJS::Link link(snapshot, modelManager->defaultVContext(document->language(), document), QmlJS::ModelManagerInterface::instance()->builtins(document));
QList<QmlJS::DiagnosticMessage> diagnosticLinkMessages;
QmlJS::ContextPtr context = link(document, &diagnosticLinkMessages);
......
......@@ -831,7 +831,7 @@ static void find_helper(QFutureInterface<FindReferences::Usage> &future,
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
Link link(snapshot, modelManager->defaultVContext(), modelManager->builtins(doc));
Link link(snapshot, modelManager->defaultVContext(doc->language(), doc), modelManager->builtins(doc));
ContextPtr context = link();
ScopeChain scopeChain(doc, context);
......
......@@ -122,7 +122,7 @@ QmlJSTools::SemanticInfo SemanticInfoUpdater::makeNewSemanticInfo(const QmlJS::D
ModelManagerInterface *modelManager = ModelManagerInterface::instance();
Link link(semanticInfo.snapshot, modelManager->defaultVContext(), modelManager->builtins(doc));
Link link(semanticInfo.snapshot, modelManager->defaultVContext(doc->language(), doc), modelManager->builtins(doc));
semanticInfo.context = link(doc, &semanticInfo.semanticMessages);
ScopeChain *scopeChain = new ScopeChain(doc, semanticInfo.context);
......
......@@ -161,7 +161,7 @@ void QmlTaskManager::updateMessagesNow(bool updateSemantic)
QFuture<FileErrorMessages> future =
QtConcurrent::run<FileErrorMessages>(
&collectMessages, modelManager->newestSnapshot(), modelManager->projectInfos(),
modelManager->defaultVContext(), updateSemantic);
modelManager->defaultVContext(Language::Unknown), updateSemantic);
m_messageCollector.setFuture(future);
}
......
......@@ -61,6 +61,8 @@
#include <QTimer>
#include <QRegExp>
#include <QtAlgorithms>
#include <QLibraryInfo>
#include <qglobal.h>
#include <QDebug>
......@@ -87,8 +89,8 @@ ModelManagerInterface::ProjectInfo QmlJSTools::defaultProjectInfoForProject(
globs.append(MimeGlobPattern(QLatin1String("*.qmltypes")));
globs.append(MimeGlobPattern(QLatin1String("*.qmlproject")));
}
foreach (const QString &filePath
, project->files(ProjectExplorer::Project::ExcludeGeneratedFiles))
foreach (const QString &filePath,
project->files(ProjectExplorer::Project::ExcludeGeneratedFiles))
foreach (const MimeGlobPattern &glob, globs)
if (glob.matches(filePath))
projectInfo.sourceFiles << filePath;
......@@ -117,6 +119,10 @@ ModelManagerInterface::ProjectInfo QmlJSTools::defaultProjectInfoForProject(
projectInfo.qtQmlPath = qtVersion->qmakeProperty("QT_INSTALL_QML");
projectInfo.qtImportsPath = qtVersion->qmakeProperty("QT_INSTALL_IMPORTS");
projectInfo.qtVersionString = qtVersion->qtVersionString();
} else {
projectInfo.qtQmlPath = QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath);
projectInfo.qtImportsPath = QLibraryInfo::location(QLibraryInfo::ImportsPath);
projectInfo.qtVersionString = QLatin1String(qVersion());
}
if (projectInfo.tryQmlDump) {
......@@ -251,11 +257,9 @@ ModelManagerInterface::WorkingCopy ModelManager::workingCopyInternal() const
ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfo() const
{
ProjectExplorer::Project *activeProject = ProjectExplorer::SessionManager::startupProject();
if (!activeProject)
return ModelManagerInterface::ProjectInfo();
return projectInfo(activeProject);
// needs to be performed in the ui therad (change?)
ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject();
return defaultProjectInfoForProject(currentProject);
}
// Check whether fileMimeType is the same or extends knownMimeType
......@@ -279,4 +283,3 @@ void ModelManager::addTaskInternal(QFuture<void> result, const QString &msg, con
{
ProgressManager::addTask(result, msg, taskId);
}
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