diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 1e665fddda7..0b6c30d5411 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -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 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 diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index b75f7421371..273580d203f 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -108,7 +108,6 @@ public: QmlJSTools::SemanticInfo semanticInfo() const; bool isSemanticInfoOutdated() const; int editorRevision() const; - QVector diagnosticRanges() const; Internal::QmlOutlineModel *outlineModel() const; @@ -183,15 +182,12 @@ private: QmlJS::ModelManagerInterface *m_modelManager; QList m_quickFixes; - QVector m_diagnosticRanges; QmlJS::IContextPane *m_contextPane; int m_oldCursorPosition; FindReferences *m_findReferences; Internal::SemanticHighlighter *m_semanticHighlighter; - - friend class Internal::SemanticHighlighter; }; } // namespace QmlJSEditor diff --git a/src/plugins/qmljseditor/qmljseditordocument.cpp b/src/plugins/qmljseditor/qmljseditordocument.cpp index 4fae802c09a..443659f1994 100644 --- a/src/plugins/qmljseditor/qmljseditordocument.cpp +++ b/src/plugins/qmljseditor/qmljseditordocument.cpp @@ -514,5 +514,15 @@ bool QmlJSEditorDocument::isSemanticInfoOutdated() const return m_d->m_semanticInfo.revision() != document()->revision(); } +QVector QmlJSEditorDocument::diagnosticRanges() const +{ + return m_d->m_diagnosticRanges; +} + +void QmlJSEditorDocument::setDiagnosticRanges(const QVector &ranges) +{ + m_d->m_diagnosticRanges = ranges; +} + } // Internal } // QmlJSEditor diff --git a/src/plugins/qmljseditor/qmljseditordocument.h b/src/plugins/qmljseditor/qmljseditordocument.h index d43797ab5e9..cbd86f0d233 100644 --- a/src/plugins/qmljseditor/qmljseditordocument.h +++ b/src/plugins/qmljseditor/qmljseditordocument.h @@ -34,6 +34,8 @@ #include #include +#include + namespace QmlJSEditor { namespace Internal { @@ -48,6 +50,8 @@ public: const QmlJSTools::SemanticInfo &semanticInfo() const; bool isSemanticInfoOutdated() const; + QVector diagnosticRanges() const; + void setDiagnosticRanges(const QVector &ranges); signals: void updateCodeWarnings(QmlJS::Document::Ptr doc); diff --git a/src/plugins/qmljseditor/qmljseditordocument_p.h b/src/plugins/qmljseditor/qmljseditordocument_p.h index 330ad9d2785..f96565b44ca 100644 --- a/src/plugins/qmljseditor/qmljseditordocument_p.h +++ b/src/plugins/qmljseditor/qmljseditordocument_p.h @@ -34,6 +34,7 @@ #include #include +#include #include 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 m_diagnosticRanges; }; } // Internal diff --git a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp index 439f186629e..976857b05bb 100644 --- a/src/plugins/qmljseditor/qmljssemantichighlighter.cpp +++ b/src/plugins/qmljseditor/qmljssemantichighlighter.cpp @@ -29,7 +29,7 @@ #include "qmljssemantichighlighter.h" -#include "qmljseditor.h" +#include "qmljseditordocument.h" #include #include @@ -47,9 +47,10 @@ #include #include -#include #include #include +#include +#include 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(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(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) diff --git a/src/plugins/qmljseditor/qmljssemantichighlighter.h b/src/plugins/qmljseditor/qmljssemantichighlighter.h index e9cdfa20501..d871403f935 100644 --- a/src/plugins/qmljseditor/qmljssemantichighlighter.h +++ b/src/plugins/qmljseditor/qmljssemantichighlighter.h @@ -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 m_watcher; - QmlJSTextEditorWidget *m_editor; + QmlJSEditorDocument *m_document; int m_startRevision; QHash m_formats; QHash m_extraFormats;