forked from qt-creator/qt-creator
QmlJS: Add semantic highlighting.
Change-Id: If9293244075cff1a52801b50cdbb77248ecd21ea Reviewed-on: http://codereview.qt.nokia.com/3310 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
#include "qmljsautocompleter.h"
|
||||
#include "qmljscompletionassist.h"
|
||||
#include "qmljsquickfixassist.h"
|
||||
#include "qmljssemantichighlighter.h"
|
||||
|
||||
#include <qmljs/qmljsbind.h>
|
||||
#include <qmljs/qmljsevaluate.h>
|
||||
@@ -658,7 +659,8 @@ QmlJSTextEditorWidget::QmlJSTextEditorWidget(QWidget *parent) :
|
||||
m_modelManager(0),
|
||||
m_contextPane(0),
|
||||
m_updateSelectedElements(false),
|
||||
m_findReferences(new FindReferences(this))
|
||||
m_findReferences(new FindReferences(this)),
|
||||
m_semanticHighlighter(new SemanticHighlighter(this))
|
||||
{
|
||||
qRegisterMetaType<QmlJSEditor::SemanticInfo>("QmlJSEditor::SemanticInfo");
|
||||
|
||||
@@ -1218,6 +1220,8 @@ void QmlJSTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
|
||||
// only set the background, we do not want to modify foreground properties set by the syntax highlighter or the link
|
||||
m_occurrencesFormat.clearForeground();
|
||||
m_occurrenceRenameFormat.clearForeground();
|
||||
|
||||
m_semanticHighlighter->updateFontSettings(fs);
|
||||
}
|
||||
|
||||
|
||||
@@ -1544,9 +1548,6 @@ void QmlJSTextEditorWidget::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
||||
FindIdDeclarations updateIds;
|
||||
m_semanticInfo.idLocations = updateIds(doc);
|
||||
|
||||
FindDeclarations findDeclarations;
|
||||
m_semanticInfo.declarations = findDeclarations(doc->ast());
|
||||
|
||||
if (m_contextPane) {
|
||||
Node *newNode = m_semanticInfo.declaringMemberNoProperties(position());
|
||||
if (newNode) {
|
||||
@@ -1563,6 +1564,10 @@ void QmlJSTextEditorWidget::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
||||
appendExtraSelectionsForMessages(&selections, doc->diagnosticMessages(), document());
|
||||
appendExtraSelectionsForMessages(&selections, m_semanticInfo.semanticMessages, document());
|
||||
setExtraSelections(CodeWarningsSelection, selections);
|
||||
|
||||
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
||||
if (editorManager->currentEditor() == editor())
|
||||
m_semanticHighlighter->rerun(m_semanticInfo.scopeChain());
|
||||
}
|
||||
|
||||
void QmlJSTextEditorWidget::onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker)
|
||||
|
||||
@@ -70,6 +70,7 @@ namespace Internal {
|
||||
class QmlOutlineModel;
|
||||
class SemanticInfoUpdater;
|
||||
struct SemanticInfoUpdaterSource;
|
||||
class SemanticHighlighter;
|
||||
} // namespace Internal
|
||||
|
||||
struct QMLJSEDITOR_EXPORT Declaration
|
||||
@@ -132,7 +133,6 @@ public: // attributes
|
||||
QmlJS::ContextPtr context;
|
||||
QList<Range> ranges;
|
||||
QHash<QString, QList<QmlJS::AST::SourceLocation> > idLocations;
|
||||
QList<Declaration> declarations;
|
||||
|
||||
// these are in addition to the parser messages in the document
|
||||
QList<QmlJS::DiagnosticMessage> semanticMessages;
|
||||
@@ -251,6 +251,9 @@ private:
|
||||
bool m_updateSelectedElements;
|
||||
|
||||
FindReferences *m_findReferences;
|
||||
Internal::SemanticHighlighter *m_semanticHighlighter;
|
||||
|
||||
friend class Internal::SemanticHighlighter;
|
||||
};
|
||||
|
||||
} // namespace QmlJSEditor
|
||||
|
||||
@@ -36,7 +36,8 @@ HEADERS += \
|
||||
qmljsquickfixassist.h \
|
||||
qmljscompletionassist.h \
|
||||
qmljsquickfix.h \
|
||||
qmljssemanticinfoupdater.h
|
||||
qmljssemanticinfoupdater.h \
|
||||
qmljssemantichighlighter.h
|
||||
|
||||
SOURCES += \
|
||||
qmljseditor.cpp \
|
||||
@@ -66,7 +67,8 @@ SOURCES += \
|
||||
qmljsquickfixassist.cpp \
|
||||
qmljscompletionassist.cpp \
|
||||
qmljsquickfix.cpp \
|
||||
qmljssemanticinfoupdater.cpp
|
||||
qmljssemanticinfoupdater.cpp \
|
||||
qmljssemantichighlighter.cpp
|
||||
|
||||
RESOURCES += qmljseditor.qrc
|
||||
OTHER_FILES += QmlJSEditor.mimetypes.xml
|
||||
@@ -74,7 +76,3 @@ OTHER_FILES += QmlJSEditor.mimetypes.xml
|
||||
FORMS += \
|
||||
quicktoolbarsettingspage.ui \
|
||||
qmljscomponentnamedialog.ui
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
406
src/plugins/qmljseditor/qmljssemantichighlighter.cpp
Normal file
406
src/plugins/qmljseditor/qmljssemantichighlighter.cpp
Normal file
@@ -0,0 +1,406 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (info@qt.nokia.com)
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** 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, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** Other Usage
|
||||
**
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at info@qt.nokia.com.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "qmljssemantichighlighter.h"
|
||||
|
||||
#include "qmljseditor.h"
|
||||
|
||||
#include <qmljs/qmljsdocument.h>
|
||||
#include <qmljs/qmljsscopechain.h>
|
||||
#include <qmljs/qmljsscopebuilder.h>
|
||||
#include <qmljs/qmljsevaluate.h>
|
||||
#include <qmljs/qmljscontext.h>
|
||||
#include <qmljs/qmljsbind.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <texteditor/syntaxhighlighter.h>
|
||||
#include <texteditor/basetextdocument.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <texteditor/fontsettings.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QtCore/QThreadPool>
|
||||
#include <QtCore/QFutureInterface>
|
||||
#include <QtCore/QRunnable>
|
||||
|
||||
using namespace QmlJSEditor;
|
||||
using namespace QmlJSEditor::Internal;
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::AST;
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename T>
|
||||
class PriorityTask :
|
||||
public QFutureInterface<T>,
|
||||
public QRunnable
|
||||
{
|
||||
public:
|
||||
typedef QFuture<T> Future;
|
||||
|
||||
Future start(QThread::Priority priority)
|
||||
{
|
||||
this->setRunnable(this);
|
||||
this->reportStarted();
|
||||
Future future = this->future();
|
||||
QThreadPool::globalInstance()->start(this, priority);
|
||||
return future;
|
||||
}
|
||||
};
|
||||
|
||||
static bool isIdScope(const ObjectValue *scope, const QList<const QmlComponentChain *> &chain)
|
||||
{
|
||||
foreach (const QmlComponentChain *c, chain) {
|
||||
if (c->idScope() == scope)
|
||||
return true;
|
||||
if (isIdScope(scope, c->instantiatingComponents()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
class CollectStateNames : protected Visitor
|
||||
{
|
||||
QStringList m_stateNames;
|
||||
bool m_inStateType;
|
||||
ScopeChain m_scopeChain;
|
||||
const QmlObjectValue *m_statePrototype;
|
||||
|
||||
public:
|
||||
CollectStateNames(const ScopeChain &scopeChain)
|
||||
: m_scopeChain(scopeChain)
|
||||
{
|
||||
m_statePrototype = scopeChain.context()->valueOwner()->cppQmlTypes().typeByCppName(QLatin1String("QDeclarativeState"));
|
||||
}
|
||||
|
||||
QStringList operator()(Node *ast)
|
||||
{
|
||||
m_stateNames.clear();
|
||||
if (!m_statePrototype)
|
||||
return m_stateNames;
|
||||
m_inStateType = false;
|
||||
accept(ast);
|
||||
return m_stateNames;
|
||||
}
|
||||
|
||||
protected:
|
||||
void accept(Node *ast)
|
||||
{
|
||||
if (ast)
|
||||
ast->accept(this);
|
||||
}
|
||||
|
||||
bool preVisit(Node *ast)
|
||||
{
|
||||
return ast->uiObjectMemberCast()
|
||||
|| cast<UiProgram *>(ast)
|
||||
|| cast<UiObjectInitializer *>(ast)
|
||||
|| cast<UiObjectMemberList *>(ast)
|
||||
|| cast<UiArrayMemberList *>(ast);
|
||||
}
|
||||
|
||||
bool hasStatePrototype(Node *ast)
|
||||
{
|
||||
Bind *bind = m_scopeChain.document()->bind();
|
||||
const ObjectValue *v = bind->findQmlObject(ast);
|
||||
if (!v)
|
||||
return false;
|
||||
PrototypeIterator it(v, m_scopeChain.context());
|
||||
while (it.hasNext()) {
|
||||
const ObjectValue *proto = it.next();
|
||||
const QmlObjectValue *qmlProto = dynamic_cast<const QmlObjectValue *>(proto);
|
||||
if (!qmlProto)
|
||||
continue;
|
||||
if (qmlProto->metaObject() == m_statePrototype->metaObject())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool visit(UiObjectDefinition *ast)
|
||||
{
|
||||
const bool old = m_inStateType;
|
||||
m_inStateType = hasStatePrototype(ast);
|
||||
accept(ast->initializer);
|
||||
m_inStateType = old;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool visit(UiObjectBinding *ast)
|
||||
{
|
||||
const bool old = m_inStateType;
|
||||
m_inStateType = hasStatePrototype(ast);
|
||||
accept(ast->initializer);
|
||||
m_inStateType = old;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool visit(UiScriptBinding *ast)
|
||||
{
|
||||
if (!m_inStateType)
|
||||
return false;
|
||||
if (!ast->qualifiedId || ! ast->qualifiedId->name || ast->qualifiedId->next)
|
||||
return false;
|
||||
if (ast->qualifiedId->name->asString() != QLatin1String("name"))
|
||||
return false;
|
||||
|
||||
ExpressionStatement *expStmt = cast<ExpressionStatement *>(ast->statement);
|
||||
if (!expStmt)
|
||||
return false;
|
||||
StringLiteral *strLit = cast<StringLiteral *>(expStmt->expression);
|
||||
if (!strLit || !strLit->value)
|
||||
return false;
|
||||
|
||||
m_stateNames += strLit->value->asString();
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class CollectionTask :
|
||||
public PriorityTask<SemanticHighlighter::Use>,
|
||||
protected Visitor
|
||||
{
|
||||
public:
|
||||
CollectionTask(const ScopeChain &scopeChain)
|
||||
: m_scopeChain(scopeChain)
|
||||
, m_scopeBuilder(&m_scopeChain)
|
||||
{}
|
||||
|
||||
protected:
|
||||
void accept(Node *ast)
|
||||
{
|
||||
if (ast)
|
||||
ast->accept(this);
|
||||
}
|
||||
|
||||
void scopedAccept(Node *ast, Node *child)
|
||||
{
|
||||
m_scopeBuilder.push(ast);
|
||||
accept(child);
|
||||
m_scopeBuilder.pop();
|
||||
}
|
||||
|
||||
void processName(NameId *name, SourceLocation location)
|
||||
{
|
||||
if (!name)
|
||||
return;
|
||||
|
||||
const QString nameStr = name->asString();
|
||||
const ObjectValue *scope = 0;
|
||||
const Value *value = m_scopeChain.lookup(nameStr, &scope);
|
||||
if (!value || !scope)
|
||||
return;
|
||||
|
||||
SemanticHighlighter::Use use = SemanticHighlighter::makeUse(location);
|
||||
if (QSharedPointer<const QmlComponentChain> chain = m_scopeChain.qmlComponentChain()) {
|
||||
if (scope == chain->idScope()) {
|
||||
use.kind = SemanticHighlighter::LocalIdType;
|
||||
} else if (isIdScope(scope, chain->instantiatingComponents())) {
|
||||
use.kind = SemanticHighlighter::ExternalIdType;
|
||||
} else if (scope == chain->rootObjectScope()) {
|
||||
use.kind = SemanticHighlighter::RootObjectPropertyType;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_scopeChain.qmlTypes() == scope) {
|
||||
use.kind = SemanticHighlighter::QmlTypeType;
|
||||
} else if (m_scopeChain.qmlScopeObjects().contains(scope)) {
|
||||
use.kind = SemanticHighlighter::ScopeObjectPropertyType;
|
||||
} else if (m_scopeChain.jsScopes().contains(scope)) {
|
||||
use.kind = SemanticHighlighter::JsScopeType;
|
||||
} else if (m_scopeChain.jsImports() == scope) {
|
||||
use.kind = SemanticHighlighter::JsImportType;
|
||||
} else if (m_scopeChain.globalScope() == scope) {
|
||||
use.kind = SemanticHighlighter::JsGlobalType;
|
||||
}
|
||||
|
||||
// eliminated other possibilities, should potentially be a real check if this yields false-positives
|
||||
if (use.kind == SemanticHighlighter::UnknownType) {
|
||||
use.kind = SemanticHighlighter::ExternalObjectPropertyType;
|
||||
}
|
||||
|
||||
reportResult(use);
|
||||
}
|
||||
|
||||
bool visit(UiObjectDefinition *ast)
|
||||
{
|
||||
scopedAccept(ast, ast->initializer);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool visit(UiObjectBinding *ast)
|
||||
{
|
||||
scopedAccept(ast, ast->initializer);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool visit(UiScriptBinding *ast)
|
||||
{
|
||||
scopedAccept(ast, ast->statement);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool visit(UiPublicMember *ast)
|
||||
{
|
||||
scopedAccept(ast, ast->statement);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool visit(FunctionExpression *ast)
|
||||
{
|
||||
processName(ast->name, ast->identifierToken);
|
||||
scopedAccept(ast, ast->body);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool visit(FunctionDeclaration *ast)
|
||||
{
|
||||
return visit(static_cast<FunctionExpression *>(ast));
|
||||
}
|
||||
|
||||
bool visit(VariableDeclaration *ast)
|
||||
{
|
||||
processName(ast->name, ast->identifierToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool visit(IdentifierExpression *ast)
|
||||
{
|
||||
processName(ast->name, ast->identifierToken);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool visit(StringLiteral *ast)
|
||||
{
|
||||
if (!ast->value)
|
||||
return false;
|
||||
|
||||
const QString value = ast->value->asString();
|
||||
if (m_stateNames.contains(value)) {
|
||||
SemanticHighlighter::Use use = SemanticHighlighter::makeUse(
|
||||
ast->literalToken, SemanticHighlighter::LocalStateNameType);
|
||||
reportResult(use);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
void run()
|
||||
{
|
||||
Node *root = m_scopeChain.document()->ast();
|
||||
m_stateNames = CollectStateNames(m_scopeChain)(root);
|
||||
accept(root);
|
||||
reportFinished();
|
||||
}
|
||||
|
||||
ScopeChain m_scopeChain;
|
||||
ScopeBuilder m_scopeBuilder;
|
||||
QStringList m_stateNames;
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
SemanticHighlighter::SemanticHighlighter(QmlJSTextEditorWidget *editor)
|
||||
: QObject(editor)
|
||||
, m_editor(editor)
|
||||
, m_startRevision(0)
|
||||
{
|
||||
connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)),
|
||||
this, SLOT(applyResults(int,int)));
|
||||
connect(&m_watcher, SIGNAL(finished()),
|
||||
this, SLOT(finished()));
|
||||
}
|
||||
|
||||
void SemanticHighlighter::rerun(const ScopeChain &scopeChain)
|
||||
{
|
||||
m_watcher.cancel();
|
||||
|
||||
// this does not simply use QtConcurrentRun because we want a low-priority future
|
||||
// the thread pool deletes the task when it is done
|
||||
CollectionTask::Future f = (new CollectionTask(scopeChain))->start(QThread::LowestPriority);
|
||||
m_startRevision = m_editor->editorRevision();
|
||||
m_watcher.setFuture(f);
|
||||
}
|
||||
|
||||
void SemanticHighlighter::applyResults(int from, int to)
|
||||
{
|
||||
if (m_watcher.isCanceled())
|
||||
return;
|
||||
if (m_startRevision != m_editor->editorRevision())
|
||||
return;
|
||||
|
||||
TextEditor::BaseTextDocument *baseTextDocument = m_editor->baseTextDocument();
|
||||
QTC_ASSERT(baseTextDocument, return);
|
||||
TextEditor::SyntaxHighlighter *highlighter = qobject_cast<TextEditor::SyntaxHighlighter *>(baseTextDocument->syntaxHighlighter());
|
||||
QTC_ASSERT(highlighter, return);
|
||||
|
||||
TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats(
|
||||
highlighter, m_watcher.future(), from, to, m_formats);
|
||||
}
|
||||
|
||||
void SemanticHighlighter::finished()
|
||||
{
|
||||
if (m_watcher.isCanceled())
|
||||
return;
|
||||
if (m_startRevision != m_editor->editorRevision())
|
||||
return;
|
||||
|
||||
TextEditor::BaseTextDocument *baseTextDocument = m_editor->baseTextDocument();
|
||||
QTC_ASSERT(baseTextDocument, return);
|
||||
TextEditor::SyntaxHighlighter *highlighter = qobject_cast<TextEditor::SyntaxHighlighter *>(baseTextDocument->syntaxHighlighter());
|
||||
QTC_ASSERT(highlighter, return);
|
||||
|
||||
TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd(
|
||||
highlighter, m_watcher.future());
|
||||
}
|
||||
|
||||
SemanticHighlighter::Use SemanticHighlighter::makeUse(const SourceLocation &location, SemanticHighlighter::UseType type)
|
||||
{
|
||||
return Use(location.startLine, location.startColumn, location.length, type);
|
||||
}
|
||||
|
||||
void SemanticHighlighter::updateFontSettings(const TextEditor::FontSettings &fontSettings)
|
||||
{
|
||||
m_formats[LocalIdType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_LOCAL_ID));
|
||||
m_formats[ExternalIdType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_EXTERNAL_ID));
|
||||
m_formats[QmlTypeType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_TYPE_ID));
|
||||
m_formats[RootObjectPropertyType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_ROOT_OBJECT_PROPERTY));
|
||||
m_formats[ScopeObjectPropertyType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_SCOPE_OBJECT_PROPERTY));
|
||||
m_formats[ExternalObjectPropertyType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_EXTERNAL_OBJECT_PROPERTY));
|
||||
m_formats[JsScopeType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_JS_SCOPE_VAR));
|
||||
m_formats[JsImportType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_JS_IMPORT_VAR));
|
||||
m_formats[JsGlobalType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_JS_GLOBAL_VAR));
|
||||
m_formats[LocalStateNameType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_STATE_NAME));
|
||||
}
|
||||
|
||||
98
src/plugins/qmljseditor/qmljssemantichighlighter.h
Normal file
98
src/plugins/qmljseditor/qmljssemantichighlighter.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (info@qt.nokia.com)
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** 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, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** Other Usage
|
||||
**
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at info@qt.nokia.com.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef QMLJSSEMANTICHIGHLIGHTER_H
|
||||
#define QMLJSSEMANTICHIGHLIGHTER_H
|
||||
|
||||
#include <texteditor/semantichighlighter.h>
|
||||
#include <QtCore/QFutureWatcher>
|
||||
|
||||
namespace QmlJS {
|
||||
class ScopeChain;
|
||||
namespace AST {
|
||||
class SourceLocation;
|
||||
}
|
||||
}
|
||||
|
||||
namespace TextEditor {
|
||||
class FontSettings;
|
||||
}
|
||||
|
||||
namespace QmlJSEditor {
|
||||
|
||||
class QmlJSTextEditorWidget;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class SemanticHighlighter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum UseType
|
||||
{
|
||||
UnknownType,
|
||||
LocalIdType, // ids in the same file
|
||||
ExternalIdType, // ids from instantiating files
|
||||
QmlTypeType, // qml types
|
||||
RootObjectPropertyType, // property in root object
|
||||
ScopeObjectPropertyType, // property in scope object
|
||||
ExternalObjectPropertyType, // property in root object of instantiating file
|
||||
JsScopeType, // var or function in local js scope
|
||||
JsImportType, // name of js import
|
||||
JsGlobalType, // in global scope
|
||||
LocalStateNameType // name of a state in the current file
|
||||
};
|
||||
|
||||
typedef TextEditor::SemanticHighlighter::Result Use;
|
||||
static Use makeUse(const QmlJS::AST::SourceLocation &location, UseType type = UnknownType);
|
||||
|
||||
SemanticHighlighter(QmlJSTextEditorWidget *editor);
|
||||
|
||||
void rerun(const QmlJS::ScopeChain &scopeChain);
|
||||
|
||||
void updateFontSettings(const TextEditor::FontSettings &fontSettings);
|
||||
|
||||
private slots:
|
||||
void applyResults(int from, int to);
|
||||
void finished();
|
||||
|
||||
private:
|
||||
QFutureWatcher<Use> m_watcher;
|
||||
QmlJSTextEditorWidget *m_editor;
|
||||
int m_startRevision;
|
||||
QHash<int, QTextCharFormat> m_formats;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlJSEditor
|
||||
|
||||
#endif // QMLJSSEMANTICHIGHLIGHTER_H
|
||||
Reference in New Issue
Block a user