SyntaxHighlighter: Move generic highlighter to separate thread

Adds a full copy of KSyntaxHighlighting::Repository class
to the Highlighter class, enabling the relocation of the
Highlighter class to a separate thread. This adjustment ensures
that all Definitions come from the copy of the repository, making
them immutable from external code.

The "reload Definition" function stays supported, as triggering
it results in the recreation of the highlighter for the document,
thereby reconstructing the Repository class.

Change-Id: Id7a4d865228c7e7e20e4770601a3fde55b8a6513
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Artem Sokolovskii
2023-11-28 14:58:58 +01:00
parent 5f3950c620
commit e396f84d10
7 changed files with 52 additions and 35 deletions

View File

@@ -1933,7 +1933,7 @@ void TextEditorWidgetPrivate::foldLicenseHeader()
QStringList docMarker;
HighlighterHelper::Definition def;
if (BaseSyntaxHighlighterRunner *highlighter = q->textDocument()->syntaxHighlighterRunner())
def = highlighter->getDefinition();
def = HighlighterHelper::definitionForName(highlighter->definitionName());
if (def.isValid()) {
for (const QString &marker :
@@ -3709,12 +3709,12 @@ void TextEditorWidgetPrivate::configureGenericHighlighter(
q->setCodeFoldingSupported(false);
}
m_document->resetSyntaxHighlighter([definition] {
auto highlighter = new Highlighter();
if (definition.isValid())
highlighter->setDefinition(definition);
return highlighter;
}, false);
const QString definitionFilesPath
= TextEditorSettings::highlighterSettings().definitionFilesPath().toString();
m_document->resetSyntaxHighlighter([definitionFilesPath] {
return new Highlighter(definitionFilesPath);
});
m_document->syntaxHighlighterRunner()->setDefinitionName(definition.name());
m_document->setFontSettings(TextEditorSettings::fontSettings());
}
@@ -3740,7 +3740,7 @@ void TextEditorWidgetPrivate::setupFromDefinition(const KSyntaxHighlighting::Def
KSyntaxHighlighting::Definition TextEditorWidgetPrivate::currentDefinition()
{
if (BaseSyntaxHighlighterRunner *highlighter = m_document->syntaxHighlighterRunner())
return highlighter->getDefinition();
return HighlighterHelper::definitionForName(highlighter->definitionName());
return {};
}