refactor(treesitter): replace gotreesitter with native cgo flat-buffer bridge - #144
Merged
Merged
Conversation
…r bridge - Wire Cgo flat-buffer bridge ([]FlatNode) and parse-phase RAII (IngestFlatAST) - Add zero-allocation language detection in detect.go - Update grammar rule definitions to match native Tree-sitter symbols - Extract comments directly from flat CST nodes in internal/comments - Wire native flat-buffer bridge directly into parser and pipeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Continuation of #143. That PR set up the native C runtime and compiled all 18 grammars into
libdiffmantic_grammars.a. This PR wires it into the core engine, replacinggotreesitteracross the parser, pipeline, and rules.Note:
gotreesitteris still ingo.modfor now solely because the existing TUI syntax highlighting still touches it. That TUI is getting removed soon and replaced with static inline and side-by-side renderers similar to difftastic, sogotreesitterwill be dropped completely once that lands.Problem
gotreesitter, which walked CST nodes across Cgo one by one. On larger files that added huge overhead (often 500ms+ just to parse and convert) and caused unnecessary memory churn.What Changed
parse_to_flat_ast) to parse and flatten the CST into a contiguous[]FlatNodearray in a single Cgo call per file.IngestFlatASTto convert the flat buffer into Go*treesitter.ASTNodetrees in one pass, freeing C memory right after parsing so there's zero off-heap memory retention during diffing.internal/treesitter/detect.gousing file extensions and filenames.internal/comments/extract.goinstead of doing separate tree traversals.internal/treesitter/rules/with upstream Tree-sitter symbols across all 18 grammars, verified byrules_grammar_test.go.