Expand description
Component-driven tree-sitter integration for Bevy.
Parses text into syntax trees on a background thread and exposes the
results as ECS components. This crate is rendering-agnostic — it produces
structured data (SyntaxTree, HighlightRange); what you do with
that data (color tokens, build an outline panel, feed an AI agent) is up
to the host.
§Concepts
Attach these components to an entity to opt into async parsing:
Language— which grammar to use. Construct from atree_sitter::Language(e.g.tree_sitter_rust::LANGUAGE).ParseSourceComp— wraps aParseSourceimplementor that provides the text content and a version counter. The plugin pollscontent_version()each frame; a bump triggers a re-parse.SyntaxTree— written back by the plugin when parsing completes. Subscribe withChanged<SyntaxTree>to react to new trees.
To get highlight ranges from a tree, attach a SyntaxProvider (built
via TreeSitterProvider) to the same entity and query
HighlightRange items. Each range carries a
HighlightRange::capture_name (e.g. "keyword", "function.method",
"comment") — map these to colors, decorations, or whatever the host needs.
§What this crate does NOT provide
- Color mapping or theming — hosts decide what
"keyword"looks like - Rendering — feed the ranges to
bevy_instanced_textLineStylesor any other renderer - Folding or code navigation — those are host concerns
§Quick start
use bevy::prelude::*;
use bevy_tree_sitter::{Language, TreeSitterPlugin};
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(TreeSitterPlugin)
.run();Re-exports§
pub use crate::highlight::HighlightRange;pub use crate::highlight::SyntaxProvider;pub use crate::language::Language;pub use crate::language::TreeSitterConfig;pub use crate::parse::byte_to_point;pub use crate::parse::ParseSource;pub use crate::parse::ParseSourceComp;pub use crate::parse::ParseTask;pub use crate::parse::SyntaxTree;pub use crate::plugin::ParseSet;pub use crate::plugin::TreeSitterPlugin;pub use crate::tree_sitter::RopeReader;pub use crate::tree_sitter::TreeSitterProvider;pub use crate::tree_sitter::MAX_BYTES_TO_QUERY;pub use crate::tree_sitter::SYNC_REPARSE_BYTE_LIMIT;pub use ::tree_sitter as ts;
Modules§
- highlight
- Structural highlight types and the
SyntaxProvidertrait. - language
- Language descriptor + tree-sitter grammar configuration.
- parse
- Component-driven async tree-sitter parsing.
- plugin
TreeSitterPlugin— drives the per-entity parse pipeline.- prelude
- Convenient re-exports for typical consumer use.
- tree_
sitter - Tree-sitter syntax-highlight provider using the low-level
QueryCursorAPI.