forked from qt-creator/qt-creator
QmlJS semantic highlighter: Use document instead of widget
Diagnostic ranges also move to document for this. Change-Id: I82a9909abb57594cdd732448270849e6a2e3a4e0 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
This commit is contained in:
@@ -119,7 +119,7 @@ void QmlJSTextEditorWidget::ctor()
|
|||||||
m_outlineModel = new QmlOutlineModel(this);
|
m_outlineModel = new QmlOutlineModel(this);
|
||||||
m_contextPane = 0;
|
m_contextPane = 0;
|
||||||
m_findReferences = new FindReferences(this);
|
m_findReferences = new FindReferences(this);
|
||||||
m_semanticHighlighter = new SemanticHighlighter(this);
|
m_semanticHighlighter = new SemanticHighlighter(m_qmlJsEditorDocument);
|
||||||
|
|
||||||
setParenthesesMatchingEnabled(true);
|
setParenthesesMatchingEnabled(true);
|
||||||
setMarksVisible(true);
|
setMarksVisible(true);
|
||||||
@@ -189,11 +189,7 @@ int QmlJSTextEditorWidget::editorRevision() const
|
|||||||
|
|
||||||
QVector<QTextLayout::FormatRange> QmlJSTextEditorWidget::diagnosticRanges() const
|
QVector<QTextLayout::FormatRange> QmlJSTextEditorWidget::diagnosticRanges() const
|
||||||
{
|
{
|
||||||
// this exist mainly because getting the tooltip from the additional formats
|
return m_qmlJsEditorDocument->diagnosticRanges();
|
||||||
// requires the use of private api (you have to extract it from
|
|
||||||
// cursor.block().layout()->specialInfo.addFormatIndex (for the .format through .formats.at()),
|
|
||||||
// and use .addFormat to get the range). So a separate bookkeeping is used.
|
|
||||||
return m_diagnosticRanges;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlJSTextEditorWidget::isSemanticInfoOutdated() const
|
bool QmlJSTextEditorWidget::isSemanticInfoOutdated() const
|
||||||
|
|||||||
@@ -108,7 +108,6 @@ public:
|
|||||||
QmlJSTools::SemanticInfo semanticInfo() const;
|
QmlJSTools::SemanticInfo semanticInfo() const;
|
||||||
bool isSemanticInfoOutdated() const;
|
bool isSemanticInfoOutdated() const;
|
||||||
int editorRevision() const;
|
int editorRevision() const;
|
||||||
|
|
||||||
QVector<QTextLayout::FormatRange> diagnosticRanges() const;
|
QVector<QTextLayout::FormatRange> diagnosticRanges() const;
|
||||||
|
|
||||||
Internal::QmlOutlineModel *outlineModel() const;
|
Internal::QmlOutlineModel *outlineModel() const;
|
||||||
@@ -183,15 +182,12 @@ private:
|
|||||||
QmlJS::ModelManagerInterface *m_modelManager;
|
QmlJS::ModelManagerInterface *m_modelManager;
|
||||||
|
|
||||||
QList<TextEditor::QuickFixOperation::Ptr> m_quickFixes;
|
QList<TextEditor::QuickFixOperation::Ptr> m_quickFixes;
|
||||||
QVector<QTextLayout::FormatRange> m_diagnosticRanges;
|
|
||||||
|
|
||||||
QmlJS::IContextPane *m_contextPane;
|
QmlJS::IContextPane *m_contextPane;
|
||||||
int m_oldCursorPosition;
|
int m_oldCursorPosition;
|
||||||
|
|
||||||
FindReferences *m_findReferences;
|
FindReferences *m_findReferences;
|
||||||
Internal::SemanticHighlighter *m_semanticHighlighter;
|
Internal::SemanticHighlighter *m_semanticHighlighter;
|
||||||
|
|
||||||
friend class Internal::SemanticHighlighter;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlJSEditor
|
} // namespace QmlJSEditor
|
||||||
|
|||||||
@@ -514,5 +514,15 @@ bool QmlJSEditorDocument::isSemanticInfoOutdated() const
|
|||||||
return m_d->m_semanticInfo.revision() != document()->revision();
|
return m_d->m_semanticInfo.revision() != document()->revision();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<QTextLayout::FormatRange> QmlJSEditorDocument::diagnosticRanges() const
|
||||||
|
{
|
||||||
|
return m_d->m_diagnosticRanges;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlJSEditorDocument::setDiagnosticRanges(const QVector<QTextLayout::FormatRange> &ranges)
|
||||||
|
{
|
||||||
|
m_d->m_diagnosticRanges = ranges;
|
||||||
|
}
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
} // QmlJSEditor
|
} // QmlJSEditor
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
#include <qmljstools/qmljssemanticinfo.h>
|
#include <qmljstools/qmljssemanticinfo.h>
|
||||||
#include <texteditor/basetextdocument.h>
|
#include <texteditor/basetextdocument.h>
|
||||||
|
|
||||||
|
#include <QTextLayout>
|
||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -48,6 +50,8 @@ public:
|
|||||||
|
|
||||||
const QmlJSTools::SemanticInfo &semanticInfo() const;
|
const QmlJSTools::SemanticInfo &semanticInfo() const;
|
||||||
bool isSemanticInfoOutdated() const;
|
bool isSemanticInfoOutdated() const;
|
||||||
|
QVector<QTextLayout::FormatRange> diagnosticRanges() const;
|
||||||
|
void setDiagnosticRanges(const QVector<QTextLayout::FormatRange> &ranges);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void updateCodeWarnings(QmlJS::Document::Ptr doc);
|
void updateCodeWarnings(QmlJS::Document::Ptr doc);
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include <qmljstools/qmljssemanticinfo.h>
|
#include <qmljstools/qmljssemanticinfo.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QTextLayout>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
@@ -64,6 +65,7 @@ public:
|
|||||||
int m_semanticInfoDocRevision; // document revision to which the semantic info is currently updated to
|
int m_semanticInfoDocRevision; // document revision to which the semantic info is currently updated to
|
||||||
SemanticInfoUpdater *m_semanticInfoUpdater;
|
SemanticInfoUpdater *m_semanticInfoUpdater;
|
||||||
QmlJSTools::SemanticInfo m_semanticInfo;
|
QmlJSTools::SemanticInfo m_semanticInfo;
|
||||||
|
QVector<QTextLayout::FormatRange> m_diagnosticRanges;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#include "qmljssemantichighlighter.h"
|
#include "qmljssemantichighlighter.h"
|
||||||
|
|
||||||
#include "qmljseditor.h"
|
#include "qmljseditordocument.h"
|
||||||
|
|
||||||
#include <qmljs/qmljsdocument.h>
|
#include <qmljs/qmljsdocument.h>
|
||||||
#include <qmljs/qmljsscopechain.h>
|
#include <qmljs/qmljsscopechain.h>
|
||||||
@@ -47,9 +47,10 @@
|
|||||||
#include <texteditor/fontsettings.h>
|
#include <texteditor/fontsettings.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QThreadPool>
|
|
||||||
#include <QFutureInterface>
|
#include <QFutureInterface>
|
||||||
#include <QRunnable>
|
#include <QRunnable>
|
||||||
|
#include <QTextDocument>
|
||||||
|
#include <QThreadPool>
|
||||||
|
|
||||||
using namespace QmlJS;
|
using namespace QmlJS;
|
||||||
using namespace QmlJS::AST;
|
using namespace QmlJS::AST;
|
||||||
@@ -534,9 +535,9 @@ private:
|
|||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
SemanticHighlighter::SemanticHighlighter(QmlJSTextEditorWidget *editor)
|
SemanticHighlighter::SemanticHighlighter(QmlJSEditorDocument *document)
|
||||||
: QObject(editor)
|
: QObject(document)
|
||||||
, m_editor(editor)
|
, m_document(document)
|
||||||
, m_startRevision(0)
|
, m_startRevision(0)
|
||||||
{
|
{
|
||||||
connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)),
|
connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)),
|
||||||
@@ -552,7 +553,7 @@ void SemanticHighlighter::rerun(const QmlJSTools::SemanticInfo &semanticInfo)
|
|||||||
// this does not simply use QtConcurrentRun because we want a low-priority future
|
// this does not simply use QtConcurrentRun because we want a low-priority future
|
||||||
// the thread pool deletes the task when it is done
|
// the thread pool deletes the task when it is done
|
||||||
CollectionTask::Future f = (new CollectionTask(semanticInfo, *this))->start(QThread::LowestPriority);
|
CollectionTask::Future f = (new CollectionTask(semanticInfo, *this))->start(QThread::LowestPriority);
|
||||||
m_startRevision = m_editor->editorRevision();
|
m_startRevision = m_document->document()->revision();
|
||||||
m_watcher.setFuture(f);
|
m_watcher.setFuture(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -565,33 +566,24 @@ void SemanticHighlighter::applyResults(int from, int to)
|
|||||||
{
|
{
|
||||||
if (m_watcher.isCanceled())
|
if (m_watcher.isCanceled())
|
||||||
return;
|
return;
|
||||||
if (m_startRevision != m_editor->editorRevision())
|
if (m_startRevision != m_document->document()->revision())
|
||||||
return;
|
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(
|
TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats(
|
||||||
highlighter, m_watcher.future(), from, to, m_extraFormats);
|
m_document->syntaxHighlighter(), m_watcher.future(), from, to, m_extraFormats);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SemanticHighlighter::finished()
|
void SemanticHighlighter::finished()
|
||||||
{
|
{
|
||||||
if (m_watcher.isCanceled())
|
if (m_watcher.isCanceled())
|
||||||
return;
|
return;
|
||||||
if (m_startRevision != m_editor->editorRevision())
|
if (m_startRevision != m_document->document()->revision())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TextEditor::BaseTextDocument *baseTextDocument = m_editor->baseTextDocument();
|
m_document->setDiagnosticRanges(m_diagnosticRanges);
|
||||||
QTC_ASSERT(baseTextDocument, return);
|
|
||||||
TextEditor::SyntaxHighlighter *highlighter = qobject_cast<TextEditor::SyntaxHighlighter *>(baseTextDocument->syntaxHighlighter());
|
|
||||||
QTC_ASSERT(highlighter, return);
|
|
||||||
m_editor->m_diagnosticRanges = m_diagnosticRanges;
|
|
||||||
|
|
||||||
TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd(
|
TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd(
|
||||||
highlighter, m_watcher.future());
|
m_document->syntaxHighlighter(), m_watcher.future());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SemanticHighlighter::updateFontSettings(const TextEditor::FontSettings &fontSettings)
|
void SemanticHighlighter::updateFontSettings(const TextEditor::FontSettings &fontSettings)
|
||||||
|
|||||||
@@ -52,10 +52,10 @@ class SemanticInfo;
|
|||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
|
|
||||||
class QmlJSTextEditorWidget;
|
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
class QmlJSEditorDocument;
|
||||||
|
|
||||||
class SemanticHighlighter : public QObject
|
class SemanticHighlighter : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -80,7 +80,7 @@ public:
|
|||||||
|
|
||||||
typedef TextEditor::HighlightingResult Use;
|
typedef TextEditor::HighlightingResult Use;
|
||||||
|
|
||||||
SemanticHighlighter(QmlJSTextEditorWidget *editor);
|
SemanticHighlighter(QmlJSEditorDocument *document);
|
||||||
|
|
||||||
void rerun(const QmlJSTools::SemanticInfo &scopeChain);
|
void rerun(const QmlJSTools::SemanticInfo &scopeChain);
|
||||||
void cancel();
|
void cancel();
|
||||||
@@ -97,7 +97,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QFutureWatcher<Use> m_watcher;
|
QFutureWatcher<Use> m_watcher;
|
||||||
QmlJSTextEditorWidget *m_editor;
|
QmlJSEditorDocument *m_document;
|
||||||
int m_startRevision;
|
int m_startRevision;
|
||||||
QHash<int, QTextCharFormat> m_formats;
|
QHash<int, QTextCharFormat> m_formats;
|
||||||
QHash<int, QTextCharFormat> m_extraFormats;
|
QHash<int, QTextCharFormat> m_extraFormats;
|
||||||
|
|||||||
Reference in New Issue
Block a user