forked from qt-creator/qt-creator
Changed the QML/JS editor to treat .qs/.js files as JavaScript, and invoke the appropriate parser for it.
Reviewed-by: Christian Kamm
This commit is contained in:
committed by
Tim Jenssen
parent
2dfe4f620c
commit
0f8126f62d
@@ -95,12 +95,12 @@ int QmlCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
||||
if (qmlDocument.isNull())
|
||||
return pos;
|
||||
|
||||
if (!qmlDocument->program())
|
||||
if (!qmlDocument->qmlProgram())
|
||||
qmlDocument = m_modelManager->snapshot().value(qmlDocument->fileName());
|
||||
|
||||
// FIXME: this completion strategy is not going to work when the document was never parsed correctly.
|
||||
if (qmlDocument && qmlDocument->program()) {
|
||||
QmlJS::AST::UiProgram *program = qmlDocument->program();
|
||||
if (qmlDocument && qmlDocument->qmlProgram()) {
|
||||
QmlJS::AST::UiProgram *program = qmlDocument->qmlProgram();
|
||||
// qDebug() << "*** program:" << program;
|
||||
|
||||
if (program) {
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace QmlJSEditor {
|
||||
_pos = pos;
|
||||
_scopes.clear();
|
||||
_currentSymbol = 0;
|
||||
Node::accept(doc->program(), this);
|
||||
Node::accept(doc->qmlProgram(), this);
|
||||
return _scopes;
|
||||
}
|
||||
|
||||
|
||||
@@ -425,11 +425,11 @@ void QmlJSTextEditor::onDocumentUpdated(Qml::QmlDocument::Ptr doc)
|
||||
|
||||
FindIdDeclarations updateIds;
|
||||
m_idsRevision = document()->revision();
|
||||
m_ids = updateIds(doc->program());
|
||||
m_ids = updateIds(doc->qmlProgram());
|
||||
|
||||
if (doc->isParsedCorrectly()) {
|
||||
FindDeclarations findDeclarations;
|
||||
m_declarations = findDeclarations(doc->program());
|
||||
m_declarations = findDeclarations(doc->qmlProgram());
|
||||
|
||||
QStringList items;
|
||||
items.append(tr("<Select Symbol>"));
|
||||
|
||||
@@ -137,7 +137,7 @@ QmlSymbol *QmlLookupContext::resolveType(const QString &name, const QString &fil
|
||||
if (document.isNull())
|
||||
return 0;
|
||||
|
||||
UiProgram *prog = document->program();
|
||||
UiProgram *prog = document->qmlProgram();
|
||||
if (!prog)
|
||||
return 0;
|
||||
|
||||
@@ -252,7 +252,7 @@ QList<QmlSymbol*> QmlLookupContext::visibleTypes()
|
||||
{
|
||||
QList<QmlSymbol*> result;
|
||||
|
||||
UiProgram *program = _doc->program();
|
||||
UiProgram *program = _doc->qmlProgram();
|
||||
if (!program)
|
||||
return result;
|
||||
|
||||
|
||||
@@ -27,21 +27,20 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include <QFile>
|
||||
#include <QtConcurrentRun>
|
||||
#include <qtconcurrent/runextensions.h>
|
||||
#include <QTextStream>
|
||||
#include "qmljseditorconstants.h"
|
||||
#include "qmlmodelmanager.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
#include <texteditor/itexteditor.h>
|
||||
|
||||
#include "qmljseditorconstants.h"
|
||||
#include "qmlmodelmanager.h"
|
||||
|
||||
#include <QtCore/QMetaType>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QtConcurrentRun>
|
||||
#include <qtconcurrent/runextensions.h>
|
||||
#include <QTextStream>
|
||||
|
||||
using namespace QmlJSEditor;
|
||||
using namespace QmlJSEditor::Internal;
|
||||
@@ -156,7 +155,21 @@ void QmlModelManager::parse(QFutureInterface<void> &future,
|
||||
|
||||
Qml::QmlDocument::Ptr doc = Qml::QmlDocument::create(fileName);
|
||||
doc->setSource(contents);
|
||||
doc->parse();
|
||||
|
||||
{
|
||||
Core::MimeDatabase *db = Core::ICore::instance()->mimeDatabase();
|
||||
Core::MimeType jsSourceTy = db->findByType(QLatin1String("application/javascript"));
|
||||
Core::MimeType qmlSourceTy = db->findByType(QLatin1String("application/x-qml"));
|
||||
|
||||
const QFileInfo fileInfo(fileName);
|
||||
|
||||
if (jsSourceTy.matchesFile(fileInfo))
|
||||
doc->parseJavaScript();
|
||||
else if (qmlSourceTy.matchesFile(fileInfo))
|
||||
doc->parseQml();
|
||||
else
|
||||
qWarning() << "Don't know how to treat" << fileName;
|
||||
}
|
||||
|
||||
modelManager->emitDocumentUpdated(doc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user