forked from qt-creator/qt-creator
QmlJSEditor: Move ownership of QmlJSTextMarks to document
Task-number: QTCREATORBUG-19607 Change-Id: I65fa11b43dcbe3c28ab100a1636ad592cfff5a4d Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -34,7 +34,6 @@
|
||||
#include "qmljshighlighter.h"
|
||||
#include "qmljshoverhandler.h"
|
||||
#include "qmljsquickfixassist.h"
|
||||
#include "qmljstextmark.h"
|
||||
#include "qmloutlinemodel.h"
|
||||
|
||||
#include <qmljs/qmljsbind.h>
|
||||
@@ -203,14 +202,12 @@ static void appendExtraSelectionsForMessages(
|
||||
|
||||
void QmlJSEditorWidget::updateCodeWarnings(Document::Ptr doc)
|
||||
{
|
||||
cleanDiagnosticMarks();
|
||||
if (doc->ast()) {
|
||||
setExtraSelections(CodeWarningsSelection, QList<QTextEdit::ExtraSelection>());
|
||||
} else if (doc->language().isFullySupportedLanguage()) {
|
||||
// show parsing errors
|
||||
QList<QTextEdit::ExtraSelection> selections;
|
||||
appendExtraSelectionsForMessages(&selections, doc->diagnosticMessages(), document());
|
||||
createTextMarks(doc->diagnosticMessages());
|
||||
setExtraSelections(CodeWarningsSelection, selections);
|
||||
} else {
|
||||
setExtraSelections(CodeWarningsSelection, QList<QTextEdit::ExtraSelection>());
|
||||
@@ -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<DiagnosticMessage> &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<TextMark *> *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
|
||||
|
@@ -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<QmlJS::DiagnosticMessage> &diagnostics);
|
||||
void cleanDiagnosticMarks();
|
||||
QVector<TextEditor::TextMark *> m_diagnosticMarks;
|
||||
|
||||
void createTextMarks(const QmlJSTools::SemanticInfo &info);
|
||||
void cleanSemanticMarks();
|
||||
QVector<TextEditor::TextMark *> m_semanticMarks;
|
||||
|
||||
FindReferences *m_findReferences;
|
||||
};
|
||||
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#include "qmljsquickfixassist.h"
|
||||
#include "qmljssemantichighlighter.h"
|
||||
#include "qmljssemanticinfoupdater.h"
|
||||
#include "qmljstextmark.h"
|
||||
#include "qmloutlinemodel.h"
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
@@ -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<TextEditor::TextMark *> *marks, TextEditor::TextDocument *doc)
|
||||
{
|
||||
for (TextEditor::TextMark *mark : *marks) {
|
||||
doc->removeMark(mark);
|
||||
delete mark;
|
||||
}
|
||||
marks->clear();
|
||||
}
|
||||
|
||||
void QmlJSEditorDocumentPrivate::createTextMarks(const QList<DiagnosticMessage> &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()
|
||||
|
@@ -32,6 +32,8 @@
|
||||
#include <QTextLayout>
|
||||
#include <QTimer>
|
||||
|
||||
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<QmlJS::DiagnosticMessage> &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<TextEditor::TextMark *> m_diagnosticMarks;
|
||||
QVector<TextEditor::TextMark *> m_semanticMarks;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
|
Reference in New Issue
Block a user