2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-09-04 16:51:11 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://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
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2009-09-04 16:51:11 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
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"
|
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>
|
2019-02-07 17:22:39 +01:00
|
|
|
#include <utils/qrcparser.h>
|
2010-10-26 15:39:37 +02:00
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
#include <QFuture>
|
|
|
|
|
#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
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
class QMLJS_EXPORT ModelManagerInterface : public QObject
|
2009-09-04 16:51:11 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2019-10-23 14:03:13 +02:00
|
|
|
Q_DISABLE_COPY(ModelManagerInterface)
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2010-06-22 12:54:19 +02:00
|
|
|
public:
|
2019-10-23 14:03:13 +02:00
|
|
|
ModelManagerInterface(ModelManagerInterface &&) = delete;
|
|
|
|
|
ModelManagerInterface &operator=(ModelManagerInterface &&) = delete;
|
|
|
|
|
|
2013-05-21 11:35:15 +02:00
|
|
|
enum QrcResourceSelector {
|
|
|
|
|
ActiveQrcResources,
|
|
|
|
|
AllQrcResources
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
struct ProjectInfo
|
2010-06-22 12:54:19 +02:00
|
|
|
{
|
|
|
|
|
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;
|
2016-10-24 19:30:24 +02:00
|
|
|
QHash<QString, QString> resourceFileContents;
|
2011-09-21 15:54:07 +02:00
|
|
|
|
|
|
|
|
// whether trying to run qmldump makes sense
|
2019-10-23 14:03:13 +02:00
|
|
|
bool tryQmlDump = false;
|
|
|
|
|
bool qmlDumpHasRelocatableFlag = true;
|
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
|
|
|
|
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:
|
2019-10-23 14:03:13 +02:00
|
|
|
using Table = QHash<QString, QPair<QString, int>>;
|
2010-09-24 14:05:34 +02:00
|
|
|
|
|
|
|
|
void insert(const QString &fileName, const QString &source, int revision = 0)
|
2019-10-23 14:03:13 +02:00
|
|
|
{ m_elements.insert(fileName, {source, revision}); }
|
2010-09-24 14:05:34 +02:00
|
|
|
|
|
|
|
|
bool contains(const QString &fileName) const
|
2019-10-23 14:03:13 +02:00
|
|
|
{ return m_elements.contains(fileName); }
|
2010-09-24 14:05:34 +02:00
|
|
|
|
|
|
|
|
QString source(const QString &fileName) const
|
2019-10-23 14:03:13 +02:00
|
|
|
{ return m_elements.value(fileName).first; }
|
2010-09-24 14:05:34 +02:00
|
|
|
|
|
|
|
|
QPair<QString, int> get(const QString &fileName) const
|
2019-10-23 14:03:13 +02:00
|
|
|
{ return m_elements.value(fileName); }
|
2010-09-24 14:05:34 +02:00
|
|
|
|
|
|
|
|
Table all() const
|
2019-10-23 14:03:13 +02:00
|
|
|
{ return m_elements; }
|
2010-09-24 14:05:34 +02:00
|
|
|
|
|
|
|
|
private:
|
2019-10-23 14:03:13 +02:00
|
|
|
Table m_elements;
|
2010-09-24 14:05:34 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
struct CppData
|
2011-08-25 12:35:55 +02:00
|
|
|
{
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
using CppDataHash = QHash<QString, CppData>;
|
2011-01-06 10:01:45 +01:00
|
|
|
|
2009-09-04 16:51:11 +02:00
|
|
|
public:
|
2019-01-16 14:28:59 +01:00
|
|
|
ModelManagerInterface(QObject *parent = nullptr);
|
2015-06-04 15:12:21 +02:00
|
|
|
~ModelManagerInterface() override;
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
static Dialect guessLanguageOfFile(const QString &fileName);
|
2019-10-23 14:03:13 +02:00
|
|
|
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);
|
2019-01-16 14:28:59 +01:00
|
|
|
QStringList qrcPathsForFile(const QString &file, const QLocale *locale = nullptr,
|
|
|
|
|
ProjectExplorer::Project *project = nullptr,
|
2016-03-18 17:43:33 +01:00
|
|
|
QrcResourceSelector resources = AllQrcResources);
|
2019-01-16 14:28:59 +01:00
|
|
|
QStringList filesAtQrcPath(const QString &path, const QLocale *locale = nullptr,
|
|
|
|
|
ProjectExplorer::Project *project = nullptr,
|
2014-01-23 14:28:31 +01:00
|
|
|
QrcResourceSelector resources = AllQrcResources);
|
2019-10-23 14:03:13 +02:00
|
|
|
QMap<QString, QStringList> filesInQrcPath(const QString &path,
|
|
|
|
|
const QLocale *locale = nullptr,
|
|
|
|
|
ProjectExplorer::Project *project = nullptr,
|
|
|
|
|
bool addDirs = false,
|
|
|
|
|
QrcResourceSelector resources = AllQrcResources);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
|
QList<ProjectInfo> projectInfos() const;
|
2019-10-23 14:03:13 +02:00
|
|
|
bool containsProject(ProjectExplorer::Project *project) const;
|
|
|
|
|
ProjectInfo projectInfo(ProjectExplorer::Project *project) const;
|
2014-01-23 14:28:31 +01:00
|
|
|
void updateProjectInfo(const ProjectInfo &pinfo, ProjectExplorer::Project *p);
|
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
void updateDocument(const QmlJS::Document::Ptr& doc);
|
2014-01-23 14:28:31 +01:00
|
|
|
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
|
|
|
|
2017-09-28 16:24:13 +02:00
|
|
|
QStringList importPathsNames() 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,
|
2019-01-16 14:28:59 +01:00
|
|
|
const Document::Ptr &doc = Document::Ptr(nullptr)) const;
|
2014-07-22 19:06:44 +02:00
|
|
|
ViewerContext defaultVContext(Dialect language = Dialect::Qml,
|
2019-01-16 14:28:59 +01:00
|
|
|
const Document::Ptr &doc = Document::Ptr(nullptr),
|
2014-04-11 23:07:52 +02:00
|
|
|
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);
|
2019-10-23 14:03:13 +02:00
|
|
|
static void importScan(QFutureInterface<void> &future, const WorkingCopy& workingCopyInternal,
|
|
|
|
|
const PathsAndLanguages& paths, ModelManagerInterface *modelManager,
|
|
|
|
|
bool emitDocChangedOnDisk, bool libOnly = true,
|
|
|
|
|
bool forceRescan = false);
|
2016-06-27 22:25:11 +03:00
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
virtual void resetCodeModel();
|
|
|
|
|
void removeProjectInfo(ProjectExplorer::Project *project);
|
2016-06-27 22:25:11 +03:00
|
|
|
void maybeQueueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc);
|
|
|
|
|
|
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);
|
2016-06-27 22:25:11 +03:00
|
|
|
|
2014-01-22 18:38:45 +01:00
|
|
|
protected:
|
2016-06-27 22:25:11 +03:00
|
|
|
Q_INVOKABLE void queueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc, bool scan);
|
|
|
|
|
Q_INVOKABLE void asyncReset();
|
|
|
|
|
virtual void startCppQmlTypeUpdate();
|
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;
|
2019-10-23 14:03:13 +02:00
|
|
|
virtual void addTaskInternal(const QFuture<void> &result, const QString &msg,
|
|
|
|
|
const char *taskId) const;
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
|
QFuture<void> refreshSourceFiles(const QStringList &sourceFiles,
|
|
|
|
|
bool emitDocumentOnDiskChanged);
|
|
|
|
|
|
|
|
|
|
static void parseLoop(QSet<QString> &scannedPaths, QSet<QString> &newLibraries,
|
2019-10-23 14:03:13 +02:00
|
|
|
const WorkingCopy &workingCopyInternal, QStringList files,
|
|
|
|
|
ModelManagerInterface *modelManager,
|
2014-07-22 19:06:44 +02:00
|
|
|
QmlJS::Dialect mainLanguage, bool emitDocChangedOnDisk,
|
2019-10-23 14:03:13 +02:00
|
|
|
const std::function<bool(qreal)> &reportProgress);
|
2014-01-23 14:28:31 +01:00
|
|
|
static void parse(QFutureInterface<void> &future,
|
2019-10-23 14:03:13 +02:00
|
|
|
const WorkingCopy &workingCopyInternal,
|
2014-01-23 14:28:31 +01:00
|
|
|
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);
|
2019-10-23 14:03:13 +02:00
|
|
|
static void updateCppQmlTypes(
|
|
|
|
|
QFutureInterface<void> &futureInterface, ModelManagerInterface *qmlModelManager,
|
|
|
|
|
const CPlusPlus::Snapshot &snapshot,
|
|
|
|
|
const QHash<QString, QPair<CPlusPlus::Document::Ptr, bool>> &documents);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
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:
|
2016-01-22 11:04:52 +01:00
|
|
|
void cleanupFutures();
|
2016-03-18 17:43:33 +01:00
|
|
|
void iterateQrcFiles(ProjectExplorer::Project *project,
|
|
|
|
|
QrcResourceSelector resources,
|
2019-10-23 14:03:13 +02:00
|
|
|
const std::function<void(Utils::QrcParser::ConstPtr)> &callback);
|
2016-01-22 11:04:52 +01:00
|
|
|
|
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;
|
2019-01-18 20:28:55 +01:00
|
|
|
bool m_shouldScanImports = false;
|
2014-01-23 14:28:31 +01:00
|
|
|
QSet<QString> m_scannedPaths;
|
|
|
|
|
|
2019-01-18 20:28:55 +01:00
|
|
|
QTimer *m_updateCppQmlTypesTimer = nullptr;
|
|
|
|
|
QTimer *m_asyncResetTimer = nullptr;
|
2019-10-23 14:03:13 +02:00
|
|
|
QHash<QString, QPair<CPlusPlus::Document::Ptr, bool>> m_queuedCppDocuments;
|
2014-01-23 14:28:31 +01:00
|
|
|
QFuture<void> m_cppQmlTypesUpdater;
|
2019-02-07 17:22:39 +01:00
|
|
|
Utils::QrcCache m_qrcCache;
|
2016-10-24 19:30:24 +02:00
|
|
|
QHash<QString, QString> m_qrcContents;
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
|
CppDataHash m_cppDataHash;
|
2019-10-23 14:03:13 +02:00
|
|
|
QHash<QString, QList<CPlusPlus::Document::Ptr>> m_cppDeclarationFiles;
|
2014-01-23 14:28:31 +01:00
|
|
|
mutable QMutex m_cppDataMutex;
|
|
|
|
|
|
|
|
|
|
// project integration
|
|
|
|
|
QMap<ProjectExplorer::Project *, ProjectInfo> m_projects;
|
2014-06-30 11:56:28 +02:00
|
|
|
ProjectInfo m_defaultProjectInfo;
|
2019-01-18 20:28:55 +01:00
|
|
|
ProjectExplorer::Project *m_defaultProject = nullptr;
|
2014-01-23 14:28:31 +01:00
|
|
|
QMultiHash<QString, ProjectExplorer::Project *> m_fileToProject;
|
|
|
|
|
|
2019-01-18 20:28:55 +01:00
|
|
|
PluginDumper *m_pluginDumper = nullptr;
|
2014-01-23 14:28:31 +01:00
|
|
|
|
2016-01-22 11:04:52 +01:00
|
|
|
QList<QFuture<void>> m_futures;
|
2019-01-18 20:28:55 +01:00
|
|
|
bool m_indexerDisabled = false;
|
2009-09-04 16:51:11 +02:00
|
|
|
};
|
|
|
|
|
|
2010-06-09 15:56:03 +02:00
|
|
|
} // namespace QmlJS
|