11use std:: collections:: HashMap ;
22use std:: num:: NonZeroU16 ;
33
4- use tree_sitter:: { InputEdit , Language , Node , Parser , Point , Range , Tree , TreeCursor } ;
4+ use tree_sitter:: {
5+ InputEdit , Language , Node , ParseOptions , Parser , Point , Range , Tree , TreeCursor ,
6+ } ;
57
68use crate :: { INLINE_LANGUAGE , LANGUAGE } ;
79
@@ -244,6 +246,16 @@ impl Default for MarkdownParser {
244246}
245247
246248impl MarkdownParser {
249+ /// Parse a slice of UTF8 text.
250+ #[ deprecated( since = "0.5.0" , note = "Prefer `parse_with_options` instead" ) ]
251+ pub fn parse_with < T : AsRef < [ u8 ] > , F : FnMut ( usize , Point ) -> T > (
252+ & mut self ,
253+ callback : & mut F ,
254+ old_tree : Option < & MarkdownTree > ,
255+ ) -> Option < MarkdownTree > {
256+ self . parse_with_options ( callback, old_tree, None )
257+ }
258+
247259 /// Parse a slice of UTF8 text.
248260 ///
249261 /// # Arguments:
@@ -256,10 +268,11 @@ impl MarkdownParser {
256268 /// Returns a [MarkdownTree] if parsing succeeded, or `None` if:
257269 /// * The timeout set with [tree_sitter::Parser::set_timeout_micros] expired
258270 /// * The cancellation flag set with [tree_sitter::Parser::set_cancellation_flag] was flipped
259- pub fn parse_with < T : AsRef < [ u8 ] > , F : FnMut ( usize , Point ) -> T > (
271+ pub fn parse_with_options < T : AsRef < [ u8 ] > , F : FnMut ( usize , Point ) -> T > (
260272 & mut self ,
261273 callback : & mut F ,
262274 old_tree : Option < & MarkdownTree > ,
275+ options : Option < ParseOptions < ' _ > > ,
263276 ) -> Option < MarkdownTree > {
264277 let MarkdownParser {
265278 parser,
@@ -272,7 +285,8 @@ impl MarkdownParser {
272285 parser
273286 . set_language ( block_language)
274287 . expect ( "Could not load block grammar" ) ;
275- let block_tree = parser. parse_with ( callback, old_tree. map ( |tree| & tree. block_tree ) ) ?;
288+ let block_tree =
289+ parser. parse_with_options ( callback, old_tree. map ( |tree| & tree. block_tree ) , options) ?;
276290 let ( mut inline_trees, mut inline_indices) = if let Some ( old_tree) = old_tree {
277291 let len = old_tree. inline_trees . len ( ) ;
278292 ( Vec :: with_capacity ( len) , HashMap :: with_capacity ( len) )
@@ -322,9 +336,10 @@ impl MarkdownParser {
322336 }
323337 ranges. push ( range) ;
324338 parser. set_included_ranges ( & ranges) . ok ( ) ?;
325- let inline_tree = parser. parse_with (
339+ let inline_tree = parser. parse_with_options (
326340 callback,
327341 old_tree. and_then ( |old_tree| old_tree. inline_trees . get ( i) ) ,
342+ options,
328343 ) ?;
329344 inline_trees. push ( inline_tree) ;
330345 inline_indices. insert ( node. id ( ) , i) ;
0 commit comments