make TreeSitterService a shared singleton

Each ClideCodeBlock and EditorView created its own TreeSitterService,
each allocating a WASM engine, store, parser, and cursor via FFI.
When widgets were disposed, multiple instances freeing the same
underlying native resources caused double-free corruption on startup.

Single shared instance for the app lifetime.  Also fixes overlapping
tree-sitter spans that caused duplicated text in code blocks — spans
are now clipped to avoid re-emitting already-rendered characters.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-04-23 21:25:22 +02:00
co-authored by Claude
parent 2f6c11e9a6
commit b236ec439f
3 changed files with 12 additions and 16 deletions
+1 -2
View File
@@ -27,7 +27,7 @@ class EditorView extends StatefulWidget {
class _EditorViewState extends State<EditorView> {
EditorController? _controller;
final TreeSitterService _syntax = TreeSitterService();
final TreeSitterService _syntax = TreeSitterService.shared;
late final SyntaxTextController _text;
late final FocusNode _focus;
String? _lastRemoteContent;
@@ -57,7 +57,6 @@ class _EditorViewState extends State<EditorView> {
_focus.dispose();
_controller?.removeListener(_onControllerChanged);
_controller?.dispose();
_syntax.dispose();
super.dispose();
}