Commit d653d600 authored by Eike Ziller's avatar Eike Ziller

QmlJS semantic highlighter: Use document instead of widget

Diagnostic ranges also move to document for this.

Change-Id: I82a9909abb57594cdd732448270849e6a2e3a4e0
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent f1606a9f
......@@ -119,7 +119,7 @@ void QmlJSTextEditorWidget::ctor()
m_outlineModel = new QmlOutlineModel(this);
m_contextPane = 0;
m_findReferences = new FindReferences(this);
m_semanticHighlighter = new SemanticHighlighter(this);
m_semanticHighlighter = new SemanticHighlighter(m_qmlJsEditorDocument);
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
......@@ -189,11 +189,7 @@ int QmlJSTextEditorWidget::editorRevision() const
QVector<QTextLayout::FormatRange> QmlJSTextEditorWidget::diagnosticRanges() const
{
// this exist mainly because getting the tooltip from the additional formats
// 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;
return m_qmlJsEditorDocument->diagnosticRanges();
}
bool QmlJSTextEditorWidget::isSemanticInfoOutdated() const
......
......@@ -108,7 +108,6 @@ public:
QmlJSTools::SemanticInfo semanticInfo() const;
bool isSemanticInfoOutdated() const;
int editorRevision() const;
QVector<QTextLayout::FormatRange> diagnosticRanges() const;
Internal::QmlOutlineModel *outlineModel() const;
......@@ -183,15 +182,12 @@ private:
QmlJS::ModelManagerInterface *m_modelManager;
QList<TextEditor::QuickFixOperation::Ptr> m_quickFixes;
QVector<QTextLayout::FormatRange> m_diagnosticRanges;
QmlJS::IContextPane *m_contextPane;
int m_oldCursorPosition;
FindReferences *m_findReferences;
Internal::SemanticHighlighter *m_semanticHighlighter;
friend class Internal::SemanticHighlighter;
};
} // namespace QmlJSEditor
......
......@@ -514,5 +514,15 @@ bool QmlJSEditorDocument::isSemanticInfoOutdated() const
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
} // QmlJSEditor
......@@ -34,6 +34,8 @@
#include <qmljstools/qmljssemanticinfo.h>
#include <texteditor/basetextdocument.h>
#include <QTextLayout>
namespace QmlJSEditor {
namespace Internal {
......@@ -48,6 +50,8 @@ public:
const QmlJSTools::SemanticInfo &semanticInfo() const;
bool isSemanticInfoOutdated() const;
QVector<QTextLayout::FormatRange> diagnosticRanges() const;
void setDiagnosticRanges(const QVector<QTextLayout::FormatRange> &ranges);
signals:
void updateCodeWarnings(QmlJS::Document::Ptr doc);
......
......@@ -34,6 +34,7 @@
#include <qmljstools/qmljssemanticinfo.h>
#include <QObject>
#include <QTextLayout>
#include <QTimer>
namespace QmlJSEditor {
......@@ -64,6 +65,7 @@ public:
int m_semanticInfoDocRevision; // document revision to which the semantic info is currently updated to
SemanticInfoUpdater *m_semanticInfoUpdater;
QmlJSTools::SemanticInfo m_semanticInfo;
QVector<QTextLayout::FormatRange> m_diagnosticRanges;
};
} // Internal
......
......@@ -29,7 +29,7 @@
#include "qmljssemantichighlighter.h"
#include "qmljseditor.h"
#include "qmljseditordocument.h"
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljsscopechain.h>
......@@ -47,9 +47,10 @@
#include <texteditor/fontsettings.h>
#include <utils/qtcassert.h>
#include <QThreadPool>
#include <QFutureInterface>
#include <QRunnable>
#include <QTextDocument>
#include <QThreadPool>
using namespace QmlJS;
using namespace QmlJS::AST;
......@@ -534,9 +535,9 @@ private:
} // anonymous namespace
SemanticHighlighter::SemanticHighlighter(QmlJSTextEditorWidget *editor)
: QObject(editor)
, m_editor(editor)
SemanticHighlighter::SemanticHighlighter(QmlJSEditorDocument *document)
: QObject(document)
, m_document(document)
, m_startRevision(0)
{
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
// the thread pool deletes the task when it is done
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);
}
......@@ -565,33 +566,24 @@ void SemanticHighlighter::applyResults(int from, int to)
{
if (m_watcher.isCanceled())
return;
if (m_startRevision != m_editor->editorRevision())
if (m_startRevision != m_document->document()->revision())
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_extraFormats);
m_document->syntaxHighlighter(), m_watcher.future(), from, to, m_extraFormats);
}
void SemanticHighlighter::finished()
{
if (m_watcher.isCanceled())
return;
if (m_startRevision != m_editor->editorRevision())
if (m_startRevision != m_document->document()->revision())
return;
TextEditor::BaseTextDocument *baseTextDocument = m_editor->baseTextDocument();
QTC_ASSERT(baseTextDocument, return);
TextEditor::SyntaxHighlighter *highlighter = qobject_cast<TextEditor::SyntaxHighlighter *>(baseTextDocument->syntaxHighlighter());
QTC_ASSERT(highlighter, return);
m_editor->m_diagnosticRanges = m_diagnosticRanges;
m_document->setDiagnosticRanges(m_diagnosticRanges);
TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd(
highlighter, m_watcher.future());
m_document->syntaxHighlighter(), m_watcher.future());
}
void SemanticHighlighter::updateFontSettings(const TextEditor::FontSettings &fontSettings)
......
......@@ -52,10 +52,10 @@ class SemanticInfo;
namespace QmlJSEditor {
class QmlJSTextEditorWidget;
namespace Internal {
class QmlJSEditorDocument;
class SemanticHighlighter : public QObject
{
Q_OBJECT
......@@ -80,7 +80,7 @@ public:
typedef TextEditor::HighlightingResult Use;
SemanticHighlighter(QmlJSTextEditorWidget *editor);
SemanticHighlighter(QmlJSEditorDocument *document);
void rerun(const QmlJSTools::SemanticInfo &scopeChain);
void cancel();
......@@ -97,7 +97,7 @@ private slots:
private:
QFutureWatcher<Use> m_watcher;
QmlJSTextEditorWidget *m_editor;
QmlJSEditorDocument *m_document;
int m_startRevision;
QHash<int, QTextCharFormat> m_formats;
QHash<int, QTextCharFormat> m_extraFormats;
......
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