Commit 174baf5e authored by Fawzi Mohamed's avatar Fawzi Mohamed

qmljs: differnt language constants for the different qml flavors

Added separated qbs, qmltypes, QtQuick1, and QtQuick2
and "generic" Qml languages.
Cleaned up the mime types a bit, preparing for registered mime
types.

Change-Id: I0e484c93e003176cd659acc546baa6d024defa19
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent a839a46d
......@@ -83,6 +83,21 @@ using namespace QmlJS::AST;
*/
bool Document::isQmlLikeLanguage(Document::Language language)
{
switch (language) {
case QmlLanguage:
case QmlQtQuick1Language:
case QmlQtQuick2Language:
case QmlQbsLanguage:
case QmlProjectLanguage:
case QmlTypeInfoLanguage:
return true;
default:
return false;
}
}
Document::Document(const QString &fileName, Language language)
: _engine(0)
, _ast(0)
......@@ -95,7 +110,7 @@ Document::Document(const QString &fileName, Language language)
QFileInfo fileInfo(fileName);
_path = QDir::cleanPath(fileInfo.absolutePath());
if (language == QmlLanguage) {
if (isQmlLikeLanguage(language)) {
_componentName = fileInfo.baseName();
if (! _componentName.isEmpty()) {
......@@ -127,6 +142,8 @@ Document::Language Document::guessLanguageFromSuffix(const QString &fileName)
{
if (fileName.endsWith(QLatin1String(".qml"), Qt::CaseInsensitive))
return QmlLanguage;
if (fileName.endsWith(QLatin1String(".qbs"), Qt::CaseInsensitive))
return QmlQbsLanguage;
if (fileName.endsWith(QLatin1String(".js"), Qt::CaseInsensitive))
return JavaScriptLanguage;
if (fileName.endsWith(QLatin1String(".json"), Qt::CaseInsensitive))
......@@ -141,7 +158,7 @@ Document::Ptr Document::ptr() const
bool Document::isQmlDocument() const
{
return _language == QmlLanguage;
return isQmlLikeLanguage(_language);
}
Document::Language Document::language() const
......@@ -259,7 +276,7 @@ bool Document::parse_helper(int startToken)
Parser parser(_engine);
QString source = _source;
lexer.setCode(source, /*line = */ 1, /*qmlMode = */_language == QmlLanguage);
lexer.setCode(source, /*line = */ 1, /*qmlMode = */isQmlLikeLanguage(_language));
CollectDirectives collectDirectives(path());
_engine->setDirectives(&collectDirectives);
......
......@@ -51,15 +51,20 @@ public:
typedef QSharedPointer<const Document> Ptr;
typedef QSharedPointer<Document> MutablePtr;
// used in a 3-bit bitfield
enum Language
{
QmlLanguage = 0,
UnknownLanguage = 0,
JavaScriptLanguage = 1,
JsonLanguage = 2,
UnknownLanguage = 3
QmlLanguage = 3,
QmlQtQuick1Language = 4,
QmlQtQuick2Language = 5,
QmlQbsLanguage = 6,
QmlProjectLanguage = 7,
QmlTypeInfoLanguage = 8
};
static bool isQmlLikeLanguage(Language languge);
protected:
Document(const QString &fileName, Language language);
......@@ -117,8 +122,8 @@ private:
QString _source;
QWeakPointer<Document> _ptr;
int _editorRevision;
Language _language : 3;
bool _parsedCorrectly : 1;
Language _language;
bool _parsedCorrectly;
// for documentFromSource
friend class Snapshot;
......
......@@ -96,6 +96,8 @@ Protocol::ContentType Protocol::contentType(const QString &mt)
|| mt == QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE))
return Cpp;
if (mt == QLatin1String(QmlJSTools::Constants::QML_MIMETYPE)
|| mt == QLatin1String(QmlJSTools::Constants::QMLPROJECT_MIMETYPE)
|| mt == QLatin1String(QmlJSTools::Constants::QBS_MIMETYPE)
|| mt == QLatin1String(QmlJSTools::Constants::JS_MIMETYPE)
|| mt == QLatin1String(QmlJSTools::Constants::JSON_MIMETYPE))
return JavaScript;
......
......@@ -170,7 +170,7 @@ const char C_HEADER_MIMETYPE[] = "text/x-chdr";
const char CPP_SOURCE_MIMETYPE[] = "text/x-c++src";
const char CPP_HEADER_MIMETYPE[] = "text/x-c++hdr";
const char FORM_MIMETYPE[] = "application/x-designer";
const char QML_MIMETYPE[] = "application/x-qml";
const char QML_MIMETYPE[] = "application/x-qml"; // separate def also in qmljstoolsconstants.h
const char RESOURCE_MIMETYPE[] = "application/vnd.nokia.xml.qt.resource";
// Settings page
......
......@@ -796,7 +796,8 @@ FileType typeForFileName(const Core::MimeDatabase *db, const QFileInfo &file)
return ResourceType;
if (typeName == QLatin1String(Constants::FORM_MIMETYPE))
return FormType;
if (typeName == QLatin1String(Constants::QML_MIMETYPE))
if (mt.subClassesOf().contains(QLatin1String(Constants::QML_MIMETYPE))
|| typeName == QLatin1String(Constants::QML_MIMETYPE))
return QMLType;
return UnknownFileType;
}
......@@ -5,10 +5,24 @@
<sub-class-of type="text/plain"/>
<comment>QML file</comment>
<glob pattern="*.qml"/>
</mime-type>
<mime-type type="application/x-qt.qbs+qml">
<alias type="text/x-qt.qbs+qml"/>
<sub-class-of type="application/x-qml"/>
<comment>Qt Build Suite file</comment>
<glob pattern="*.qbs"/>
</mime-type>
<mime-type type="application/x-qmlproject">
<alias type="text/x-qmlproject"/>
<sub-class-of type="application/x-qml"/>
<comment>Qt Creator Qt UI project file</comment>
<glob pattern="*.qmlproject"/>
</mime-type>
<mime-type type="application/x-qt.meta-info+qml">
<alias type="text/x-qt.meta-info+qml"/>
<sub-class-of type="application/x-qml"/>
<comment>QML file</comment>
<glob pattern="*.qmltypes"/>
<glob pattern="*.qbs"/>
<glob pattern="*.qbp"/>
</mime-type>
<mime-type type="application/javascript">
<alias type="application/x-javascript"/>
......
......@@ -59,6 +59,9 @@ QmlJSEditorFactory::QmlJSEditorFactory(QObject *parent)
{
m_mimeTypes
<< QLatin1String(QmlJSTools::Constants::QML_MIMETYPE)
<< QLatin1String(QmlJSTools::Constants::QMLPROJECT_MIMETYPE)
<< QLatin1String(QmlJSTools::Constants::QBS_MIMETYPE)
<< QLatin1String(QmlJSTools::Constants::QMLTYPES_MIMETYPE)
<< QLatin1String(QmlJSTools::Constants::JS_MIMETYPE)
<< QLatin1String(QmlJSTools::Constants::JSON_MIMETYPE)
;
......
......@@ -70,27 +70,41 @@ using namespace QmlJSTools::Internal;
static QStringList environmentImportPaths();
static void mergeSuffixes(QStringList &l1, const QStringList &l2)
{
if (!l2.isEmpty())
l1 = l2;
}
QmlJS::Document::Language QmlJSTools::languageOfFile(const QString &fileName)
{
QStringList jsSuffixes(QLatin1String("js"));
QStringList qmlSuffixes(QLatin1String("qml"));
QStringList qmlProjectSuffixes(QLatin1String("qmlproject"));
QStringList jsonSuffixes(QLatin1String("json"));
QStringList qbsSuffixes(QLatin1String("qbs"));
if (Core::ICore::instance()) {
Core::MimeDatabase *db = Core::ICore::mimeDatabase();
Core::MimeType jsSourceTy = db->findByType(QLatin1String(Constants::JS_MIMETYPE));
jsSuffixes = jsSourceTy.suffixes();
mergeSuffixes(jsSuffixes, jsSourceTy.suffixes());
Core::MimeType qmlSourceTy = db->findByType(QLatin1String(Constants::QML_MIMETYPE));
qmlSuffixes = qmlSourceTy.suffixes();
mergeSuffixes(qmlSuffixes, qmlSourceTy.suffixes());
Core::MimeType qbsSourceTy = db->findByType(QLatin1String(Constants::QBS_MIMETYPE));
mergeSuffixes(qbsSuffixes, qbsSourceTy.suffixes());
Core::MimeType qmlProjectSourceTy = db->findByType(QLatin1String(Constants::QMLPROJECT_MIMETYPE));
mergeSuffixes(qbsSuffixes, qmlProjectSourceTy.suffixes());
Core::MimeType jsonSourceTy = db->findByType(QLatin1String(Constants::JSON_MIMETYPE));
jsonSuffixes = jsonSourceTy.suffixes();
mergeSuffixes(jsonSuffixes, jsonSourceTy.suffixes());
}
const QFileInfo info(fileName);
const QString fileSuffix = info.suffix();
if (jsSuffixes.contains(fileSuffix))
return QmlJS::Document::JavaScriptLanguage;
if (qmlSuffixes.contains(fileSuffix))
if (qbsSuffixes.contains(fileSuffix))
return QmlJS::Document::QmlQbsLanguage;
if (qmlSuffixes.contains(fileSuffix) || qmlProjectSuffixes.contains(fileSuffix))
return QmlJS::Document::QmlLanguage;
if (jsonSuffixes.contains(fileSuffix))
return QmlJS::Document::JsonLanguage;
......
......@@ -35,7 +35,10 @@
namespace QmlJSTools {
namespace Constants {
const char QML_MIMETYPE[] = "application/x-qml";
const char QML_MIMETYPE[] = "application/x-qml"; // separate def also in projectexplorerconstants.h
const char QBS_MIMETYPE[] = "application/x-qt.qbs+qml";
const char QMLPROJECT_MIMETYPE[] = "application/x-qmlproject";
const char QMLTYPES_MIMETYPE[] = "application/x-qt.meta-info+qml";
const char JS_MIMETYPE[] = "application/javascript";
const char JSON_MIMETYPE[] = "application/json";
......
......@@ -140,6 +140,15 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
textEditorSettings->registerMimeTypeForLanguageId(
QLatin1String(Constants::QML_MIMETYPE),
Constants::QML_JS_SETTINGS_ID);
textEditorSettings->registerMimeTypeForLanguageId(
QLatin1String(Constants::QBS_MIMETYPE),
Constants::QML_JS_SETTINGS_ID);
textEditorSettings->registerMimeTypeForLanguageId(
QLatin1String(Constants::QMLPROJECT_MIMETYPE),
Constants::QML_JS_SETTINGS_ID);
textEditorSettings->registerMimeTypeForLanguageId(
QLatin1String(Constants::QMLTYPES_MIMETYPE),
Constants::QML_JS_SETTINGS_ID);
textEditorSettings->registerMimeTypeForLanguageId(
QLatin1String(Constants::JS_MIMETYPE),
Constants::QML_JS_SETTINGS_ID);
......
......@@ -129,7 +129,7 @@ void QmlProfilerDetailsRewriter::requestDetailsForLocation(int type,
QFileInfo fileInfo(localFile);
if (!fileInfo.exists() || !fileInfo.isReadable())
return;
if (QmlJSTools::languageOfFile(localFile) != QmlJS::Document::QmlLanguage)
if (!QmlJS::Document::isQmlLikeLanguage(QmlJSTools::languageOfFile(localFile)))
return;
PendingEvent ev = {location, localFile, type};
......
......@@ -30,12 +30,14 @@
#ifndef QMLPROJECTCONSTANTS_H
#define QMLPROJECTCONSTANTS_H
#include <qmljstools/qmljstoolsconstants.h>
namespace QmlProjectManager {
namespace Constants {
const char *const PROJECTCONTEXT = "QmlProject.ProjectContext";
const char *const LANG_QML = "QML";
const char *const QMLMIMETYPE = "application/x-qmlproject";
const char *const QMLPROJECT_MIMETYPE = QmlJSTools::Constants::QMLPROJECT_MIMETYPE;
} // namespace Constants
} // namespace QmlProjectManager
......
......@@ -77,7 +77,7 @@ QString QmlProjectFile::suggestedFileName() const
QString QmlProjectFile::mimeType() const
{
return QLatin1String(Constants::QMLMIMETYPE);
return QLatin1String(Constants::QMLPROJECT_MIMETYPE);
}
bool QmlProjectFile::isModified() const
......
......@@ -47,7 +47,7 @@ Manager::Manager()
}
QString Manager::mimeType() const
{ return QLatin1String(Constants::QMLMIMETYPE); }
{ return QLatin1String(Constants::QMLPROJECT_MIMETYPE); }
ProjectExplorer::Project *Manager::openProject(const QString &fileName, QString *errorString)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment