File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,11 @@ mod native {
3232 self . inner . child_by_field_name ( field_name) . map ( Into :: into)
3333 }
3434
35+ #[ inline]
36+ pub fn child_with_descendant ( & self , descendant : Self ) -> Option < Self > {
37+ self . inner . child_with_descendant ( descendant. inner ) . map ( Into :: into)
38+ }
39+
3540 #[ inline]
3641 pub fn child_count ( & self ) -> u32 {
3742 u32:: try_from ( self . inner . child_count ( ) ) . unwrap ( )
@@ -322,6 +327,11 @@ mod wasm {
322327 self . inner . child_for_field_name ( field_name) . map ( Into :: into)
323328 }
324329
330+ #[ inline]
331+ pub fn child_with_descendant ( & self , descendant : Self ) -> Option < Self > {
332+ self . inner . child_with_descendant ( descendant. inner ) . map ( Into :: into)
333+ }
334+
325335 #[ inline]
326336 pub fn child_count ( & self ) -> u32 {
327337 u32:: try_from ( self . inner . child_count ( ) ) . unwrap ( )
Original file line number Diff line number Diff line change @@ -679,6 +679,9 @@ extern {
679679 #[ wasm_bindgen( method, js_name = childForFieldName) ]
680680 pub fn child_for_field_name ( this : & SyntaxNode , field_name : & str ) -> Option < SyntaxNode > ;
681681
682+ #[ wasm_bindgen( method, js_name = childWithDescendant) ]
683+ pub fn child_with_descendant ( this : & SyntaxNode , descendant : & SyntaxNode ) -> Option < SyntaxNode > ;
684+
682685 #[ wasm_bindgen( method, js_name = descendantForIndex) ]
683686 pub fn descendant_for_index ( this : & SyntaxNode , index : u32 ) -> Option < SyntaxNode > ;
684687
Original file line number Diff line number Diff line change @@ -369,6 +369,18 @@ async fn child_for_field_name() {
369369 assert ! ( inner( ) . await . is_ok( ) ) ;
370370}
371371
372+ #[ wasm_bindgen_test]
373+ async fn child_with_descendant ( ) {
374+ async fn inner ( ) -> Result < ( ) , JsValue > {
375+ TreeSitter :: init ( ) . await ?;
376+ let node = crate :: util:: syntax_node:: make ( ) . await ?. unwrap ( ) ;
377+ let descendant = crate :: util:: syntax_node:: make ( ) . await ?. unwrap ( ) ;
378+ let _ = node. child_with_descendant ( & descendant) ;
379+ Ok ( ( ) )
380+ }
381+ assert ! ( inner( ) . await . is_ok( ) ) ;
382+ }
383+
372384#[ wasm_bindgen_test]
373385async fn descendant_for_index ( ) {
374386 async fn inner ( ) -> Result < ( ) , JsValue > {
You can’t perform that action at this time.
0 commit comments