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

@@ -156,9 +156,9 @@ void GenerigHighlighterTests::testHighlight()
QTextBlock block = m_editor->textDocument()->document()->findBlockByNumber(blockNumber);
QVERIFY(block.isValid());
QTRY_COMPARE(block.layout()->formats().size(), formatRanges.size());
const QList<QTextLayout::FormatRange> actualFormats = block.layout()->formats();
// full hash calculation for QTextCharFormat fails so just check the important entries of format
QCOMPARE(actualFormats.size(), formatRanges.size());
for (int i = 0; i < formatRanges.size(); ++i)
compareFormats(actualFormats.at(i), formatRanges.at(i));
}
@@ -178,9 +178,9 @@ void GenerigHighlighterTests::testChange()
const FormatRanges formatRanges = {{0, 4, toFormat(C_VISUAL_WHITESPACE)},
{4, 1, toFormat(C_TEXT)}};
QTRY_COMPARE(block.layout()->formats().size(), formatRanges.size());
const QList<QTextLayout::FormatRange> actualFormats = block.layout()->formats();
// full hash calculation for QTextCharFormat fails so just check the important entries of format
QCOMPARE(actualFormats.size(), formatRanges.size());
for (int i = 0; i < formatRanges.size(); ++i)
compareFormats(actualFormats.at(i), formatRanges.at(i));
}
@@ -204,9 +204,9 @@ void GenerigHighlighterTests::testPreeditText()
{14, 1, toFormat(C_VISUAL_WHITESPACE)},
{15, 6, toFormat(C_STRING)},
{21, 1, toFormat(C_FUNCTION)}};
QTRY_COMPARE(block.layout()->formats().size(), formatRanges.size());
const QList<QTextLayout::FormatRange> actualFormats = block.layout()->formats();
// full hash calculation for QTextCharFormat fails so just check the important entries of format
QCOMPARE(actualFormats.size(), formatRanges.size());
for (int i = 0; i < formatRanges.size(); ++i)
compareFormats(actualFormats.at(i), formatRanges.at(i));
}