Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/core/editor/syntax_highlight_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,14 @@ TextStyle? _styleFromSegment(HighlightSegment s, TextStyle? base) {
);
}

/// Runs [syntaxHighlightInIsolate] off the UI thread.
/// Runs highlighting on a worker isolate when [job.code] is large enough;
/// otherwise highlights synchronously on the calling isolate (avoids
/// `compute` overhead for small editors).
Future<List<HighlightSegment>> highlightOffMainThread(
SyntaxHighlightJob job,
) {
if (job.code.length < kSyntaxHighlightIsolateThreshold) {
return Future<List<HighlightSegment>>.value(syntaxHighlightInIsolate(job));
}
return compute(syntaxHighlightInIsolate, job);
}
23 changes: 23 additions & 0 deletions test/core/editor/syntax_highlight_isolate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,27 @@ void main() {
expect(segments, isNotEmpty);
expect(segments.map((s) => s.text).join(), code);
});

test('small SQL buffer highlights inline below isolate threshold', () async {
const code = 'SELECT 1;';
expect(code.length, lessThan(kSyntaxHighlightIsolateThreshold));

final config = buildDefaultEditorHighlighterConfig(
QueryaTheme.darkDefault.editor,
);
final segments = await highlightOffMainThread(
SyntaxHighlightJob(
code: code,
language: 'sql',
themeConfigJson: config,
grammarJson: SyntaxHighlightService.grammarJsonFor(
QueryaCodeLanguage.sql,
),
wrapperArgb: QueryaTheme.darkDefault.editor.foreground.toARGB32(),
),
);

expect(segments, isNotEmpty);
expect(segments.map((s) => s.text).join(), code);
});
}
Loading