diff options
author | Artem Sokolovskii <artem.sokolovskii@qt.io> | 2023-05-08 17:11:54 +0200 |
---|---|---|
committer | Artem Sokolovskii <artem.sokolovskii@qt.io> | 2023-12-11 09:55:02 +0000 |
commit | 62ea85ee6ad15c8e4d9cb5e35b1f10bee3c49ac7 (patch) | |
tree | 71ca8c9033e3389ae3b40021736f07938a8efe0f /src/plugins/cppeditor/cppeditordocument.cpp | |
parent | d5ddf391c14dd3a750856d0d2079a66a2fb7aad8 (diff) |
SyntaxHighlighter: Move SyntaxHighlighter to separate thread
This change involves the relocation of SyntaxHighlighter processing
to another thread. The core idea is to create a duplicate of the
original TextDocument using SyntaxHighlighterRunnerPrivate::cloneDocument.
A new SyntaxHighlighter is then instantiated by SyntaxHighLighterCreator
for the cloned document. The entire SyntaxHighLighterCreator class is
moved to a new thread, where it performs highlighting on the cloned
document. Upon completion of the highlighting process, the resultsReady
signal is emitted, and the updated highlighting data is applied to the
original document.
This shift of SyntaxHighlighter to another thread enhances the user
experience by preventing UI slowdowns during the highlighting process.
- Introduction of BaseSyntaxHighlighterRunner as an interface class for
future *SyntaxHighlighterRunner.
- Inclusion of DirectSyntaxHighlighterRunner class for performing
highlighting in the main thread, suitable for syntax highlighters
that cannot be moved to another thread.
- Introduction of ThreadedSyntaxHighlighterRunner class for highlighting
in a separate thread, preventing UI blocking during the process.
- Addition of Result data to the SyntaxHighlighter class to facilitate
data exchange between threads.
Task-number: QTCREATORBUG-28727
Change-Id: I4b6a38d15f5ec9b8828055d38d2a0c6f21a657b4
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/cppeditor/cppeditordocument.cpp')
-rw-r--r-- | src/plugins/cppeditor/cppeditordocument.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/plugins/cppeditor/cppeditordocument.cpp b/src/plugins/cppeditor/cppeditordocument.cpp index 3d62aadcd6..8d4adebf14 100644 --- a/src/plugins/cppeditor/cppeditordocument.cpp +++ b/src/plugins/cppeditor/cppeditordocument.cpp @@ -22,6 +22,7 @@ #include <texteditor/storagesettings.h> #include <texteditor/textdocumentlayout.h> #include <texteditor/texteditorsettings.h> +#include <texteditor/syntaxhighlighterrunner.h> #include <utils/infobar.h> #include <utils/mimeconstants.h> @@ -79,7 +80,7 @@ private: CppEditorDocument::CppEditorDocument() { setId(CppEditor::Constants::CPPEDITOR_ID); - setSyntaxHighlighterCreator([] { return new CppHighlighter(); }); + resetSyntaxHighlighter([] { return new CppHighlighter(); }); ICodeStylePreferencesFactory *factory = TextEditorSettings::codeStyleFactory(Constants::CPP_SETTINGS_ID); @@ -165,7 +166,7 @@ QByteArray CppEditorDocument::contentsText() const void CppEditorDocument::applyFontSettings() { - if (TextEditor::SyntaxHighlighter *highlighter = syntaxHighlighter()) + if (TextEditor::BaseSyntaxHighlighterRunner *highlighter = syntaxHighlighterRunner()) highlighter->clearAllExtraFormats(); // Clear all additional formats since they may have changed TextDocument::applyFontSettings(); // rehighlights and updates additional formats if (m_processor) @@ -409,8 +410,8 @@ BaseEditorDocumentProcessor *CppEditorDocument::processor() connect(m_processor.data(), &BaseEditorDocumentProcessor::cppDocumentUpdated, this, [this](const CPlusPlus::Document::Ptr document) { // Update syntax highlighter - auto *highlighter = qobject_cast<CppHighlighter *>(syntaxHighlighter()); - highlighter->setLanguageFeatures(document->languageFeatures()); + if (BaseSyntaxHighlighterRunner *highlighter = syntaxHighlighterRunner()) + highlighter->setLanguageFeaturesFlags(document->languageFeatures().flags); m_overviewModel.update(usesClangd() ? nullptr : document); |