2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-09-04 16:51:11 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2009-09-04 16:51:11 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-09-04 16:51:11 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2009-09-04 16:51:11 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2009-09-04 16:51:11 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2010-02-15 13:49:00 +01:00
|
|
|
#ifndef QMLJSMODELMANAGERINTERFACE_H
|
|
|
|
|
#define QMLJSMODELMANAGERINTERFACE_H
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2010-06-09 15:56:03 +02:00
|
|
|
#include "qmljs_global.h"
|
2012-12-06 17:20:58 +01:00
|
|
|
#include "qmljsbundle.h"
|
2014-01-23 14:28:31 +01:00
|
|
|
#include "qmljsdocument.h"
|
|
|
|
|
#include "qmljsqrcparser.h"
|
2014-07-22 19:06:44 +02:00
|
|
|
#include "qmljsdialect.h"
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
|
#include <cplusplus/CppDocument.h>
|
2010-10-26 15:39:37 +02:00
|
|
|
#include <utils/environment.h>
|
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
#include <QFuture>
|
|
|
|
|
#include <QFutureSynchronizer>
|
|
|
|
|
#include <QHash>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QObject>
|
|
|
|
|
#include <QPointer>
|
2014-01-23 14:28:31 +01:00
|
|
|
#include <QStringList>
|
2015-03-04 16:46:23 +01:00
|
|
|
|
|
|
|
|
QT_FORWARD_DECLARE_CLASS(QTimer)
|
2010-06-22 12:54:19 +02:00
|
|
|
|
2014-02-11 21:55:42 +02:00
|
|
|
namespace ProjectExplorer { class Project; }
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2010-01-18 16:15:23 +01:00
|
|
|
namespace QmlJS {
|
2010-01-14 16:22:43 +01:00
|
|
|
|
2010-06-09 15:56:03 +02:00
|
|
|
class Snapshot;
|
2014-01-23 14:28:31 +01:00
|
|
|
class PluginDumper;
|
2010-01-14 16:22:43 +01:00
|
|
|
|
2010-06-09 15:56:03 +02:00
|
|
|
class QMLJS_EXPORT ModelManagerInterface: public QObject
|
2009-09-04 16:51:11 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
2010-06-22 12:54:19 +02:00
|
|
|
public:
|
2013-05-21 11:35:15 +02:00
|
|
|
enum QrcResourceSelector {
|
|
|
|
|
ActiveQrcResources,
|
|
|
|
|
AllQrcResources
|
|
|
|
|
};
|
|
|
|
|
|
2010-06-22 12:54:19 +02:00
|
|
|
class ProjectInfo
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ProjectInfo()
|
2013-04-24 12:21:21 +02:00
|
|
|
: tryQmlDump(false), qmlDumpHasRelocatableFlag(true)
|
2010-06-22 12:54:19 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
ProjectInfo(QPointer<ProjectExplorer::Project> project)
|
|
|
|
|
: project(project)
|
2013-04-24 12:21:21 +02:00
|
|
|
, tryQmlDump(false), qmlDumpHasRelocatableFlag(true)
|
2010-06-22 12:54:19 +02:00
|
|
|
{ }
|
|
|
|
|
|
2015-06-02 13:23:04 +02:00
|
|
|
explicit operator bool() const
|
2010-06-22 12:54:19 +02:00
|
|
|
{ return ! project.isNull(); }
|
|
|
|
|
|
|
|
|
|
bool isValid() const
|
|
|
|
|
{ return ! project.isNull(); }
|
|
|
|
|
|
|
|
|
|
bool isNull() const
|
|
|
|
|
{ return project.isNull(); }
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
|
|
|
|
QPointer<ProjectExplorer::Project> project;
|
|
|
|
|
QStringList sourceFiles;
|
2014-07-22 19:06:44 +02:00
|
|
|
PathsAndLanguages importPaths;
|
2013-05-21 11:35:15 +02:00
|
|
|
QStringList activeResourceFiles;
|
|
|
|
|
QStringList allResourceFiles;
|
2011-09-21 15:54:07 +02:00
|
|
|
|
|
|
|
|
// whether trying to run qmldump makes sense
|
|
|
|
|
bool tryQmlDump;
|
2013-04-24 12:21:21 +02:00
|
|
|
bool qmlDumpHasRelocatableFlag;
|
2010-09-27 17:22:57 +02:00
|
|
|
QString qmlDumpPath;
|
2011-10-07 14:04:06 +02:00
|
|
|
::Utils::Environment qmlDumpEnvironment;
|
2011-09-21 15:54:07 +02:00
|
|
|
|
2011-06-28 12:01:56 +02:00
|
|
|
QString qtImportsPath;
|
2012-12-07 09:25:48 +01:00
|
|
|
QString qtQmlPath;
|
2011-06-28 12:01:56 +02:00
|
|
|
QString qtVersionString;
|
2012-12-06 17:20:58 +01:00
|
|
|
QmlJS::QmlLanguageBundles activeBundle;
|
|
|
|
|
QmlJS::QmlLanguageBundles extendedBundle;
|
2010-06-22 12:54:19 +02:00
|
|
|
};
|
|
|
|
|
|
2010-09-24 14:05:34 +02:00
|
|
|
class WorkingCopy
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
typedef QHash<QString, QPair<QString, int> > Table;
|
|
|
|
|
|
|
|
|
|
void insert(const QString &fileName, const QString &source, int revision = 0)
|
|
|
|
|
{ _elements.insert(fileName, qMakePair(source, revision)); }
|
|
|
|
|
|
|
|
|
|
bool contains(const QString &fileName) const
|
|
|
|
|
{ return _elements.contains(fileName); }
|
|
|
|
|
|
|
|
|
|
QString source(const QString &fileName) const
|
|
|
|
|
{ return _elements.value(fileName).first; }
|
|
|
|
|
|
|
|
|
|
QPair<QString, int> get(const QString &fileName) const
|
|
|
|
|
{ return _elements.value(fileName); }
|
|
|
|
|
|
|
|
|
|
Table all() const
|
|
|
|
|
{ return _elements; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Table _elements;
|
|
|
|
|
};
|
|
|
|
|
|
2011-08-25 12:35:55 +02:00
|
|
|
class CppData
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QList<LanguageUtils::FakeMetaObject::ConstPtr> exportedTypes;
|
2011-09-16 10:35:48 +02:00
|
|
|
QHash<QString, QString> contextProperties;
|
2011-08-25 12:35:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef QHash<QString, CppData> CppDataHash;
|
2014-07-16 16:21:40 +02:00
|
|
|
typedef QHashIterator<QString, CppData> CppDataHashIterator;
|
2011-01-06 10:01:45 +01:00
|
|
|
|
2009-09-04 16:51:11 +02:00
|
|
|
public:
|
2010-02-15 13:49:00 +01:00
|
|
|
ModelManagerInterface(QObject *parent = 0);
|
|
|
|
|
virtual ~ModelManagerInterface();
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
static Dialect guessLanguageOfFile(const QString &fileName);
|
|
|
|
|
static QStringList globPatternsForLanguages(const QList<Dialect> languages);
|
2010-07-08 14:38:47 +02:00
|
|
|
static ModelManagerInterface *instance();
|
2014-01-23 14:28:31 +01:00
|
|
|
static void writeWarning(const QString &msg);
|
|
|
|
|
static WorkingCopy workingCopy();
|
|
|
|
|
|
|
|
|
|
QmlJS::Snapshot snapshot() const;
|
|
|
|
|
QmlJS::Snapshot newestSnapshot() const;
|
|
|
|
|
|
2014-04-29 16:39:16 +02:00
|
|
|
void activateScan();
|
2014-01-23 14:28:31 +01:00
|
|
|
void updateSourceFiles(const QStringList &files,
|
|
|
|
|
bool emitDocumentOnDiskChanged);
|
|
|
|
|
void fileChangedOnDisk(const QString &path);
|
|
|
|
|
void removeFiles(const QStringList &files);
|
|
|
|
|
QStringList filesAtQrcPath(const QString &path, const QLocale *locale = 0,
|
|
|
|
|
ProjectExplorer::Project *project = 0,
|
|
|
|
|
QrcResourceSelector resources = AllQrcResources);
|
|
|
|
|
QMap<QString,QStringList> filesInQrcPath(const QString &path,
|
|
|
|
|
const QLocale *locale = 0,
|
|
|
|
|
ProjectExplorer::Project *project = 0,
|
|
|
|
|
bool addDirs = false,
|
|
|
|
|
QrcResourceSelector resources = AllQrcResources);
|
|
|
|
|
|
|
|
|
|
QList<ProjectInfo> projectInfos() const;
|
2014-06-30 11:56:28 +02:00
|
|
|
ProjectInfo projectInfo(ProjectExplorer::Project *project,
|
|
|
|
|
const ModelManagerInterface::ProjectInfo &defaultValue = ProjectInfo()) const;
|
2014-01-23 14:28:31 +01:00
|
|
|
void updateProjectInfo(const ProjectInfo &pinfo, ProjectExplorer::Project *p);
|
|
|
|
|
|
|
|
|
|
void updateDocument(QmlJS::Document::Ptr doc);
|
|
|
|
|
void updateLibraryInfo(const QString &path, const QmlJS::LibraryInfo &info);
|
|
|
|
|
void emitDocumentChangedOnDisk(QmlJS::Document::Ptr doc);
|
|
|
|
|
void updateQrcFile(const QString &path);
|
2015-04-26 23:59:36 +03:00
|
|
|
ProjectInfo projectInfoForPath(const QString &path) const;
|
|
|
|
|
QList<ProjectInfo> allProjectInfosForPath(const QString &path) const;
|
2014-11-06 16:24:26 +01:00
|
|
|
bool isIdle() const ;
|
2014-01-23 14:28:31 +01:00
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
PathsAndLanguages importPaths() const;
|
2014-01-23 14:28:31 +01:00
|
|
|
QmlJS::QmlLanguageBundles activeBundles() const;
|
|
|
|
|
QmlJS::QmlLanguageBundles extendedBundles() const;
|
|
|
|
|
|
|
|
|
|
void loadPluginTypes(const QString &libraryPath, const QString &importPath,
|
|
|
|
|
const QString &importUri, const QString &importVersion);
|
|
|
|
|
|
|
|
|
|
CppDataHash cppData() const;
|
|
|
|
|
LibraryInfo builtins(const Document::Ptr &doc) const;
|
2014-04-11 23:07:52 +02:00
|
|
|
ViewerContext completeVContext(const ViewerContext &vCtx,
|
|
|
|
|
const Document::Ptr &doc = Document::Ptr(0)) const;
|
2014-07-22 19:06:44 +02:00
|
|
|
ViewerContext defaultVContext(Dialect language = Dialect::Qml,
|
2014-04-11 23:07:52 +02:00
|
|
|
const Document::Ptr &doc = Document::Ptr(0),
|
|
|
|
|
bool autoComplete = true) const;
|
|
|
|
|
void setDefaultVContext(const ViewerContext &vContext);
|
|
|
|
|
virtual ProjectInfo defaultProjectInfo() const;
|
2014-07-24 11:48:30 +02:00
|
|
|
virtual ProjectInfo defaultProjectInfoForProject(ProjectExplorer::Project *project) const;
|
|
|
|
|
|
2013-10-16 15:08:27 +02:00
|
|
|
|
2011-07-12 11:11:26 +02:00
|
|
|
// Blocks until all parsing threads are done. Used for testing.
|
2014-01-23 14:28:31 +01:00
|
|
|
void joinAllThreads();
|
2014-06-26 13:52:36 +02:00
|
|
|
|
|
|
|
|
QmlJS::Document::Ptr ensuredGetDocumentForPath(const QString &filePath);
|
2014-07-29 17:48:34 +02:00
|
|
|
static void importScan(QFutureInterface<void> &future,
|
|
|
|
|
WorkingCopy workingCopyInternal,
|
|
|
|
|
PathsAndLanguages paths,
|
|
|
|
|
ModelManagerInterface *modelManager,
|
2014-11-10 13:23:44 +01:00
|
|
|
bool emitDocChangedOnDisk, bool libOnly = true);
|
2014-01-23 14:28:31 +01:00
|
|
|
public slots:
|
|
|
|
|
virtual void resetCodeModel();
|
|
|
|
|
void removeProjectInfo(ProjectExplorer::Project *project);
|
2009-11-11 10:10:00 +01:00
|
|
|
signals:
|
2010-01-18 16:15:23 +01:00
|
|
|
void documentUpdated(QmlJS::Document::Ptr doc);
|
2010-04-16 12:42:12 +02:00
|
|
|
void documentChangedOnDisk(QmlJS::Document::Ptr doc);
|
|
|
|
|
void aboutToRemoveFiles(const QStringList &files);
|
2010-10-15 10:09:40 +02:00
|
|
|
void libraryInfoUpdated(const QString &path, const QmlJS::LibraryInfo &info);
|
2011-04-21 11:09:29 +02:00
|
|
|
void projectInfoUpdated(const ProjectInfo &pinfo);
|
2014-01-23 14:28:31 +01:00
|
|
|
void projectPathChanged(const QString &projectPath);
|
|
|
|
|
protected slots:
|
|
|
|
|
void maybeQueueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc);
|
|
|
|
|
void queueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc, bool scan);
|
|
|
|
|
void asyncReset();
|
|
|
|
|
virtual void startCppQmlTypeUpdate();
|
2014-01-22 18:38:45 +01:00
|
|
|
protected:
|
2014-06-30 11:56:28 +02:00
|
|
|
QMutex *mutex() const;
|
2014-07-22 19:06:44 +02:00
|
|
|
virtual QHash<QString,Dialect> languageForSuffix() const;
|
2014-01-23 14:28:31 +01:00
|
|
|
virtual void writeMessageInternal(const QString &msg) const;
|
|
|
|
|
virtual WorkingCopy workingCopyInternal() const;
|
|
|
|
|
virtual void addTaskInternal(QFuture<void> result, const QString &msg, const char *taskId) const;
|
|
|
|
|
|
|
|
|
|
QFuture<void> refreshSourceFiles(const QStringList &sourceFiles,
|
|
|
|
|
bool emitDocumentOnDiskChanged);
|
|
|
|
|
|
|
|
|
|
static void parseLoop(QSet<QString> &scannedPaths, QSet<QString> &newLibraries,
|
|
|
|
|
WorkingCopy workingCopyInternal, QStringList files, ModelManagerInterface *modelManager,
|
2014-07-22 19:06:44 +02:00
|
|
|
QmlJS::Dialect mainLanguage, bool emitDocChangedOnDisk,
|
2014-06-27 22:11:09 +02:00
|
|
|
std::function<bool (qreal)> reportProgress);
|
2014-01-23 14:28:31 +01:00
|
|
|
static void parse(QFutureInterface<void> &future,
|
|
|
|
|
WorkingCopy workingCopyInternal,
|
|
|
|
|
QStringList files,
|
|
|
|
|
ModelManagerInterface *modelManager,
|
2014-07-22 19:06:44 +02:00
|
|
|
QmlJS::Dialect mainLanguage,
|
2014-01-23 14:28:31 +01:00
|
|
|
bool emitDocChangedOnDisk);
|
|
|
|
|
static void updateCppQmlTypes(QFutureInterface<void> &interface,
|
|
|
|
|
ModelManagerInterface *qmlModelManager,
|
|
|
|
|
CPlusPlus::Snapshot snapshot,
|
|
|
|
|
QHash<QString, QPair<CPlusPlus::Document::Ptr, bool> > documents);
|
|
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
void maybeScan(const PathsAndLanguages &importPaths);
|
2014-01-23 14:28:31 +01:00
|
|
|
void updateImportPaths();
|
|
|
|
|
void loadQmlTypeDescriptionsInternal(const QString &path);
|
2014-06-30 11:56:28 +02:00
|
|
|
void setDefaultProject(const ProjectInfo &pInfo, ProjectExplorer::Project *p);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
2014-02-13 11:11:40 +01:00
|
|
|
private:
|
2014-01-23 14:28:31 +01:00
|
|
|
mutable QMutex m_mutex;
|
2014-02-13 11:11:40 +01:00
|
|
|
QmlJS::Snapshot m_validSnapshot;
|
|
|
|
|
QmlJS::Snapshot m_newestSnapshot;
|
2014-07-22 19:06:44 +02:00
|
|
|
PathsAndLanguages m_allImportPaths;
|
2014-01-23 14:28:31 +01:00
|
|
|
QStringList m_defaultImportPaths;
|
|
|
|
|
QmlJS::QmlLanguageBundles m_activeBundles;
|
|
|
|
|
QmlJS::QmlLanguageBundles m_extendedBundles;
|
2014-07-22 19:06:44 +02:00
|
|
|
QHash<Dialect, QmlJS::ViewerContext> m_defaultVContexts;
|
2014-01-23 14:28:31 +01:00
|
|
|
bool m_shouldScanImports;
|
|
|
|
|
QSet<QString> m_scannedPaths;
|
|
|
|
|
|
|
|
|
|
QTimer *m_updateCppQmlTypesTimer;
|
|
|
|
|
QTimer *m_asyncResetTimer;
|
|
|
|
|
QHash<QString, QPair<CPlusPlus::Document::Ptr, bool> > m_queuedCppDocuments;
|
|
|
|
|
QFuture<void> m_cppQmlTypesUpdater;
|
|
|
|
|
QrcCache m_qrcCache;
|
|
|
|
|
|
|
|
|
|
CppDataHash m_cppDataHash;
|
|
|
|
|
mutable QMutex m_cppDataMutex;
|
|
|
|
|
|
|
|
|
|
// project integration
|
|
|
|
|
QMap<ProjectExplorer::Project *, ProjectInfo> m_projects;
|
2014-06-30 11:56:28 +02:00
|
|
|
ProjectInfo m_defaultProjectInfo;
|
|
|
|
|
ProjectExplorer::Project *m_defaultProject;
|
2014-01-23 14:28:31 +01:00
|
|
|
QMultiHash<QString, ProjectExplorer::Project *> m_fileToProject;
|
|
|
|
|
|
|
|
|
|
PluginDumper *m_pluginDumper;
|
|
|
|
|
|
|
|
|
|
QFutureSynchronizer<void> m_synchronizer;
|
2014-09-08 17:59:25 +02:00
|
|
|
bool m_indexerEnabled;
|
2009-09-04 16:51:11 +02:00
|
|
|
};
|
|
|
|
|
|
2010-06-09 15:56:03 +02:00
|
|
|
} // namespace QmlJS
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2010-02-15 13:49:00 +01:00
|
|
|
#endif // QMLJSMODELMANAGERINTERFACE_H
|