diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 01e37a3e4ca..946edbd078b 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -34,7 +34,6 @@ #include "qmljshighlighter.h" #include "qmljshoverhandler.h" #include "qmljsquickfixassist.h" -#include "qmljstextmark.h" #include "qmloutlinemodel.h" #include @@ -203,14 +202,12 @@ static void appendExtraSelectionsForMessages( void QmlJSEditorWidget::updateCodeWarnings(Document::Ptr doc) { - cleanDiagnosticMarks(); if (doc->ast()) { setExtraSelections(CodeWarningsSelection, QList()); } else if (doc->language().isFullySupportedLanguage()) { // show parsing errors QList selections; appendExtraSelectionsForMessages(&selections, doc->diagnosticMessages(), document()); - createTextMarks(doc->diagnosticMessages()); setExtraSelections(CodeWarningsSelection, selections); } else { setExtraSelections(CodeWarningsSelection, QList()); @@ -935,8 +932,6 @@ void QmlJSEditorWidget::semanticInfoUpdated(const SemanticInfo &semanticInfo) } } - createTextMarks(semanticInfo); - updateUses(); } @@ -978,61 +973,6 @@ bool QmlJSEditorWidget::hideContextPane() return b; } -void QmlJSEditorWidget::createTextMarks(const QList &diagnostics) -{ - for (const DiagnosticMessage &diagnostic : diagnostics) { - const auto onMarkRemoved = [this](QmlJSTextMark *mark) { - m_diagnosticMarks.removeAll(mark); - delete mark; - }; - - auto mark = new QmlJSTextMark(textDocument()->filePath().toString(), - diagnostic, onMarkRemoved); - m_diagnosticMarks.append(mark); - textDocument()->addMark(mark); - } -} - -static void cleanMarks(QVector *marks, TextDocument *doc) -{ - for (TextEditor::TextMark *mark : *marks) { - doc->removeMark(mark); - delete mark; - } - marks->clear(); -} - -void QmlJSEditorWidget::cleanDiagnosticMarks() -{ - cleanMarks(&m_diagnosticMarks, textDocument()); -} - -void QmlJSEditorWidget::createTextMarks(const SemanticInfo &info) -{ - cleanSemanticMarks(); - const auto onMarkRemoved = [this](QmlJSTextMark *mark) { - m_semanticMarks.removeAll(mark); - delete mark; - }; - for (const DiagnosticMessage &diagnostic : info.semanticMessages) { - auto mark = new QmlJSTextMark(textDocument()->filePath().toString(), - diagnostic, onMarkRemoved); - m_semanticMarks.append(mark); - textDocument()->addMark(mark); - } - for (const QmlJS::StaticAnalysis::Message &message : info.staticAnalysisMessages) { - auto mark = new QmlJSTextMark(textDocument()->filePath().toString(), - message, onMarkRemoved); - m_semanticMarks.append(mark); - textDocument()->addMark(mark); - } -} - -void QmlJSEditorWidget::cleanSemanticMarks() -{ - cleanMarks(&m_semanticMarks, textDocument()); -} - AssistInterface *QmlJSEditorWidget::createAssistInterface( AssistKind assistKind, AssistReason reason) const diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index 7d68cf318f3..3e055d69c08 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -47,8 +47,6 @@ namespace QmlJS { namespace AST { class UiObjectMember; } } -namespace TextEditor { class TextMark; } - namespace QmlJSEditor { class QmlJSEditorDocument; @@ -129,14 +127,6 @@ private: QmlJS::IContextPane *m_contextPane = nullptr; int m_oldCursorPosition = -1; - void createTextMarks(const QList &diagnostics); - void cleanDiagnosticMarks(); - QVector m_diagnosticMarks; - - void createTextMarks(const QmlJSTools::SemanticInfo &info); - void cleanSemanticMarks(); - QVector m_semanticMarks; - FindReferences *m_findReferences; }; diff --git a/src/plugins/qmljseditor/qmljseditordocument.cpp b/src/plugins/qmljseditor/qmljseditordocument.cpp index 387c1d719fe..79c348ecc4d 100644 --- a/src/plugins/qmljseditor/qmljseditordocument.cpp +++ b/src/plugins/qmljseditor/qmljseditordocument.cpp @@ -32,6 +32,7 @@ #include "qmljsquickfixassist.h" #include "qmljssemantichighlighter.h" #include "qmljssemanticinfoupdater.h" +#include "qmljstextmark.h" #include "qmloutlinemodel.h" #include @@ -521,10 +522,13 @@ void QmlJSEditorDocumentPrivate::onDocumentUpdated(Document::Ptr doc) if (doc->editorRevision() != q->document()->revision()) return; + cleanDiagnosticMarks(); if (doc->ast()) { // got a correctly parsed (or recovered) file. m_semanticInfoDocRevision = doc->editorRevision(); m_semanticInfoUpdater->update(doc, ModelManagerInterface::instance()->snapshot()); + } else if (doc->language().isFullySupportedLanguage()) { + createTextMarks(doc->diagnosticMessages()); } emit q->updateCodeWarnings(doc); } @@ -573,6 +577,7 @@ void QmlJSEditorDocumentPrivate::acceptNewSemanticInfo(const SemanticInfo &seman } } + createTextMarks(m_semanticInfo); emit q->semanticInfoUpdated(m_semanticInfo); // calls triggerPendingUpdates as necessary } @@ -584,6 +589,61 @@ void QmlJSEditorDocumentPrivate::updateOutlineModel() m_outlineModel->update(m_semanticInfo); } +static void cleanMarks(QVector *marks, TextEditor::TextDocument *doc) +{ + for (TextEditor::TextMark *mark : *marks) { + doc->removeMark(mark); + delete mark; + } + marks->clear(); +} + +void QmlJSEditorDocumentPrivate::createTextMarks(const QList &diagnostics) +{ + for (const DiagnosticMessage &diagnostic : diagnostics) { + const auto onMarkRemoved = [this](QmlJSTextMark *mark) { + m_diagnosticMarks.removeAll(mark); + delete mark; + }; + + auto mark = new QmlJSTextMark(q->filePath().toString(), + diagnostic, onMarkRemoved); + m_diagnosticMarks.append(mark); + q->addMark(mark); + } +} + +void QmlJSEditorDocumentPrivate::cleanDiagnosticMarks() +{ + cleanMarks(&m_diagnosticMarks, q); +} + +void QmlJSEditorDocumentPrivate::createTextMarks(const SemanticInfo &info) +{ + cleanSemanticMarks(); + const auto onMarkRemoved = [this](QmlJSTextMark *mark) { + m_semanticMarks.removeAll(mark); + delete mark; + }; + for (const DiagnosticMessage &diagnostic : info.semanticMessages) { + auto mark = new QmlJSTextMark(q->filePath().toString(), + diagnostic, onMarkRemoved); + m_semanticMarks.append(mark); + q->addMark(mark); + } + for (const QmlJS::StaticAnalysis::Message &message : info.staticAnalysisMessages) { + auto mark = new QmlJSTextMark(q->filePath().toString(), + message, onMarkRemoved); + m_semanticMarks.append(mark); + q->addMark(mark); + } +} + +void QmlJSEditorDocumentPrivate::cleanSemanticMarks() +{ + cleanMarks(&m_semanticMarks, q); +} + } // Internal QmlJSEditorDocument::QmlJSEditorDocument() diff --git a/src/plugins/qmljseditor/qmljseditordocument_p.h b/src/plugins/qmljseditor/qmljseditordocument_p.h index 854b81519f8..11d639cb596 100644 --- a/src/plugins/qmljseditor/qmljseditordocument_p.h +++ b/src/plugins/qmljseditor/qmljseditordocument_p.h @@ -32,6 +32,8 @@ #include #include +namespace TextEditor { class TextMark; } + namespace QmlJSEditor { class QmlJSEditorDocument; @@ -57,6 +59,11 @@ public: void acceptNewSemanticInfo(const QmlJSTools::SemanticInfo &semanticInfo); void updateOutlineModel(); + void createTextMarks(const QList &diagnostics); + void cleanDiagnosticMarks(); + void createTextMarks(const QmlJSTools::SemanticInfo &info); + void cleanSemanticMarks(); + public: QmlJSEditorDocument *q = nullptr; QTimer m_updateDocumentTimer; // used to compress multiple document changes @@ -71,6 +78,8 @@ public: bool m_firstSementicInfo = true; QTimer m_updateOutlineModelTimer; Internal::QmlOutlineModel *m_outlineModel = nullptr; + QVector m_diagnosticMarks; + QVector m_semanticMarks; }; } // Internal