QmlJSEditor: prevent possible crash on font settings change

Fixes: QTCREATORBUG-27116
Change-Id: Iac38bd4ef20e739da4c4b8b1c072fd2cd648a66a
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2022-03-17 11:25:48 +01:00
parent 03abdcda9f
commit 519804a0d2
2 changed files with 21 additions and 15 deletions

View File

@@ -175,9 +175,11 @@ class CollectionTask : protected Visitor
{ {
public: public:
CollectionTask(QFutureInterface<SemanticHighlighter::Use> &futureInterface, CollectionTask(QFutureInterface<SemanticHighlighter::Use> &futureInterface,
const QmlJSTools::SemanticInfo &semanticInfo) const QmlJSTools::SemanticInfo &semanticInfo,
const TextEditor::FontSettings &fontSettings)
: m_futureInterface(futureInterface) : m_futureInterface(futureInterface)
, m_semanticInfo(semanticInfo) , m_semanticInfo(semanticInfo)
, m_fontSettings(fontSettings)
, m_scopeChain(semanticInfo.scopeChain()) , m_scopeChain(semanticInfo.scopeChain())
, m_scopeBuilder(&m_scopeChain) , m_scopeBuilder(&m_scopeChain)
, m_lineOfLastUse(0) , m_lineOfLastUse(0)
@@ -408,13 +410,11 @@ protected:
length = end-begin; length = end-begin;
} }
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::fontSettings();
QTextCharFormat format; QTextCharFormat format;
if (d.isWarning()) if (d.isWarning())
format = fontSettings.toTextCharFormat(TextEditor::C_WARNING); format = m_fontSettings.toTextCharFormat(TextEditor::C_WARNING);
else else
format = fontSettings.toTextCharFormat(TextEditor::C_ERROR); format = m_fontSettings.toTextCharFormat(TextEditor::C_ERROR);
format.setToolTip(d.message); format.setToolTip(d.message);
@@ -445,17 +445,15 @@ protected:
length = end-begin; length = end-begin;
} }
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::fontSettings();
QTextCharFormat format; QTextCharFormat format;
if (d.severity == Severity::Warning if (d.severity == Severity::Warning
|| d.severity == Severity::MaybeWarning || d.severity == Severity::MaybeWarning
|| d.severity == Severity::ReadingTypeInfoWarning) { || d.severity == Severity::ReadingTypeInfoWarning) {
format = fontSettings.toTextCharFormat(TextEditor::C_WARNING); format = m_fontSettings.toTextCharFormat(TextEditor::C_WARNING);
} else if (d.severity == Severity::Error || d.severity == Severity::MaybeError) { } else if (d.severity == Severity::Error || d.severity == Severity::MaybeError) {
format = fontSettings.toTextCharFormat(TextEditor::C_ERROR); format = m_fontSettings.toTextCharFormat(TextEditor::C_ERROR);
} else if (d.severity == Severity::Hint) { } else if (d.severity == Severity::Hint) {
format = fontSettings.toTextCharFormat(TextEditor::C_WARNING); format = m_fontSettings.toTextCharFormat(TextEditor::C_WARNING);
format.setUnderlineColor(Qt::darkGreen); format.setUnderlineColor(Qt::darkGreen);
} }
@@ -534,6 +532,7 @@ private:
QFutureInterface<SemanticHighlighter::Use> &m_futureInterface; QFutureInterface<SemanticHighlighter::Use> &m_futureInterface;
const QmlJSTools::SemanticInfo &m_semanticInfo; const QmlJSTools::SemanticInfo &m_semanticInfo;
const TextEditor::FontSettings &m_fontSettings;
ScopeChain m_scopeChain; ScopeChain m_scopeChain;
ScopeBuilder m_scopeBuilder; ScopeBuilder m_scopeBuilder;
QStringList m_stateNames; QStringList m_stateNames;
@@ -565,8 +564,11 @@ void SemanticHighlighter::rerun(const QmlJSTools::SemanticInfo &semanticInfo)
m_watcher.cancel(); m_watcher.cancel();
m_startRevision = m_document->document()->revision(); m_startRevision = m_document->document()->revision();
auto future = Utils::runAsync(QThread::LowestPriority, &SemanticHighlighter::run, auto future = Utils::runAsync(QThread::LowestPriority,
this, semanticInfo); &SemanticHighlighter::run,
this,
semanticInfo,
TextEditor::TextEditorSettings::fontSettings());
m_watcher.setFuture(future); m_watcher.setFuture(future);
m_futureSynchronizer.addFuture(future); m_futureSynchronizer.addFuture(future);
} }
@@ -600,9 +602,11 @@ void SemanticHighlighter::finished()
m_document->syntaxHighlighter(), m_watcher.future()); m_document->syntaxHighlighter(), m_watcher.future());
} }
void SemanticHighlighter::run(QFutureInterface<SemanticHighlighter::Use> &futureInterface, const QmlJSTools::SemanticInfo &semanticInfo) void SemanticHighlighter::run(QFutureInterface<SemanticHighlighter::Use> &futureInterface,
const QmlJSTools::SemanticInfo &semanticInfo,
const TextEditor::FontSettings &fontSettings)
{ {
CollectionTask task(futureInterface, semanticInfo); CollectionTask task(futureInterface, semanticInfo, fontSettings);
reportMessagesInfo(task.diagnosticRanges(), task.extraFormats()); reportMessagesInfo(task.diagnosticRanges(), task.extraFormats());
task.run(); task.run();
} }

View File

@@ -82,7 +82,9 @@ public:
private: private:
void applyResults(int from, int to); void applyResults(int from, int to);
void finished(); void finished();
void run(QFutureInterface<Use> &futureInterface, const QmlJSTools::SemanticInfo &semanticInfo); void run(QFutureInterface<Use> &futureInterface,
const QmlJSTools::SemanticInfo &semanticInfo,
const TextEditor::FontSettings &fontSettings);
QFutureWatcher<Use> m_watcher; QFutureWatcher<Use> m_watcher;
QmlJSEditorDocument *m_document; QmlJSEditorDocument *m_document;