Skip to main content

compile_pattern

Function compile_pattern 

Source
pub fn compile_pattern(
    snippet: &str,
    language: Language,
) -> Result<CompiledPattern, String>
Expand description

Compile a pattern snippet for language into a tree-sitter query.

A snippet is often a fragment (a + a, foo(bar)) that is not a valid compilation unit on its own. We therefore try the snippet bare first (works for expression-statement languages like TS/JS/Python), then in a small set of per-language wrapper contexts (e.g. a function body for Rust/Go), and locate the snippet’s own subtree by byte range.