pub struct Injection {
pub language_id: String,
pub ranges: Vec<Range<usize>>,
pub start_row: u32,
pub start_col: u32,
pub end_row: u32,
pub end_col: u32,
}Expand description
An injection point for embedded languages.
Injections allow one language to be embedded within another, such as code blocks in markdown or script tags in HTML.
§Single vs Combined Injections
- Single-range: A fenced code block in Markdown produces one injection with one byte range (e.g., the code block content).
- Combined: Consecutive doc comment lines (
///) produce one injection with multiple byte ranges (one per comment line), merged via#set! injection.combined.
§Example
use reovim_driver_syntax::Injection;
// A Rust code block in a markdown file
let inj = Injection::new("rust", 100..200, 5, 3, 10, 3);
assert_eq!(inj.language_id, "rust");
assert!(inj.overlaps_lines(6, 8));Fields§
§language_id: StringThe language ID to use for the injected region.
ranges: Vec<Range<usize>>Byte ranges in the parent document. Single-range injections (fenced code blocks) have exactly one element. Combined injections (doc comment lines) have multiple elements.
start_row: u32Start row (0-indexed) of the first range.
start_col: u32Start column (0-indexed) of the first range.
end_row: u32End row (0-indexed) of the last range.
end_col: u32End column (0-indexed) of the last range.
Implementations§
Source§impl Injection
impl Injection
Sourcepub fn new(
language_id: impl Into<String>,
byte_range: Range<usize>,
start_row: u32,
start_col: u32,
end_row: u32,
end_col: u32,
) -> Self
pub fn new( language_id: impl Into<String>, byte_range: Range<usize>, start_row: u32, start_col: u32, end_row: u32, end_col: u32, ) -> Self
Create a new single-range injection.
Sourcepub fn combined(
language_id: impl Into<String>,
ranges: Vec<Range<usize>>,
start_row: u32,
start_col: u32,
end_row: u32,
end_col: u32,
) -> Self
pub fn combined( language_id: impl Into<String>, ranges: Vec<Range<usize>>, start_row: u32, start_col: u32, end_row: u32, end_col: u32, ) -> Self
Create a combined injection from multiple byte ranges.
Used for injection.combined patterns where multiple source nodes
(e.g., consecutive doc comment lines) map to a single injection.
Sourcepub fn from_bytes(
language_id: impl Into<String>,
byte_range: Range<usize>,
) -> Self
pub fn from_bytes( language_id: impl Into<String>, byte_range: Range<usize>, ) -> Self
Create an injection from byte range only (row/col set to 0).
Useful when only byte positions are known.
Sourcepub fn byte_range(&self) -> Range<usize>
pub fn byte_range(&self) -> Range<usize>
Get the overall byte range (start of first range to end of last range).
For single-range injections, this is identical to the original range. For combined injections, this spans the entire region.
Sourcepub const fn overlaps_lines(&self, start_line: u32, end_line: u32) -> bool
pub const fn overlaps_lines(&self, start_line: u32, end_line: u32) -> bool
Check if this injection overlaps with a line range.
Both start_line and end_line are inclusive.
Sourcepub const fn contains_line(&self, line: u32) -> bool
pub const fn contains_line(&self, line: u32) -> bool
Check if this injection contains a specific line.
Sourcepub fn overlaps_bytes(&self, range: &Range<usize>) -> bool
pub fn overlaps_bytes(&self, range: &Range<usize>) -> bool
Check if this injection overlaps with a byte range.
Sourcepub const fn is_multiline(&self) -> bool
pub const fn is_multiline(&self) -> bool
Check if this injection spans multiple lines.
Sourcepub const fn line_count(&self) -> u32
pub const fn line_count(&self) -> u32
Get the number of lines spanned by this injection.
Sourcepub const fn is_combined(&self) -> bool
pub const fn is_combined(&self) -> bool
Check if this is a combined injection (multiple ranges).