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 "qmljshighlighter.h"
|
||||||
#include "qmljshoverhandler.h"
|
#include "qmljshoverhandler.h"
|
||||||
#include "qmljsquickfixassist.h"
|
#include "qmljsquickfixassist.h"
|
||||||
#include "qmljstextmark.h"
|
|
||||||
#include "qmloutlinemodel.h"
|
#include "qmloutlinemodel.h"
|
||||||
|
|
||||||
#include <qmljs/qmljsbind.h>
|
#include <qmljs/qmljsbind.h>
|
||||||
@@ -203,14 +202,12 @@ static void appendExtraSelectionsForMessages(
|
|||||||
|
|
||||||
void QmlJSEditorWidget::updateCodeWarnings(Document::Ptr doc)
|
void QmlJSEditorWidget::updateCodeWarnings(Document::Ptr doc)
|
||||||
{
|
{
|
||||||
cleanDiagnosticMarks();
|
|
||||||
if (doc->ast()) {
|
if (doc->ast()) {
|
||||||
setExtraSelections(CodeWarningsSelection, QList<QTextEdit::ExtraSelection>());
|
setExtraSelections(CodeWarningsSelection, QList<QTextEdit::ExtraSelection>());
|
||||||
} else if (doc->language().isFullySupportedLanguage()) {
|
} else if (doc->language().isFullySupportedLanguage()) {
|
||||||
// show parsing errors
|
// show parsing errors
|
||||||
QList<QTextEdit::ExtraSelection> selections;
|
QList<QTextEdit::ExtraSelection> selections;
|
||||||
appendExtraSelectionsForMessages(&selections, doc->diagnosticMessages(), document());
|
appendExtraSelectionsForMessages(&selections, doc->diagnosticMessages(), document());
|
||||||
createTextMarks(doc->diagnosticMessages());
|
|
||||||
setExtraSelections(CodeWarningsSelection, selections);
|
setExtraSelections(CodeWarningsSelection, selections);
|
||||||
} else {
|
} else {
|
||||||
setExtraSelections(CodeWarningsSelection, QList<QTextEdit::ExtraSelection>());
|
setExtraSelections(CodeWarningsSelection, QList<QTextEdit::ExtraSelection>());
|
||||||
@@ -935,8 +932,6 @@ void QmlJSEditorWidget::semanticInfoUpdated(const SemanticInfo &semanticInfo)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createTextMarks(semanticInfo);
|
|
||||||
|
|
||||||
updateUses();
|
updateUses();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -978,61 +973,6 @@ bool QmlJSEditorWidget::hideContextPane()
|
|||||||
return b;
|
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(
|
AssistInterface *QmlJSEditorWidget::createAssistInterface(
|
||||||
AssistKind assistKind,
|
AssistKind assistKind,
|
||||||
AssistReason reason) const
|
AssistReason reason) const
|
||||||
|
@@ -47,8 +47,6 @@ namespace QmlJS {
|
|||||||
namespace AST { class UiObjectMember; }
|
namespace AST { class UiObjectMember; }
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace TextEditor { class TextMark; }
|
|
||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
|
|
||||||
class QmlJSEditorDocument;
|
class QmlJSEditorDocument;
|
||||||
@@ -129,14 +127,6 @@ private:
|
|||||||
QmlJS::IContextPane *m_contextPane = nullptr;
|
QmlJS::IContextPane *m_contextPane = nullptr;
|
||||||
int m_oldCursorPosition = -1;
|
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;
|
FindReferences *m_findReferences;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#include "qmljsquickfixassist.h"
|
#include "qmljsquickfixassist.h"
|
||||||
#include "qmljssemantichighlighter.h"
|
#include "qmljssemantichighlighter.h"
|
||||||
#include "qmljssemanticinfoupdater.h"
|
#include "qmljssemanticinfoupdater.h"
|
||||||
|
#include "qmljstextmark.h"
|
||||||
#include "qmloutlinemodel.h"
|
#include "qmloutlinemodel.h"
|
||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
@@ -521,10 +522,13 @@ void QmlJSEditorDocumentPrivate::onDocumentUpdated(Document::Ptr doc)
|
|||||||
if (doc->editorRevision() != q->document()->revision())
|
if (doc->editorRevision() != q->document()->revision())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
cleanDiagnosticMarks();
|
||||||
if (doc->ast()) {
|
if (doc->ast()) {
|
||||||
// got a correctly parsed (or recovered) file.
|
// got a correctly parsed (or recovered) file.
|
||||||
m_semanticInfoDocRevision = doc->editorRevision();
|
m_semanticInfoDocRevision = doc->editorRevision();
|
||||||
m_semanticInfoUpdater->update(doc, ModelManagerInterface::instance()->snapshot());
|
m_semanticInfoUpdater->update(doc, ModelManagerInterface::instance()->snapshot());
|
||||||
|
} else if (doc->language().isFullySupportedLanguage()) {
|
||||||
|
createTextMarks(doc->diagnosticMessages());
|
||||||
}
|
}
|
||||||
emit q->updateCodeWarnings(doc);
|
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
|
emit q->semanticInfoUpdated(m_semanticInfo); // calls triggerPendingUpdates as necessary
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -584,6 +589,61 @@ void QmlJSEditorDocumentPrivate::updateOutlineModel()
|
|||||||
m_outlineModel->update(m_semanticInfo);
|
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
|
} // Internal
|
||||||
|
|
||||||
QmlJSEditorDocument::QmlJSEditorDocument()
|
QmlJSEditorDocument::QmlJSEditorDocument()
|
||||||
|
@@ -32,6 +32,8 @@
|
|||||||
#include <QTextLayout>
|
#include <QTextLayout>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
namespace TextEditor { class TextMark; }
|
||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
|
|
||||||
class QmlJSEditorDocument;
|
class QmlJSEditorDocument;
|
||||||
@@ -57,6 +59,11 @@ public:
|
|||||||
void acceptNewSemanticInfo(const QmlJSTools::SemanticInfo &semanticInfo);
|
void acceptNewSemanticInfo(const QmlJSTools::SemanticInfo &semanticInfo);
|
||||||
void updateOutlineModel();
|
void updateOutlineModel();
|
||||||
|
|
||||||
|
void createTextMarks(const QList<QmlJS::DiagnosticMessage> &diagnostics);
|
||||||
|
void cleanDiagnosticMarks();
|
||||||
|
void createTextMarks(const QmlJSTools::SemanticInfo &info);
|
||||||
|
void cleanSemanticMarks();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QmlJSEditorDocument *q = nullptr;
|
QmlJSEditorDocument *q = nullptr;
|
||||||
QTimer m_updateDocumentTimer; // used to compress multiple document changes
|
QTimer m_updateDocumentTimer; // used to compress multiple document changes
|
||||||
@@ -71,6 +78,8 @@ public:
|
|||||||
bool m_firstSementicInfo = true;
|
bool m_firstSementicInfo = true;
|
||||||
QTimer m_updateOutlineModelTimer;
|
QTimer m_updateOutlineModelTimer;
|
||||||
Internal::QmlOutlineModel *m_outlineModel = nullptr;
|
Internal::QmlOutlineModel *m_outlineModel = nullptr;
|
||||||
|
QVector<TextEditor::TextMark *> m_diagnosticMarks;
|
||||||
|
QVector<TextEditor::TextMark *> m_semanticMarks;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
Reference in New Issue
Block a user