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
@@ -42,6 +42,9 @@ class _LoadedGrammar {
}
class TreeSitterService {
static final TreeSitterService shared = TreeSitterService._();
TreeSitterService._();
final Map<String, _LoadedGrammar> _grammars = {};
final Set<String> _unavailable = {};