forked from qt-creator/qt-creator
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:
@@ -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();
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
|
Reference in New Issue
Block a user