forked from qt-creator/qt-creator
qmljs: improve handling of qml dialects
Language::Enum -> QmlDialect * class instead of enum * moved Language specific operations to it (from Document) * nicer handling QStringList -> PathsAndLanguages * store language along with path, to perform a correct scan and improve path handling Change-Id: If69d35c63cfeb48aa670b51870916cd0c40f1916 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
@@ -44,7 +44,8 @@ HEADERS += \
|
||||
$$PWD/qmljsconstants.h \
|
||||
$$PWD/qmljsimportdependencies.h \
|
||||
$$PWD/qmljsviewercontext.h \
|
||||
$$PWD/qmljsdescribevalue.h
|
||||
$$PWD/qmljsdescribevalue.h \
|
||||
$$PWD/qmljsdialect.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/qmljsbind.cpp \
|
||||
@@ -80,7 +81,8 @@ SOURCES += \
|
||||
$$PWD/qmljsqrcparser.cpp \
|
||||
$$PWD/qmljsimportdependencies.cpp \
|
||||
$$PWD/qmljsviewercontext.cpp \
|
||||
$$PWD/qmljsdescribevalue.cpp
|
||||
$$PWD/qmljsdescribevalue.cpp \
|
||||
$$PWD/qmljsdialect.cpp
|
||||
|
||||
|
||||
RESOURCES += \
|
||||
|
||||
@@ -41,6 +41,7 @@ QtcLibrary {
|
||||
"qmljsimportdependencies.cpp", "qmljsimportdependencies.h",
|
||||
"qmljsindenter.cpp", "qmljsindenter.h",
|
||||
"qmljsinterpreter.cpp", "qmljsinterpreter.h",
|
||||
"qmljsdialect.cpp", "qmljsdialect.h",
|
||||
"qmljslineinfo.cpp", "qmljslineinfo.h",
|
||||
"qmljslink.cpp", "qmljslink.h",
|
||||
"qmljsmodelmanagerinterface.cpp", "qmljsmodelmanagerinterface.h",
|
||||
|
||||
@@ -202,18 +202,18 @@ bool Bind::visit(UiImport *ast)
|
||||
const QString importId = ast->importId.toString();
|
||||
ImportInfo import = ImportInfo::moduleImport(toString(ast->importUri), version,
|
||||
importId, ast);
|
||||
if (_doc->language() == Language::Qml) {
|
||||
if (_doc->language() == Dialect::Qml) {
|
||||
const QString importStr = import.name() + importId;
|
||||
if (ModelManagerInterface::instance()) {
|
||||
QmlLanguageBundles langBundles = ModelManagerInterface::instance()->extendedBundles();
|
||||
QmlBundle qq1 = langBundles.bundleForLanguage(Language::QmlQtQuick1);
|
||||
QmlBundle qq2 = langBundles.bundleForLanguage(Language::QmlQtQuick2);
|
||||
QmlBundle qq1 = langBundles.bundleForLanguage(Dialect::QmlQtQuick1);
|
||||
QmlBundle qq2 = langBundles.bundleForLanguage(Dialect::QmlQtQuick2);
|
||||
bool isQQ1 = qq1.supportedImports().contains(importStr);
|
||||
bool isQQ2 = qq2.supportedImports().contains(importStr);
|
||||
if (isQQ1 && ! isQQ2)
|
||||
_doc->setLanguage(Language::QmlQtQuick1);
|
||||
_doc->setLanguage(Dialect::QmlQtQuick1);
|
||||
if (isQQ2 && ! isQQ1)
|
||||
_doc->setLanguage(Language::QmlQtQuick2);
|
||||
_doc->setLanguage(Dialect::QmlQtQuick2);
|
||||
}
|
||||
}
|
||||
_imports += import;
|
||||
|
||||
@@ -288,14 +288,14 @@ bool QmlBundle::readFrom(QString path, QStringList *errors)
|
||||
return errs.isEmpty();
|
||||
}
|
||||
|
||||
QmlBundle QmlLanguageBundles::bundleForLanguage(Language::Enum l) const
|
||||
QmlBundle QmlLanguageBundles::bundleForLanguage(Dialect l) const
|
||||
{
|
||||
if (m_bundles.contains(l))
|
||||
return m_bundles.value(l);
|
||||
return QmlBundle();
|
||||
}
|
||||
|
||||
void QmlLanguageBundles::mergeBundleForLanguage(Language::Enum l, const QmlBundle &bundle)
|
||||
void QmlLanguageBundles::mergeBundleForLanguage(Dialect l, const QmlBundle &bundle)
|
||||
{
|
||||
if (bundle.isEmpty())
|
||||
return;
|
||||
@@ -305,14 +305,14 @@ void QmlLanguageBundles::mergeBundleForLanguage(Language::Enum l, const QmlBundl
|
||||
m_bundles.insert(l,bundle);
|
||||
}
|
||||
|
||||
QList<Language::Enum> QmlLanguageBundles::languages() const
|
||||
QList<Dialect> QmlLanguageBundles::languages() const
|
||||
{
|
||||
return m_bundles.keys();
|
||||
}
|
||||
|
||||
void QmlLanguageBundles::mergeLanguageBundles(const QmlLanguageBundles &o)
|
||||
{
|
||||
foreach (Language::Enum l, o.languages())
|
||||
foreach (Dialect l, o.languages())
|
||||
mergeBundleForLanguage(l, o.bundleForLanguage(l));
|
||||
}
|
||||
|
||||
|
||||
@@ -100,12 +100,12 @@ private:
|
||||
class QMLJS_EXPORT QmlLanguageBundles
|
||||
{
|
||||
public:
|
||||
QmlBundle bundleForLanguage(Language::Enum l) const;
|
||||
void mergeBundleForLanguage(Language::Enum l, const QmlBundle &bundle);
|
||||
QList<Language::Enum> languages() const;
|
||||
QmlBundle bundleForLanguage(Dialect l) const;
|
||||
void mergeBundleForLanguage(Dialect l, const QmlBundle &bundle);
|
||||
QList<Dialect> languages() const;
|
||||
void mergeLanguageBundles(const QmlLanguageBundles &);
|
||||
private:
|
||||
QHash<Language::Enum,QmlBundle> m_bundles;
|
||||
QHash<Dialect,QmlBundle> m_bundles;
|
||||
};
|
||||
} // namespace QmlJS
|
||||
|
||||
|
||||
330
src/libs/qmljs/qmljsdialect.cpp
Normal file
330
src/libs/qmljs/qmljsdialect.cpp
Normal file
@@ -0,0 +1,330 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** 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
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qmljsdialect.h"
|
||||
|
||||
namespace QmlJS {
|
||||
|
||||
|
||||
bool Dialect::isQmlLikeLanguage() const
|
||||
{
|
||||
switch (m_dialect) {
|
||||
case Dialect::Qml:
|
||||
case Dialect::QmlQtQuick1:
|
||||
case Dialect::QmlQtQuick2:
|
||||
case Dialect::QmlQbs:
|
||||
case Dialect::QmlProject:
|
||||
case Dialect::QmlTypeInfo:
|
||||
case Dialect::AnyLanguage:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Dialect::isFullySupportedLanguage() const
|
||||
{
|
||||
switch (m_dialect) {
|
||||
case Dialect::JavaScript:
|
||||
case Dialect::Json:
|
||||
case Dialect::Qml:
|
||||
case Dialect::QmlQtQuick1:
|
||||
case Dialect::QmlQtQuick2:
|
||||
return true;
|
||||
case Dialect::NoLanguage:
|
||||
case Dialect::AnyLanguage:
|
||||
case Dialect::QmlQbs:
|
||||
case Dialect::QmlProject:
|
||||
case Dialect::QmlTypeInfo:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Dialect::isQmlLikeOrJsLanguage() const
|
||||
{
|
||||
switch (m_dialect) {
|
||||
case Dialect::Qml:
|
||||
case Dialect::QmlQtQuick1:
|
||||
case Dialect::QmlQtQuick2:
|
||||
case Dialect::QmlQbs:
|
||||
case Dialect::QmlProject:
|
||||
case Dialect::QmlTypeInfo:
|
||||
case Dialect::JavaScript:
|
||||
case Dialect::AnyLanguage:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QString Dialect::toString() const
|
||||
{
|
||||
switch (m_dialect) {
|
||||
case Dialect::JavaScript:
|
||||
return QLatin1String("JavaScript");
|
||||
case Dialect::Json:
|
||||
return QLatin1String("Json");
|
||||
case Dialect::Qml:
|
||||
return QLatin1String("Qml");
|
||||
case Dialect::QmlQtQuick1:
|
||||
return QLatin1String("QmlQtQuick1");
|
||||
case Dialect::QmlQtQuick2:
|
||||
return QLatin1String("QmlQtQuick2");
|
||||
case Dialect::NoLanguage:
|
||||
return QLatin1String("NoLanguage");
|
||||
case Dialect::AnyLanguage:
|
||||
return QLatin1String("AnyLanguage");
|
||||
case Dialect::QmlQbs:
|
||||
return QLatin1String("QmlQbs");
|
||||
case Dialect::QmlProject:
|
||||
return QLatin1String("QmlProject");
|
||||
case Dialect::QmlTypeInfo:
|
||||
break;
|
||||
}
|
||||
return QLatin1String("QmlTypeInfo");
|
||||
}
|
||||
|
||||
bool Dialect::operator ==(const Dialect &o) const {
|
||||
return m_dialect == o.m_dialect;
|
||||
}
|
||||
|
||||
bool Dialect::operator <(const Dialect &o) const {
|
||||
return m_dialect < o.m_dialect;
|
||||
}
|
||||
|
||||
Dialect Dialect::mergeLanguages(const Dialect &l1, const Dialect &l2)
|
||||
{
|
||||
if (l1 == Dialect::NoLanguage)
|
||||
return l2;
|
||||
if (l2 == Dialect::NoLanguage)
|
||||
return l1;
|
||||
QList<Dialect> ll1 = l1.companionLanguages();
|
||||
QList<Dialect> ll2 = l2.companionLanguages();
|
||||
bool i1 = ll1.contains(l2);
|
||||
bool i2 = ll2.contains(l1);
|
||||
if (i1 && i2) {
|
||||
if (ll1.size() > ll2.size())
|
||||
return l1;
|
||||
if (ll2.size() > ll1.size())
|
||||
return l2;
|
||||
if (l1 < l2)
|
||||
return l1;
|
||||
return l2;
|
||||
}
|
||||
if (i1 && !i2)
|
||||
return l1;
|
||||
if (i2 && !i1)
|
||||
return l2;
|
||||
QList<Dialect> qmlLangs = Dialect(Qml).companionLanguages();
|
||||
if (qmlLangs.contains(l1) && qmlLangs.contains(l2))
|
||||
return Dialect::Qml;
|
||||
return Dialect::AnyLanguage;
|
||||
}
|
||||
|
||||
void Dialect::mergeLanguage(const Dialect &l2) {
|
||||
*this = mergeLanguages(*this, l2);
|
||||
}
|
||||
|
||||
bool Dialect::restrictLanguage(const Dialect &l2)
|
||||
{
|
||||
if (*this == l2)
|
||||
return true;
|
||||
QList<Dialect> ll1 = companionLanguages();
|
||||
QList<Dialect> ll2 = l2.companionLanguages();
|
||||
bool i1 = ll1.contains(l2);
|
||||
bool i2 = ll2.contains(*this);
|
||||
if (i1 && i2) {
|
||||
if (ll1.size() < ll2.size())
|
||||
return true;
|
||||
if (ll2.size() < ll1.size()) {
|
||||
*this = l2;
|
||||
return true;
|
||||
}
|
||||
if (m_dialect < l2.m_dialect)
|
||||
return true;
|
||||
*this = l2;
|
||||
return true;
|
||||
}
|
||||
if (i1 && !i2) {
|
||||
*this = l2;
|
||||
return true;
|
||||
}
|
||||
if (i2 && !i1)
|
||||
return true;
|
||||
QList<Dialect> qmlLangs = Dialect(Qml).companionLanguages();
|
||||
if (qmlLangs.contains(*this) && qmlLangs.contains(l2))
|
||||
*this = Dialect::Qml;
|
||||
*this = Dialect::AnyLanguage;
|
||||
return false;
|
||||
}
|
||||
|
||||
QList<Dialect> Dialect::companionLanguages() const
|
||||
{
|
||||
QList<Dialect> langs;
|
||||
langs << *this;
|
||||
switch (m_dialect) {
|
||||
case Dialect::JavaScript:
|
||||
case Dialect::Json:
|
||||
case Dialect::QmlProject:
|
||||
case Dialect::QmlTypeInfo:
|
||||
break;
|
||||
case Dialect::QmlQbs:
|
||||
langs << Dialect::JavaScript;
|
||||
break;
|
||||
case Dialect::Qml:
|
||||
langs << Dialect::QmlQtQuick1 << Dialect::QmlQtQuick2 << Dialect::JavaScript;
|
||||
break;
|
||||
case Dialect::QmlQtQuick1:
|
||||
case Dialect::QmlQtQuick2:
|
||||
langs << Dialect::Qml << Dialect::JavaScript;
|
||||
break;
|
||||
case Dialect::AnyLanguage:
|
||||
langs << Dialect::JavaScript << Dialect::Json << Dialect::QmlProject << Dialect:: QmlQbs
|
||||
<< Dialect::QmlTypeInfo << Dialect::QmlQtQuick1 << Dialect::QmlQtQuick2
|
||||
<< Dialect::Qml;
|
||||
break;
|
||||
case Dialect::NoLanguage:
|
||||
return QList<Dialect>(); // return at least itself?
|
||||
}
|
||||
if (*this != Dialect::AnyLanguage)
|
||||
langs << Dialect::AnyLanguage;
|
||||
return langs;
|
||||
}
|
||||
|
||||
uint qHash(const Dialect &o)
|
||||
{
|
||||
return uint(o.dialect());
|
||||
}
|
||||
|
||||
QDebug operator << (QDebug &dbg, const Dialect &dialect)
|
||||
{
|
||||
dbg << dialect.toString();
|
||||
return dbg;
|
||||
}
|
||||
|
||||
PathAndLanguage::PathAndLanguage(const Utils::FileName &path, Dialect language)
|
||||
: m_path(path), m_language(language)
|
||||
{ }
|
||||
|
||||
bool PathAndLanguage::operator ==(const PathAndLanguage &other) const
|
||||
{
|
||||
return path() == other.path() && language() == other.language();
|
||||
}
|
||||
|
||||
bool PathAndLanguage::operator <(const PathAndLanguage &other) const
|
||||
{
|
||||
if (path() < other.path())
|
||||
return true;
|
||||
if (path() > other.path())
|
||||
return false;
|
||||
if (language() == other.language())
|
||||
return false;
|
||||
bool i1 = other.language().companionLanguages().contains(language());
|
||||
bool i2 = language().companionLanguages().contains(other.language());
|
||||
if (i1 && !i2)
|
||||
return true;
|
||||
if (i2 && !i1)
|
||||
return false;
|
||||
return language() < other.language();
|
||||
}
|
||||
|
||||
QDebug operator << (QDebug &dbg, const PathAndLanguage &pathAndLanguage)
|
||||
{
|
||||
dbg << "{ path:" << pathAndLanguage.path() << " language:" << pathAndLanguage.language().toString() << "}";
|
||||
return dbg;
|
||||
}
|
||||
|
||||
bool PathsAndLanguages::maybeInsert(const PathAndLanguage &pathAndLanguage) {
|
||||
for (int i = 0; i < m_list.size(); ++i) {
|
||||
PathAndLanguage currentElement = m_list.at(i);
|
||||
if (currentElement.path() == pathAndLanguage.path()) {
|
||||
int j = i;
|
||||
do {
|
||||
if (pathAndLanguage.language() < currentElement.language()) {
|
||||
if (currentElement.language() == pathAndLanguage.language())
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
++j;
|
||||
if (j == m_list.length())
|
||||
break;
|
||||
currentElement = m_list.at(j);
|
||||
} while (currentElement.path() == pathAndLanguage.path());
|
||||
m_list.insert(j, pathAndLanguage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
m_list.append(pathAndLanguage);
|
||||
return true;
|
||||
}
|
||||
|
||||
void PathsAndLanguages::compact() {
|
||||
int oldCompactionPlace = 0;
|
||||
Utils::FileName oldPath = m_list.first().path();
|
||||
QList<PathAndLanguage> compactedList;
|
||||
bool restrictFailed = false;
|
||||
for (int i = 1; i < m_list.length(); ++i) {
|
||||
Utils::FileName newPath = m_list.at(i).path();
|
||||
if (newPath == oldPath) {
|
||||
int newCompactionPlace = i - 1;
|
||||
compactedList << m_list.mid(oldCompactionPlace, newCompactionPlace - oldCompactionPlace);
|
||||
LanguageMerger merger;
|
||||
merger.merge(m_list.at(i - 1).language());
|
||||
do {
|
||||
merger.merge(m_list.at(i++).language());
|
||||
if (++i == m_list.length())
|
||||
break;
|
||||
newPath = m_list.at(i).path();
|
||||
} while (newPath == oldPath);
|
||||
oldCompactionPlace = i;
|
||||
compactedList << PathAndLanguage(oldPath, merger.mergedLanguage());
|
||||
if (merger.restrictFailed())
|
||||
restrictFailed = true;
|
||||
}
|
||||
oldPath = newPath;
|
||||
}
|
||||
if (oldCompactionPlace == 0)
|
||||
return;
|
||||
if (restrictFailed)
|
||||
qCWarning(qmljsLog) << "failed to restrict PathAndLanguages " << m_list;
|
||||
m_list = compactedList;
|
||||
}
|
||||
|
||||
void LanguageMerger::merge(Dialect l)
|
||||
{
|
||||
bool restrictSuccedeed = m_specificLanguage.restrictLanguage(l);
|
||||
m_specificLanguage.mergeLanguage(m_minimalSpecificLanguage);
|
||||
if (!restrictSuccedeed) {
|
||||
m_minimalSpecificLanguage = m_specificLanguage;
|
||||
m_restrictFailed = true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace QmlJS
|
||||
174
src/libs/qmljs/qmljsdialect.h
Normal file
174
src/libs/qmljs/qmljsdialect.h
Normal file
@@ -0,0 +1,174 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** 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
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QMLJSDIALECT_H
|
||||
#define QMLJSDIALECT_H
|
||||
|
||||
#include "qmljsconstants.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace QmlJS {
|
||||
|
||||
class QMLJS_EXPORT Dialect {
|
||||
public:
|
||||
enum Enum
|
||||
{
|
||||
NoLanguage = 0,
|
||||
JavaScript = 1,
|
||||
Json = 2,
|
||||
Qml = 3,
|
||||
QmlQtQuick1 = 4,
|
||||
QmlQtQuick2 = 5,
|
||||
QmlQbs = 6,
|
||||
QmlProject = 7,
|
||||
QmlTypeInfo = 8,
|
||||
AnyLanguage = 9,
|
||||
};
|
||||
Dialect(Enum dialect = NoLanguage)
|
||||
: m_dialect(dialect)
|
||||
{ }
|
||||
static Dialect mergeLanguages(const Dialect &l1, const Dialect &l2);
|
||||
|
||||
bool isQmlLikeLanguage() const;
|
||||
bool isFullySupportedLanguage() const;
|
||||
bool isQmlLikeOrJsLanguage() const;
|
||||
QList<Dialect> companionLanguages() const;
|
||||
bool restrictLanguage(const Dialect &l2);
|
||||
QString toString() const;
|
||||
bool operator ==(const Dialect &o) const;
|
||||
bool operator !=(const Dialect &o) const {
|
||||
return !(*this == o);
|
||||
}
|
||||
bool operator <(const Dialect &o) const;
|
||||
Enum dialect() const {
|
||||
return m_dialect;
|
||||
}
|
||||
void mergeLanguage(const Dialect &l2);
|
||||
private:
|
||||
Enum m_dialect;
|
||||
};
|
||||
|
||||
QMLJS_EXPORT uint qHash(const Dialect &o);
|
||||
|
||||
QMLJS_EXPORT QDebug operator << (QDebug &dbg, const Dialect &dialect);
|
||||
|
||||
class QMLJS_EXPORT PathAndLanguage {
|
||||
public:
|
||||
PathAndLanguage(const Utils::FileName &path = Utils::FileName(), Dialect language = Dialect::AnyLanguage);
|
||||
PathAndLanguage(const PathAndLanguage &o)
|
||||
: m_path(o.path()), m_language(o.language())
|
||||
{ }
|
||||
Utils::FileName path() const {
|
||||
return m_path;
|
||||
}
|
||||
Dialect language() const {
|
||||
return m_language;
|
||||
}
|
||||
bool operator ==(const PathAndLanguage &other) const;
|
||||
bool operator < (const PathAndLanguage &other) const;
|
||||
private:
|
||||
Utils::FileName m_path;
|
||||
Dialect m_language;
|
||||
};
|
||||
|
||||
// tries to find the "most specific" language still compatible with all requested ones
|
||||
class QMLJS_EXPORT LanguageMerger
|
||||
{
|
||||
public:
|
||||
LanguageMerger()
|
||||
: m_specificLanguage(Dialect::AnyLanguage),
|
||||
m_minimalSpecificLanguage(Dialect::NoLanguage),
|
||||
m_restrictFailed(false)
|
||||
{ }
|
||||
|
||||
void merge(Dialect l);
|
||||
|
||||
Dialect mergedLanguage() const {
|
||||
return m_specificLanguage;
|
||||
}
|
||||
bool restrictFailed() const {
|
||||
return m_restrictFailed;
|
||||
}
|
||||
private:
|
||||
Dialect m_specificLanguage;
|
||||
Dialect m_minimalSpecificLanguage;
|
||||
bool m_restrictFailed;
|
||||
};
|
||||
|
||||
|
||||
QMLJS_EXPORT QDebug operator << (QDebug &dbg, const PathAndLanguage &pathAndLanguage);
|
||||
|
||||
class QMLJS_EXPORT PathsAndLanguages
|
||||
{
|
||||
public:
|
||||
explicit PathsAndLanguages()
|
||||
{ }
|
||||
explicit PathsAndLanguages(const QList<PathAndLanguage> &list)
|
||||
: m_list(list)
|
||||
{ }
|
||||
PathsAndLanguages(const PathsAndLanguages &o)
|
||||
: m_list(o.m_list)
|
||||
{ }
|
||||
|
||||
bool maybeInsert(const Utils::FileName &path, Dialect language = Dialect::AnyLanguage) {
|
||||
return maybeInsert(PathAndLanguage(path, language));
|
||||
}
|
||||
|
||||
bool maybeInsert(const PathAndLanguage &pathAndLanguage);
|
||||
|
||||
PathAndLanguage at(int i) const {
|
||||
return m_list.at(i);
|
||||
}
|
||||
int size() const {
|
||||
return m_list.size();
|
||||
}
|
||||
int length() const {
|
||||
return m_list.length();
|
||||
}
|
||||
void clear() {
|
||||
m_list.clear();
|
||||
}
|
||||
// foreach support
|
||||
typedef QList<PathAndLanguage>::const_iterator const_iterator;
|
||||
const_iterator begin() const {
|
||||
return m_list.begin();
|
||||
}
|
||||
const_iterator end() const {
|
||||
return m_list.end();
|
||||
}
|
||||
void compact();
|
||||
private:
|
||||
QList<PathAndLanguage> m_list;
|
||||
};
|
||||
|
||||
} // namespace QmlJS
|
||||
#endif // QMLJSDIALECT_H
|
||||
@@ -88,93 +88,7 @@ using namespace QmlJS::AST;
|
||||
threads finish and new information becomes available.
|
||||
*/
|
||||
|
||||
|
||||
bool Document::isQmlLikeLanguage(Language::Enum language)
|
||||
{
|
||||
switch (language) {
|
||||
case Language::Qml:
|
||||
case Language::QmlQtQuick1:
|
||||
case Language::QmlQtQuick2:
|
||||
case Language::QmlQbs:
|
||||
case Language::QmlProject:
|
||||
case Language::QmlTypeInfo:
|
||||
case Language::AnyLanguage:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Document::isFullySupportedLanguage(Language::Enum language)
|
||||
{
|
||||
switch (language) {
|
||||
case Language::JavaScript:
|
||||
case Language::Json:
|
||||
case Language::Qml:
|
||||
case Language::QmlQtQuick1:
|
||||
case Language::QmlQtQuick2:
|
||||
return true;
|
||||
case Language::NoLanguage:
|
||||
case Language::AnyLanguage:
|
||||
case Language::QmlQbs:
|
||||
case Language::QmlProject:
|
||||
case Language::QmlTypeInfo:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Document::isQmlLikeOrJsLanguage(Language::Enum language)
|
||||
{
|
||||
switch (language) {
|
||||
case Language::Qml:
|
||||
case Language::QmlQtQuick1:
|
||||
case Language::QmlQtQuick2:
|
||||
case Language::QmlQbs:
|
||||
case Language::QmlProject:
|
||||
case Language::QmlTypeInfo:
|
||||
case Language::JavaScript:
|
||||
case Language::AnyLanguage:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QList<Language::Enum> Document::companionLanguages(Language::Enum language)
|
||||
{
|
||||
QList<Language::Enum> langs;
|
||||
langs << language;
|
||||
switch (language) {
|
||||
case Language::JavaScript:
|
||||
case Language::Json:
|
||||
case Language::QmlProject:
|
||||
case Language::QmlTypeInfo:
|
||||
break;
|
||||
case Language::QmlQbs:
|
||||
langs << Language::JavaScript;
|
||||
break;
|
||||
case Language::Qml:
|
||||
langs << Language::QmlQtQuick1 << Language::QmlQtQuick2 << Language::JavaScript;
|
||||
break;
|
||||
case Language::QmlQtQuick1:
|
||||
case Language::QmlQtQuick2:
|
||||
langs << Language::Qml << Language::JavaScript;
|
||||
break;
|
||||
case Language::AnyLanguage:
|
||||
langs << Language::JavaScript << Language::Json << Language::QmlProject << Language:: QmlQbs
|
||||
<< Language::QmlTypeInfo << Language::QmlQtQuick1 << Language::QmlQtQuick2
|
||||
<< Language::Qml;
|
||||
break;
|
||||
case Language::NoLanguage:
|
||||
return QList<Language::Enum>(); // return at least itself?
|
||||
}
|
||||
if (language != Language::AnyLanguage)
|
||||
langs << Language::AnyLanguage;
|
||||
return langs;
|
||||
}
|
||||
|
||||
Document::Document(const QString &fileName, Language::Enum language)
|
||||
Document::Document(const QString &fileName, Dialect language)
|
||||
: _engine(0)
|
||||
, _ast(0)
|
||||
, _bind(0)
|
||||
@@ -186,7 +100,7 @@ Document::Document(const QString &fileName, Language::Enum language)
|
||||
QFileInfo fileInfo(fileName);
|
||||
_path = QDir::cleanPath(fileInfo.absolutePath());
|
||||
|
||||
if (isQmlLikeLanguage(language)) {
|
||||
if (language.isQmlLikeLanguage()) {
|
||||
_componentName = fileInfo.baseName();
|
||||
|
||||
if (! _componentName.isEmpty()) {
|
||||
@@ -207,7 +121,7 @@ Document::~Document()
|
||||
delete _engine;
|
||||
}
|
||||
|
||||
Document::MutablePtr Document::create(const QString &fileName, Language::Enum language)
|
||||
Document::MutablePtr Document::create(const QString &fileName, Dialect language)
|
||||
{
|
||||
Document::MutablePtr doc(new Document(fileName, language));
|
||||
doc->_ptr = doc;
|
||||
@@ -221,15 +135,15 @@ Document::Ptr Document::ptr() const
|
||||
|
||||
bool Document::isQmlDocument() const
|
||||
{
|
||||
return isQmlLikeLanguage(_language);
|
||||
return _language.isQmlLikeLanguage();
|
||||
}
|
||||
|
||||
Language::Enum Document::language() const
|
||||
Dialect Document::language() const
|
||||
{
|
||||
return _language;
|
||||
}
|
||||
|
||||
void Document::setLanguage(Language::Enum l)
|
||||
void Document::setLanguage(Dialect l)
|
||||
{
|
||||
_language = l;
|
||||
}
|
||||
@@ -357,7 +271,7 @@ bool Document::parse_helper(int startToken)
|
||||
Parser parser(_engine);
|
||||
|
||||
QString source = _source;
|
||||
lexer.setCode(source, /*line = */ 1, /*qmlMode = */isQmlLikeLanguage(_language));
|
||||
lexer.setCode(source, /*line = */ 1, /*qmlMode = */_language.isQmlLikeLanguage());
|
||||
|
||||
CollectDirectives collectDirectives(path());
|
||||
_engine->setDirectives(&collectDirectives);
|
||||
@@ -539,7 +453,7 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
|
||||
if (!info.wasFound()) return;
|
||||
CoreImport cImport;
|
||||
cImport.importId = path;
|
||||
cImport.language = Language::AnyLanguage;
|
||||
cImport.language = Dialect::AnyLanguage;
|
||||
QSet<ImportKey> packages;
|
||||
foreach (const ModuleApiInfo &moduleInfo, info.moduleApis()) {
|
||||
ImportKey iKey(ImportType::Library, moduleInfo.uri, moduleInfo.version.majorVersion(),
|
||||
@@ -638,7 +552,7 @@ QmlJS::ImportDependencies *Snapshot::importDependencies()
|
||||
|
||||
Document::MutablePtr Snapshot::documentFromSource(
|
||||
const QString &code, const QString &fileName,
|
||||
Language::Enum language) const
|
||||
Dialect language) const
|
||||
{
|
||||
Document::MutablePtr newDoc = Document::create(fileName, language);
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <languageutils/fakemetaobject.h>
|
||||
|
||||
#include "qmljsdialect.h"
|
||||
#include "parser/qmldirparser_p.h"
|
||||
#include "parser/qmljsengine_p.h"
|
||||
#include "qmljs_global.h"
|
||||
@@ -52,24 +53,19 @@ class QMLJS_EXPORT Document
|
||||
public:
|
||||
typedef QSharedPointer<const Document> Ptr;
|
||||
typedef QSharedPointer<Document> MutablePtr;
|
||||
|
||||
static bool isQmlLikeLanguage(Language::Enum languge);
|
||||
static bool isFullySupportedLanguage(Language::Enum language);
|
||||
static bool isQmlLikeOrJsLanguage(Language::Enum language);
|
||||
static QList<Language::Enum> companionLanguages(Language::Enum language);
|
||||
protected:
|
||||
Document(const QString &fileName, Language::Enum language);
|
||||
Document(const QString &fileName, Dialect language);
|
||||
|
||||
public:
|
||||
~Document();
|
||||
|
||||
static MutablePtr create(const QString &fileName, Language::Enum language);
|
||||
static MutablePtr create(const QString &fileName, Dialect language);
|
||||
|
||||
Document::Ptr ptr() const;
|
||||
|
||||
bool isQmlDocument() const;
|
||||
Language::Enum language() const;
|
||||
void setLanguage(Language::Enum l);
|
||||
Dialect language() const;
|
||||
void setLanguage(Dialect l);
|
||||
|
||||
QString importId() const;
|
||||
QByteArray fingerprint() const;
|
||||
@@ -117,7 +113,7 @@ private:
|
||||
QWeakPointer<Document> _ptr;
|
||||
QByteArray _fingerprint;
|
||||
int _editorRevision;
|
||||
Language::Enum _language;
|
||||
Dialect _language;
|
||||
bool _parsedCorrectly;
|
||||
|
||||
// for documentFromSource
|
||||
@@ -246,7 +242,7 @@ public:
|
||||
|
||||
Document::MutablePtr documentFromSource(const QString &code,
|
||||
const QString &fileName,
|
||||
Language::Enum language) const;
|
||||
Dialect language) const;
|
||||
};
|
||||
|
||||
} // namespace QmlJS
|
||||
|
||||
@@ -509,10 +509,10 @@ bool operator !=(const Export &i1, const Export &i2)
|
||||
return !(i1 == i2);
|
||||
}
|
||||
|
||||
CoreImport::CoreImport() : language(Language::Qml) { }
|
||||
CoreImport::CoreImport() : language(Dialect::Qml) { }
|
||||
|
||||
CoreImport::CoreImport(const QString &importId, const QList<Export> &possibleExports,
|
||||
Language::Enum language, const QByteArray &fingerprint)
|
||||
Dialect language, const QByteArray &fingerprint)
|
||||
: importId(importId), possibleExports(possibleExports), language(language),
|
||||
fingerprint(fingerprint)
|
||||
{ }
|
||||
@@ -787,7 +787,7 @@ void ImportDependencies::addExport(const QString &importId, const ImportKey &imp
|
||||
{
|
||||
if (!m_coreImports.contains(importId)) {
|
||||
CoreImport newImport(importId);
|
||||
newImport.language = Language::AnyLanguage;
|
||||
newImport.language = Dialect::AnyLanguage;
|
||||
newImport.possibleExports.append(Export(importKey, requiredPath, false, typeName));
|
||||
m_coreImports.insert(newImport.importId, newImport);
|
||||
m_importCache[importKey].append(importId);
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#define QMLJSIMPORTCACHE_H
|
||||
|
||||
#include "qmljsviewercontext.h"
|
||||
#include "qmljsdialect.h"
|
||||
|
||||
#include <languageutils/componentversion.h>
|
||||
#include <utils/qtcoverride.h>
|
||||
@@ -147,10 +148,10 @@ class QMLJS_EXPORT CoreImport
|
||||
public:
|
||||
CoreImport();
|
||||
CoreImport(const QString &importId, const QList<Export> &possibleExports = QList<Export>(),
|
||||
Language::Enum language = Language::Qml, const QByteArray &fingerprint = QByteArray());
|
||||
Dialect language = Dialect::Qml, const QByteArray &fingerprint = QByteArray());
|
||||
QString importId;
|
||||
QList<Export> possibleExports;
|
||||
Language::Enum language;
|
||||
Dialect language;
|
||||
QByteArray fingerprint;
|
||||
bool valid();
|
||||
};
|
||||
|
||||
@@ -333,7 +333,7 @@ Import LinkPrivate::importFileOrDirectory(Document::Ptr doc, const ImportInfo &i
|
||||
->filesInQrcPath(path));
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
if (Document::isQmlLikeLanguage(ModelManagerInterface::guessLanguageOfFile(iter.key()))) {
|
||||
if (ModelManagerInterface::guessLanguageOfFile(iter.key()).isQmlLikeLanguage()) {
|
||||
Document::Ptr importedDoc = snapshot.document(iter.value().at(0));
|
||||
if (importedDoc && importedDoc->bind()->rootObjectValue()) {
|
||||
const QString targetName = QFileInfo(iter.key()).baseName();
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "qmljsmodelmanagerinterface.h"
|
||||
#include "qmljsplugindumper.h"
|
||||
#include "qmljstypedescriptionreader.h"
|
||||
#include "qmljsdialect.h"
|
||||
|
||||
#include <cplusplus/cppmodelmanagerbase.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
@@ -113,6 +114,9 @@ ModelManagerInterface::ModelManagerInterface(QObject *parent)
|
||||
|
||||
qRegisterMetaType<QmlJS::Document::Ptr>("QmlJS::Document::Ptr");
|
||||
qRegisterMetaType<QmlJS::LibraryInfo>("QmlJS::LibraryInfo");
|
||||
qRegisterMetaType<QmlJS::Dialect>("QmlJS::Dialect");
|
||||
qRegisterMetaType<QmlJS::PathAndLanguage>("QmlJS::PathAndLanguage");
|
||||
qRegisterMetaType<QmlJS::PathsAndLanguages>("QmlJS::PathsAndLanguages");
|
||||
|
||||
m_defaultProjectInfo.qtImportsPath = QLibraryInfo::location(QLibraryInfo::ImportsPath);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
@@ -134,39 +138,39 @@ ModelManagerInterface::~ModelManagerInterface()
|
||||
g_instance = 0;
|
||||
}
|
||||
|
||||
static QHash<QString, Language::Enum> defaultLanguageMapping()
|
||||
static QHash<QString, Dialect> defaultLanguageMapping()
|
||||
{
|
||||
QHash<QString, Language::Enum> res;
|
||||
res[QLatin1String("js")] = Language::JavaScript;
|
||||
res[QLatin1String("qml")] = Language::Qml;
|
||||
res[QLatin1String("qmltypes")] = Language::QmlTypeInfo;
|
||||
res[QLatin1String("qmlproject")] = Language::QmlProject;
|
||||
res[QLatin1String("json")] = Language::Json;
|
||||
res[QLatin1String("qbs")] = Language::QmlQbs;
|
||||
QHash<QString, Dialect> res;
|
||||
res[QLatin1String("js")] = Dialect::JavaScript;
|
||||
res[QLatin1String("qml")] = Dialect::Qml;
|
||||
res[QLatin1String("qmltypes")] = Dialect::QmlTypeInfo;
|
||||
res[QLatin1String("qmlproject")] = Dialect::QmlProject;
|
||||
res[QLatin1String("json")] = Dialect::Json;
|
||||
res[QLatin1String("qbs")] = Dialect::QmlQbs;
|
||||
return res;
|
||||
}
|
||||
|
||||
Language::Enum ModelManagerInterface::guessLanguageOfFile(const QString &fileName)
|
||||
Dialect ModelManagerInterface::guessLanguageOfFile(const QString &fileName)
|
||||
{
|
||||
QHash<QString, Language::Enum> lMapping;
|
||||
QHash<QString, Dialect> lMapping;
|
||||
if (instance())
|
||||
lMapping = instance()->languageForSuffix();
|
||||
else
|
||||
lMapping = defaultLanguageMapping();
|
||||
const QFileInfo info(fileName);
|
||||
const QString fileSuffix = info.suffix();
|
||||
return lMapping.value(fileSuffix, Language::NoLanguage);
|
||||
return lMapping.value(fileSuffix, Dialect::NoLanguage);
|
||||
}
|
||||
|
||||
QStringList ModelManagerInterface::globPatternsForLanguages(const QList<Language::Enum> languages)
|
||||
QStringList ModelManagerInterface::globPatternsForLanguages(const QList<Dialect> languages)
|
||||
{
|
||||
QHash<QString, Language::Enum> lMapping;
|
||||
QHash<QString, Dialect> lMapping;
|
||||
if (instance())
|
||||
lMapping = instance()->languageForSuffix();
|
||||
else
|
||||
lMapping = defaultLanguageMapping();
|
||||
QStringList patterns;
|
||||
QHashIterator<QString,Language::Enum> i(lMapping);
|
||||
QHashIterator<QString,Dialect> i(lMapping);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (languages.contains(i.value()))
|
||||
@@ -203,7 +207,7 @@ void ModelManagerInterface::activateScan()
|
||||
}
|
||||
}
|
||||
|
||||
QHash<QString, Language::Enum> ModelManagerInterface::languageForSuffix() const
|
||||
QHash<QString, Dialect> ModelManagerInterface::languageForSuffix() const
|
||||
{
|
||||
return defaultLanguageMapping();
|
||||
}
|
||||
@@ -294,7 +298,7 @@ QFuture<void> ModelManagerInterface::refreshSourceFiles(const QStringList &sourc
|
||||
|
||||
QFuture<void> result = QtConcurrent::run(&ModelManagerInterface::parse,
|
||||
workingCopyInternal(), sourceFiles,
|
||||
this, Language::Qml,
|
||||
this, Dialect(Dialect::Qml),
|
||||
emitDocumentOnDiskChanged);
|
||||
|
||||
if (m_synchronizer.futures().size() > 10) {
|
||||
@@ -334,7 +338,7 @@ void ModelManagerInterface::fileChangedOnDisk(const QString &path)
|
||||
{
|
||||
QtConcurrent::run(&ModelManagerInterface::parse,
|
||||
workingCopyInternal(), QStringList() << path,
|
||||
this, Language::AnyLanguage, true);
|
||||
this, Dialect(Dialect::AnyLanguage), true);
|
||||
}
|
||||
|
||||
void ModelManagerInterface::removeFiles(const QStringList &files)
|
||||
@@ -394,8 +398,8 @@ bool pInfoLessThanImports(const ModelManagerInterface::ProjectInfo &p1, const Mo
|
||||
return true;
|
||||
if (p1.qtImportsPath > p2.qtImportsPath)
|
||||
return false;
|
||||
QStringList s1 = p1.importPaths;
|
||||
QStringList s2 = p2.importPaths;
|
||||
const PathsAndLanguages &s1 = p1.importPaths;
|
||||
const PathsAndLanguages &s2 = p2.importPaths;
|
||||
if (s1.size() < s2.size())
|
||||
return true;
|
||||
if (s1.size() > s2.size())
|
||||
@@ -403,7 +407,7 @@ bool pInfoLessThanImports(const ModelManagerInterface::ProjectInfo &p1, const Mo
|
||||
for (int i = 0; i < s1.size(); ++i) {
|
||||
if (s1.at(i) < s2.at(i))
|
||||
return true;
|
||||
else if (s1.at(i) > s2.at(i))
|
||||
else if (s2.at(i) < s1.at(i))
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@@ -603,9 +607,8 @@ ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfoForPath(QSt
|
||||
res.qtImportsPath = pInfo.qtImportsPath;
|
||||
if (res.qtQmlPath.isEmpty())
|
||||
res.qtQmlPath = pInfo.qtQmlPath;
|
||||
foreach (const QString &path, pInfo.importPaths)
|
||||
if (!res.importPaths.contains(path))
|
||||
res.importPaths.append(path);
|
||||
for (int i = 0; i < pInfo.importPaths.size(); ++i)
|
||||
res.importPaths.maybeInsert(pInfo.importPaths.at(i));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -643,7 +646,7 @@ void ModelManagerInterface::updateLibraryInfo(const QString &path, const Library
|
||||
emit libraryInfoUpdated(path, info);
|
||||
}
|
||||
|
||||
static QStringList filesInDirectoryForLanguages(const QString &path, QList<Language::Enum> languages)
|
||||
static QStringList filesInDirectoryForLanguages(const QString &path, QList<Dialect> languages)
|
||||
{
|
||||
const QStringList pattern = ModelManagerInterface::globPatternsForLanguages(languages);
|
||||
QStringList files;
|
||||
@@ -663,7 +666,7 @@ static void findNewImplicitImports(const Document::Ptr &doc, const Snapshot &sna
|
||||
if (snapshot.documentsInDirectory(doc->path()).isEmpty()) {
|
||||
if (! scannedPaths->contains(doc->path())) {
|
||||
*importedFiles += filesInDirectoryForLanguages(doc->path(),
|
||||
Document::companionLanguages(doc->language()));
|
||||
doc->language().companionLanguages());
|
||||
scannedPaths->insert(doc->path());
|
||||
}
|
||||
}
|
||||
@@ -682,7 +685,7 @@ static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapsho
|
||||
if (snapshot.documentsInDirectory(importName).isEmpty()) {
|
||||
if (! scannedPaths->contains(importName)) {
|
||||
*importedFiles += filesInDirectoryForLanguages(importName,
|
||||
Document::companionLanguages(doc->language()));
|
||||
doc->language().companionLanguages());
|
||||
scannedPaths->insert(importName);
|
||||
}
|
||||
}
|
||||
@@ -696,7 +699,7 @@ static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapsho
|
||||
QMapIterator<QString,QStringList> dirContents(ModelManagerInterface::instance()->filesInQrcPath(importName));
|
||||
while (dirContents.hasNext()) {
|
||||
dirContents.next();
|
||||
if (Document::isQmlLikeOrJsLanguage(ModelManagerInterface::guessLanguageOfFile(dirContents.key()))) {
|
||||
if (ModelManagerInterface::guessLanguageOfFile(dirContents.key()).isQmlLikeOrJsLanguage()) {
|
||||
foreach (const QString &filePath, dirContents.value()) {
|
||||
if (! snapshot.document(filePath))
|
||||
*importedFiles += filePath;
|
||||
@@ -759,7 +762,7 @@ static bool findNewQmlLibraryInPath(const QString &path,
|
||||
const QString path = QDir::cleanPath(componentFileInfo.absolutePath());
|
||||
if (! scannedPaths->contains(path)) {
|
||||
*importedFiles += filesInDirectoryForLanguages(path,
|
||||
Document::companionLanguages(Language::AnyLanguage));
|
||||
Dialect(Dialect::AnyLanguage).companionLanguages());
|
||||
scannedPaths->insert(path);
|
||||
}
|
||||
}
|
||||
@@ -806,7 +809,7 @@ static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snap
|
||||
importedFiles, scannedPaths, newLibraries, false);
|
||||
|
||||
// scan dir and lib imports
|
||||
const QStringList importPaths = modelManager->importPaths();
|
||||
const PathsAndLanguages importPaths = modelManager->importPaths();
|
||||
foreach (const ImportInfo &import, doc->bind()->imports()) {
|
||||
if (import.type() == ImportType::Directory) {
|
||||
const QString targetPath = import.path();
|
||||
@@ -817,8 +820,8 @@ static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snap
|
||||
if (import.type() == ImportType::Library) {
|
||||
if (!import.version().isValid())
|
||||
continue;
|
||||
foreach (const QString &importPath, importPaths) {
|
||||
const QString targetPath = QDir(importPath).filePath(import.path());
|
||||
foreach (const PathAndLanguage &importPath, importPaths) {
|
||||
const QString targetPath = importPath.path().toFileInfo().dir().filePath(import.path());
|
||||
findNewQmlLibrary(targetPath, import.version(), snapshot, modelManager,
|
||||
importedFiles, scannedPaths, newLibraries);
|
||||
}
|
||||
@@ -831,7 +834,7 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
|
||||
WorkingCopy workingCopy,
|
||||
QStringList files,
|
||||
ModelManagerInterface *modelManager,
|
||||
Language::Enum mainLanguage,
|
||||
Dialect mainLanguage,
|
||||
bool emitDocChangedOnDisk,
|
||||
std::function<bool(qreal)> reportProgress)
|
||||
{
|
||||
@@ -841,14 +844,14 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
|
||||
|
||||
const QString fileName = files.at(i);
|
||||
|
||||
Language::Enum language = guessLanguageOfFile(fileName);
|
||||
if (language == Language::NoLanguage) {
|
||||
Dialect language = guessLanguageOfFile(fileName);
|
||||
if (language == Dialect::NoLanguage) {
|
||||
if (fileName.endsWith(QLatin1String(".qrc")))
|
||||
modelManager->updateQrcFile(fileName);
|
||||
continue;
|
||||
}
|
||||
if (language == Language::Qml
|
||||
&& (mainLanguage == Language::QmlQtQuick1 || mainLanguage == Language::QmlQtQuick2))
|
||||
if (language == Dialect::Qml
|
||||
&& (mainLanguage == Dialect::QmlQtQuick1 || mainLanguage == Dialect::QmlQtQuick2))
|
||||
language = mainLanguage;
|
||||
QString contents;
|
||||
int documentRevision = 0;
|
||||
@@ -917,7 +920,7 @@ void ModelManagerInterface::parse(QFutureInterface<void> &future,
|
||||
WorkingCopy workingCopy,
|
||||
QStringList files,
|
||||
ModelManagerInterface *modelManager,
|
||||
Language::Enum mainLanguage,
|
||||
Dialect mainLanguage,
|
||||
bool emitDocChangedOnDisk)
|
||||
{
|
||||
FutureReporter reporter(future);
|
||||
@@ -935,15 +938,15 @@ void ModelManagerInterface::parse(QFutureInterface<void> &future,
|
||||
struct ScanItem {
|
||||
QString path;
|
||||
int depth;
|
||||
ScanItem(QString path = QString(), int depth = 0)
|
||||
: path(path), depth(depth)
|
||||
Dialect language;
|
||||
ScanItem(QString path = QString(), int depth = 0, Dialect language = Dialect::AnyLanguage)
|
||||
: path(path), depth(depth), language(language)
|
||||
{ }
|
||||
};
|
||||
|
||||
void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
ModelManagerInterface::WorkingCopy workingCopy,
|
||||
QStringList paths, ModelManagerInterface *modelManager,
|
||||
Language::Enum language,
|
||||
PathsAndLanguages paths, ModelManagerInterface *modelManager,
|
||||
bool emitDocChangedOnDisk)
|
||||
{
|
||||
// paths we have scanned for files and added to the files list
|
||||
@@ -959,11 +962,12 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
pathsToScan.reserve(paths.size());
|
||||
{
|
||||
QMutexLocker l(&modelManager->m_mutex);
|
||||
foreach (const QString &path, paths) {
|
||||
QString cPath = QDir::cleanPath(path);
|
||||
for (int i = 0; i < paths.size(); ++i) {
|
||||
PathAndLanguage pAndL = paths.at(i);
|
||||
QString cPath = QDir::cleanPath(pAndL.path().toString());
|
||||
if (modelManager->m_scannedPaths.contains(cPath))
|
||||
continue;
|
||||
pathsToScan.append(ScanItem(cPath));
|
||||
pathsToScan.append(ScanItem(cPath, 0, pAndL.language()));
|
||||
modelManager->m_scannedPaths.insert(cPath);
|
||||
}
|
||||
}
|
||||
@@ -983,14 +987,14 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
&scannedPaths, &newLibraries, true)
|
||||
&& !libOnly && snapshot.documentsInDirectory(toScan.path).isEmpty())
|
||||
importedFiles += filesInDirectoryForLanguages(toScan.path,
|
||||
Document::companionLanguages(language));
|
||||
toScan.language.companionLanguages());
|
||||
workDone += 1;
|
||||
future.setProgressValue(progressRange * workDone / totalWork);
|
||||
if (!importedFiles.isEmpty()) {
|
||||
FutureReporter reporter(future, progressRange * pathBudget / (4 * totalWork),
|
||||
progressRange * workDone / totalWork);
|
||||
parseLoop(scannedPaths, newLibraries, workingCopy, importedFiles, modelManager,
|
||||
language, emitDocChangedOnDisk, reporter); // run in parallel??
|
||||
toScan.language, emitDocChangedOnDisk, reporter); // run in parallel??
|
||||
importedFiles.clear();
|
||||
}
|
||||
workDone += pathBudget / 4 - 1;
|
||||
@@ -1004,8 +1008,8 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
QStringList subDirs(dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot));
|
||||
workDone += 1;
|
||||
totalWork += pathBudget / 2 * subDirs.size() - pathBudget * 3 / 4 + 1;
|
||||
foreach (const QString &path, subDirs)
|
||||
pathsToScan.append(ScanItem(dir.absoluteFilePath(path), toScan.depth + 1));
|
||||
foreach (const QString path, subDirs)
|
||||
pathsToScan.append(ScanItem(dir.absoluteFilePath(path), toScan.depth + 1, toScan.language));
|
||||
} else {
|
||||
workDone += pathBudget * 3 / 4;
|
||||
}
|
||||
@@ -1015,12 +1019,12 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
if (future.isCanceled()) {
|
||||
// assume no work has been done
|
||||
QMutexLocker l(&modelManager->m_mutex);
|
||||
foreach (const QString &path, paths)
|
||||
modelManager->m_scannedPaths.remove(path);
|
||||
for (int i = 0; i < paths.size(); ++i)
|
||||
modelManager->m_scannedPaths.remove(paths.at(i).path().toString());
|
||||
}
|
||||
}
|
||||
|
||||
QStringList ModelManagerInterface::importPaths() const
|
||||
PathsAndLanguages ModelManagerInterface::importPaths() const
|
||||
{
|
||||
QMutexLocker l(&m_mutex);
|
||||
return m_allImportPaths;
|
||||
@@ -1038,23 +1042,20 @@ QmlLanguageBundles ModelManagerInterface::extendedBundles() const
|
||||
return m_extendedBundles;
|
||||
}
|
||||
|
||||
void ModelManagerInterface::maybeScan(const QStringList &importPaths,
|
||||
Language::Enum defaultLanguage)
|
||||
void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths)
|
||||
{
|
||||
QStringList pathToScan;
|
||||
PathsAndLanguages pathToScan;
|
||||
{
|
||||
QMutexLocker l(&m_mutex);
|
||||
foreach (const QString &importPath, importPaths)
|
||||
if (!m_scannedPaths.contains(importPath)) {
|
||||
pathToScan.append(importPath);
|
||||
}
|
||||
foreach (const PathAndLanguage &importPath, importPaths)
|
||||
if (!m_scannedPaths.contains(importPath.path().toString()))
|
||||
pathToScan.maybeInsert(importPath);
|
||||
}
|
||||
|
||||
if (pathToScan.count() > 1) {
|
||||
if (pathToScan.length() > 1) {
|
||||
QFuture<void> result = QtConcurrent::run(&ModelManagerInterface::importScan,
|
||||
workingCopyInternal(), pathToScan,
|
||||
this, defaultLanguage,
|
||||
true);
|
||||
this, true);
|
||||
|
||||
if (m_synchronizer.futures().size() > 10) {
|
||||
QList<QFuture<void> > futures = m_synchronizer.futures();
|
||||
@@ -1075,33 +1076,37 @@ void ModelManagerInterface::maybeScan(const QStringList &importPaths,
|
||||
|
||||
void ModelManagerInterface::updateImportPaths()
|
||||
{
|
||||
QStringList allImportPaths;
|
||||
PathsAndLanguages allImportPaths;
|
||||
QmlLanguageBundles activeBundles;
|
||||
QmlLanguageBundles extendedBundles;
|
||||
QMapIterator<ProjectExplorer::Project *, ProjectInfo> pInfoIter(m_projects);
|
||||
QHashIterator<Language::Enum, QmlJS::ViewerContext> vCtxsIter = m_defaultVContexts;
|
||||
QHashIterator<Dialect, QmlJS::ViewerContext> vCtxsIter = m_defaultVContexts;
|
||||
while (pInfoIter.hasNext()) {
|
||||
pInfoIter.next();
|
||||
foreach (const QString &path, pInfoIter.value().importPaths) {
|
||||
const QString canonicalPath = QFileInfo(path).canonicalFilePath();
|
||||
const PathsAndLanguages &iPaths = pInfoIter.value().importPaths;
|
||||
for (int i = 0; i < iPaths.size(); ++i) {
|
||||
PathAndLanguage pAndL = iPaths.at(i);
|
||||
const QString canonicalPath = pAndL.path().toFileInfo().canonicalFilePath();
|
||||
if (!canonicalPath.isEmpty())
|
||||
allImportPaths += canonicalPath;
|
||||
allImportPaths.maybeInsert(Utils::FileName::fromString(canonicalPath),
|
||||
pAndL.language());
|
||||
}
|
||||
}
|
||||
while (vCtxsIter.hasNext()) {
|
||||
vCtxsIter.next();
|
||||
allImportPaths << vCtxsIter.value().paths;
|
||||
foreach (const QString &path, vCtxsIter.value().paths)
|
||||
allImportPaths.maybeInsert(Utils::FileName::fromString(path), vCtxsIter.value().language);
|
||||
}
|
||||
pInfoIter.toFront();
|
||||
while (pInfoIter.hasNext()) {
|
||||
pInfoIter.next();
|
||||
activeBundles.mergeLanguageBundles(pInfoIter.value().activeBundle);
|
||||
foreach (Language::Enum l, pInfoIter.value().activeBundle.languages()) {
|
||||
foreach (Dialect l, pInfoIter.value().activeBundle.languages()) {
|
||||
foreach (const QString &path, pInfoIter.value().activeBundle.bundleForLanguage(l)
|
||||
.searchPaths().stringList()) {
|
||||
const QString canonicalPath = QFileInfo(path).canonicalFilePath();
|
||||
if (!canonicalPath.isEmpty())
|
||||
allImportPaths += canonicalPath;
|
||||
allImportPaths.maybeInsert(Utils::FileName::fromString(canonicalPath), l);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1109,28 +1114,29 @@ void ModelManagerInterface::updateImportPaths()
|
||||
while (pInfoIter.hasNext()) {
|
||||
pInfoIter.next();
|
||||
QString pathAtt = pInfoIter.value().qtQmlPath;
|
||||
if (!pathAtt.isEmpty() && (allImportPaths.isEmpty() || allImportPaths.last() != pathAtt))
|
||||
allImportPaths.append(pathAtt);
|
||||
if (!pathAtt.isEmpty())
|
||||
allImportPaths.maybeInsert(Utils::FileName::fromString(pathAtt), Dialect::QmlQtQuick2);
|
||||
}
|
||||
{
|
||||
QString pathAtt = defaultProjectInfo().qtQmlPath;
|
||||
if (!pathAtt.isEmpty() && (allImportPaths.isEmpty() || allImportPaths.last() != pathAtt))
|
||||
allImportPaths.append(pathAtt);
|
||||
if (!pathAtt.isEmpty())
|
||||
allImportPaths.maybeInsert(Utils::FileName::fromString(pathAtt), Dialect::QmlQtQuick2);
|
||||
}
|
||||
pInfoIter.toFront();
|
||||
while (pInfoIter.hasNext()) {
|
||||
pInfoIter.next();
|
||||
QString pathAtt = pInfoIter.value().qtImportsPath;
|
||||
if (!pathAtt.isEmpty() && (allImportPaths.isEmpty() || allImportPaths.last() != pathAtt))
|
||||
allImportPaths.append(pathAtt);
|
||||
if (!pathAtt.isEmpty())
|
||||
allImportPaths.maybeInsert(Utils::FileName::fromString(pathAtt), Dialect::QmlQtQuick1);
|
||||
}
|
||||
{
|
||||
QString pathAtt = defaultProjectInfo().qtImportsPath;
|
||||
if (!pathAtt.isEmpty() && (allImportPaths.isEmpty() || allImportPaths.last() != pathAtt))
|
||||
allImportPaths.append(pathAtt);
|
||||
if (!pathAtt.isEmpty())
|
||||
allImportPaths.maybeInsert(Utils::FileName::fromString(pathAtt), Dialect::QmlQtQuick1);
|
||||
}
|
||||
allImportPaths += m_defaultImportPaths;
|
||||
allImportPaths.removeDuplicates();
|
||||
foreach (const QString &path, m_defaultImportPaths)
|
||||
allImportPaths.maybeInsert(Utils::FileName::fromString(path), Dialect::Qml);
|
||||
allImportPaths.compact();
|
||||
|
||||
{
|
||||
QMutexLocker l(&m_mutex);
|
||||
@@ -1152,7 +1158,7 @@ void ModelManagerInterface::updateImportPaths()
|
||||
|
||||
if (!m_shouldScanImports)
|
||||
return;
|
||||
maybeScan(allImportPaths, Language::Qml);
|
||||
maybeScan(allImportPaths);
|
||||
}
|
||||
|
||||
void ModelManagerInterface::loadPluginTypes(const QString &libraryPath, const QString &importPath,
|
||||
@@ -1298,10 +1304,10 @@ ViewerContext ModelManagerInterface::completeVContext(const ViewerContext &vCtx,
|
||||
ViewerContext res = vCtx;
|
||||
|
||||
if (!doc.isNull()
|
||||
&& ((vCtx.language == Language::AnyLanguage && doc->language() != Language::NoLanguage)
|
||||
|| (vCtx.language == Language::Qml
|
||||
&& (doc->language() == Language::QmlQtQuick1
|
||||
|| doc->language() == Language::QmlQtQuick2))))
|
||||
&& ((vCtx.language == Dialect::AnyLanguage && doc->language() != Dialect::NoLanguage)
|
||||
|| (vCtx.language == Dialect::Qml
|
||||
&& (doc->language() == Dialect::QmlQtQuick1
|
||||
|| doc->language() == Dialect::QmlQtQuick2))))
|
||||
res.language = doc->language();
|
||||
ProjectInfo info;
|
||||
if (!doc.isNull())
|
||||
@@ -1322,17 +1328,17 @@ ViewerContext ModelManagerInterface::completeVContext(const ViewerContext &vCtx,
|
||||
{
|
||||
foreach (const QString &path, defaultVCtx.paths)
|
||||
res.maybeAddPath(path);
|
||||
switch (res.language) {
|
||||
case Language::AnyLanguage:
|
||||
case Language::Qml:
|
||||
switch (res.language.dialect()) {
|
||||
case Dialect::AnyLanguage:
|
||||
case Dialect::Qml:
|
||||
res.maybeAddPath(info.qtQmlPath);
|
||||
// fallthrough
|
||||
case Language::QmlQtQuick1:
|
||||
case Dialect::QmlQtQuick1:
|
||||
res.maybeAddPath(info.qtImportsPath);
|
||||
// fallthrough
|
||||
case Language::QmlQtQuick2:
|
||||
case Dialect::QmlQtQuick2:
|
||||
{
|
||||
if (res.language == Language::QmlQtQuick2)
|
||||
if (res.language == Dialect::QmlQtQuick2)
|
||||
res.maybeAddPath(info.qtQmlPath);
|
||||
QList<ProjectInfo> allProjects;
|
||||
{
|
||||
@@ -1340,18 +1346,22 @@ ViewerContext ModelManagerInterface::completeVContext(const ViewerContext &vCtx,
|
||||
allProjects = m_projects.values();
|
||||
}
|
||||
std::sort(allProjects.begin(), allProjects.end(), &pInfoLessThanImports);
|
||||
QList<Dialect> languages = res.language.companionLanguages();
|
||||
foreach (const ProjectInfo &pInfo, allProjects) {
|
||||
foreach (const QString &path, pInfo.importPaths)
|
||||
res.maybeAddPath(path);
|
||||
for (int i = 0; i< pInfo.importPaths.size(); ++i) {
|
||||
PathAndLanguage pAndL = pInfo.importPaths.at(i);
|
||||
if (languages.contains(pAndL.language()) || pAndL.language().companionLanguages().contains(res.language))
|
||||
res.maybeAddPath(pAndL.path().toString());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Language::NoLanguage:
|
||||
case Language::JavaScript:
|
||||
case Language::QmlTypeInfo:
|
||||
case Language::Json:
|
||||
case Language::QmlQbs:
|
||||
case Language::QmlProject:
|
||||
case Dialect::NoLanguage:
|
||||
case Dialect::JavaScript:
|
||||
case Dialect::QmlTypeInfo:
|
||||
case Dialect::Json:
|
||||
case Dialect::QmlQbs:
|
||||
case Dialect::QmlProject:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -1362,11 +1372,11 @@ ViewerContext ModelManagerInterface::completeVContext(const ViewerContext &vCtx,
|
||||
case ViewerContext::AddDefaultPaths:
|
||||
foreach (const QString &path, defaultVCtx.paths)
|
||||
res.maybeAddPath(path);
|
||||
if (res.language == Language::AnyLanguage || res.language == Language::Qml
|
||||
|| res.language == Language::QmlQtQuick2)
|
||||
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml
|
||||
|| res.language == Dialect::QmlQtQuick2)
|
||||
res.maybeAddPath(info.qtImportsPath);
|
||||
if (res.language == Language::AnyLanguage || res.language == Language::Qml
|
||||
|| res.language == Language::QmlQtQuick1)
|
||||
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml
|
||||
|| res.language == Dialect::QmlQtQuick1)
|
||||
res.maybeAddPath(info.qtQmlPath);
|
||||
break;
|
||||
}
|
||||
@@ -1374,15 +1384,15 @@ ViewerContext ModelManagerInterface::completeVContext(const ViewerContext &vCtx,
|
||||
return res;
|
||||
}
|
||||
|
||||
ViewerContext ModelManagerInterface::defaultVContext(Language::Enum language,
|
||||
ViewerContext ModelManagerInterface::defaultVContext(Dialect language,
|
||||
const Document::Ptr &doc,
|
||||
bool autoComplete) const
|
||||
{
|
||||
if (!doc.isNull()) {
|
||||
if (language == Language::AnyLanguage && doc->language() != Language::NoLanguage)
|
||||
if (language == Dialect::AnyLanguage && doc->language() != Dialect::NoLanguage)
|
||||
language = doc->language();
|
||||
else if (language == Language::Qml &&
|
||||
(doc->language() == Language::QmlQtQuick1 || doc->language() == Language::QmlQtQuick2))
|
||||
else if (language == Dialect::Qml &&
|
||||
(doc->language() == Dialect::QmlQtQuick1 || doc->language() == Dialect::QmlQtQuick2))
|
||||
language = doc->language();
|
||||
}
|
||||
ViewerContext defaultCtx;
|
||||
@@ -1425,7 +1435,7 @@ Document::Ptr ModelManagerInterface::ensuredGetDocumentForPath(const QString &fi
|
||||
{
|
||||
QmlJS::Document::Ptr document = newestSnapshot().document(filePath);
|
||||
if (!document) {
|
||||
document = QmlJS::Document::create(filePath, QmlJS::Language::Qml);
|
||||
document = QmlJS::Document::create(filePath, QmlJS::Dialect::Qml);
|
||||
QMutexLocker lock(&m_mutex);
|
||||
|
||||
m_newestSnapshot.insert(document);
|
||||
|
||||
@@ -36,9 +36,11 @@
|
||||
#include "qmljsdocument.h"
|
||||
#include "qmljsqrcparser.h"
|
||||
#include "qmljsviewercontext.h"
|
||||
#include "qmljsdialect.h"
|
||||
|
||||
#include <cplusplus/CppDocument.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QFuture>
|
||||
#include <QFutureSynchronizer>
|
||||
@@ -93,7 +95,7 @@ public:
|
||||
public: // attributes
|
||||
QPointer<ProjectExplorer::Project> project;
|
||||
QStringList sourceFiles;
|
||||
QStringList importPaths;
|
||||
PathsAndLanguages importPaths;
|
||||
QStringList activeResourceFiles;
|
||||
QStringList allResourceFiles;
|
||||
|
||||
@@ -148,8 +150,8 @@ public:
|
||||
ModelManagerInterface(QObject *parent = 0);
|
||||
virtual ~ModelManagerInterface();
|
||||
|
||||
static Language::Enum guessLanguageOfFile(const QString &fileName);
|
||||
static QStringList globPatternsForLanguages(const QList<Language::Enum> languages);
|
||||
static Dialect guessLanguageOfFile(const QString &fileName);
|
||||
static QStringList globPatternsForLanguages(const QList<Dialect> languages);
|
||||
static ModelManagerInterface *instance();
|
||||
static void writeWarning(const QString &msg);
|
||||
static WorkingCopy workingCopy();
|
||||
@@ -182,7 +184,7 @@ public:
|
||||
void updateQrcFile(const QString &path);
|
||||
ProjectInfo projectInfoForPath(QString path) const;
|
||||
|
||||
QStringList importPaths() const;
|
||||
PathsAndLanguages importPaths() const;
|
||||
QmlJS::QmlLanguageBundles activeBundles() const;
|
||||
QmlJS::QmlLanguageBundles extendedBundles() const;
|
||||
|
||||
@@ -193,7 +195,7 @@ public:
|
||||
LibraryInfo builtins(const Document::Ptr &doc) const;
|
||||
ViewerContext completeVContext(const ViewerContext &vCtx,
|
||||
const Document::Ptr &doc = Document::Ptr(0)) const;
|
||||
ViewerContext defaultVContext(Language::Enum language = Language::Qml,
|
||||
ViewerContext defaultVContext(Dialect language = Dialect::Qml,
|
||||
const Document::Ptr &doc = Document::Ptr(0),
|
||||
bool autoComplete = true) const;
|
||||
void setDefaultVContext(const ViewerContext &vContext);
|
||||
@@ -223,7 +225,7 @@ protected slots:
|
||||
virtual void startCppQmlTypeUpdate();
|
||||
protected:
|
||||
QMutex *mutex() const;
|
||||
virtual QHash<QString,Language::Enum> languageForSuffix() const;
|
||||
virtual QHash<QString,Dialect> languageForSuffix() const;
|
||||
virtual void writeMessageInternal(const QString &msg) const;
|
||||
virtual WorkingCopy workingCopyInternal() const;
|
||||
virtual void addTaskInternal(QFuture<void> result, const QString &msg, const char *taskId) const;
|
||||
@@ -233,26 +235,25 @@ protected:
|
||||
|
||||
static void parseLoop(QSet<QString> &scannedPaths, QSet<QString> &newLibraries,
|
||||
WorkingCopy workingCopyInternal, QStringList files, ModelManagerInterface *modelManager,
|
||||
QmlJS::Language::Enum mainLanguage, bool emitDocChangedOnDisk,
|
||||
QmlJS::Dialect mainLanguage, bool emitDocChangedOnDisk,
|
||||
std::function<bool (qreal)> reportProgress);
|
||||
static void parse(QFutureInterface<void> &future,
|
||||
WorkingCopy workingCopyInternal,
|
||||
QStringList files,
|
||||
ModelManagerInterface *modelManager,
|
||||
QmlJS::Language::Enum mainLanguage,
|
||||
QmlJS::Dialect mainLanguage,
|
||||
bool emitDocChangedOnDisk);
|
||||
static void importScan(QFutureInterface<void> &future,
|
||||
WorkingCopy workingCopyInternal,
|
||||
QStringList paths,
|
||||
PathsAndLanguages paths,
|
||||
ModelManagerInterface *modelManager,
|
||||
QmlJS::Language::Enum mainLanguage,
|
||||
bool emitDocChangedOnDisk);
|
||||
static void updateCppQmlTypes(QFutureInterface<void> &interface,
|
||||
ModelManagerInterface *qmlModelManager,
|
||||
CPlusPlus::Snapshot snapshot,
|
||||
QHash<QString, QPair<CPlusPlus::Document::Ptr, bool> > documents);
|
||||
|
||||
void maybeScan(const QStringList &importPaths, Language::Enum defaultLanguage);
|
||||
void maybeScan(const PathsAndLanguages &importPaths);
|
||||
void updateImportPaths();
|
||||
void loadQmlTypeDescriptionsInternal(const QString &path);
|
||||
void setDefaultProject(const ProjectInfo &pInfo, ProjectExplorer::Project *p);
|
||||
@@ -261,11 +262,11 @@ private:
|
||||
mutable QMutex m_mutex;
|
||||
QmlJS::Snapshot m_validSnapshot;
|
||||
QmlJS::Snapshot m_newestSnapshot;
|
||||
QStringList m_allImportPaths;
|
||||
PathsAndLanguages m_allImportPaths;
|
||||
QStringList m_defaultImportPaths;
|
||||
QmlJS::QmlLanguageBundles m_activeBundles;
|
||||
QmlJS::QmlLanguageBundles m_extendedBundles;
|
||||
QHash<Language::Enum, QmlJS::ViewerContext> m_defaultVContexts;
|
||||
QHash<Dialect, QmlJS::ViewerContext> m_defaultVContexts;
|
||||
bool m_shouldScanImports;
|
||||
QSet<QString> m_scannedPaths;
|
||||
|
||||
|
||||
@@ -258,7 +258,7 @@ void ScopeChain::update() const
|
||||
m_all += m_cppContextProperties;
|
||||
|
||||
// the root scope in js files doesn't see instantiating components
|
||||
if (m_document->language() != Language::JavaScript || m_jsScopes.count() != 1) {
|
||||
if (m_document->language() != Dialect::JavaScript || m_jsScopes.count() != 1) {
|
||||
if (m_qmlComponentScope) {
|
||||
foreach (const QmlComponentChain *parent, m_qmlComponentScope->instantiatingComponents())
|
||||
collectScopes(parent, &m_all);
|
||||
|
||||
@@ -40,11 +40,11 @@ namespace QmlJS {
|
||||
Screen information will also most likely need to be added here.
|
||||
*/
|
||||
ViewerContext::ViewerContext()
|
||||
: language(Language::Qml), flags(AddAllPaths)
|
||||
: language(Dialect::Qml), flags(AddAllPaths)
|
||||
{ }
|
||||
|
||||
ViewerContext::ViewerContext(QStringList selectors, QStringList paths,
|
||||
QmlJS::Language::Enum language,
|
||||
QmlJS::Dialect language,
|
||||
QmlJS::ViewerContext::Flags flags)
|
||||
: selectors(selectors), paths(paths), language(language),
|
||||
flags(flags)
|
||||
@@ -54,27 +54,27 @@ ViewerContext::ViewerContext(QStringList selectors, QStringList paths,
|
||||
/*
|
||||
which languages might be imported in this context
|
||||
*/
|
||||
bool ViewerContext::languageIsCompatible(Language::Enum l) const
|
||||
bool ViewerContext::languageIsCompatible(Dialect l) const
|
||||
{
|
||||
if (l == Language::AnyLanguage && language != Language::NoLanguage)
|
||||
if (l == Dialect::AnyLanguage && language != Dialect::NoLanguage)
|
||||
return true;
|
||||
switch (language) {
|
||||
case Language::JavaScript:
|
||||
case Language::Json:
|
||||
case Language::QmlProject:
|
||||
case Language::QmlQbs:
|
||||
case Language::QmlTypeInfo:
|
||||
switch (language.dialect()) {
|
||||
case Dialect::JavaScript:
|
||||
case Dialect::Json:
|
||||
case Dialect::QmlProject:
|
||||
case Dialect::QmlQbs:
|
||||
case Dialect::QmlTypeInfo:
|
||||
return language == l;
|
||||
case Language::Qml:
|
||||
return l == Language::Qml || l == Language::QmlQtQuick1 || l == Language::QmlQtQuick2
|
||||
|| l == Language::JavaScript;
|
||||
case Language::QmlQtQuick1:
|
||||
return l == Language::Qml || l == Language::QmlQtQuick1 || l == Language::JavaScript;
|
||||
case Language::QmlQtQuick2:
|
||||
return l == Language::Qml || l == Language::QmlQtQuick2 || l == Language::JavaScript;
|
||||
case Language::AnyLanguage:
|
||||
case Dialect::Qml:
|
||||
return l == Dialect::Qml || l == Dialect::QmlQtQuick1 || l == Dialect::QmlQtQuick2
|
||||
|| l == Dialect::JavaScript;
|
||||
case Dialect::QmlQtQuick1:
|
||||
return l == Dialect::Qml || l == Dialect::QmlQtQuick1 || l == Dialect::JavaScript;
|
||||
case Dialect::QmlQtQuick2:
|
||||
return l == Dialect::Qml || l == Dialect::QmlQtQuick2 || l == Dialect::JavaScript;
|
||||
case Dialect::AnyLanguage:
|
||||
return true;
|
||||
case Language::NoLanguage:
|
||||
case Dialect::NoLanguage:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "qmljs_global.h"
|
||||
#include "qmljsconstants.h"
|
||||
#include "qmljsdialect.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
@@ -50,15 +51,15 @@ public:
|
||||
|
||||
ViewerContext();
|
||||
ViewerContext(QStringList selectors, QStringList paths,
|
||||
Language::Enum language = Language::Qml,
|
||||
Dialect language = Dialect::Qml,
|
||||
Flags flags = AddAllPaths);
|
||||
|
||||
bool languageIsCompatible(Language::Enum l) const;
|
||||
bool languageIsCompatible(Dialect l) const;
|
||||
void maybeAddPath(const QString &path);
|
||||
|
||||
QStringList selectors;
|
||||
QStringList paths;
|
||||
Language::Enum language;
|
||||
Dialect language;
|
||||
Flags flags;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user