Skip to content

Commit 3ada374

Browse files
committed
feat: API for Node child_with_descendant
1 parent f21d89a commit 3ada374

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

crates/tree-sitter-facade/src/node.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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()

crates/web-tree-sitter-sg/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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

crates/web-tree-sitter-sg/tests/node/syntax_node.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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]
373385
async fn descendant_for_index() {
374386
async fn inner() -> Result<(), JsValue> {

0 commit comments

Comments
 (0)