tree_sitter_language_pack 1.8.0 → 1.9.0.pre.rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  // This file is auto-generated by alef. DO NOT EDIT.
2
- // alef:hash:eed307d857d74c9dce2d6a626941327b2f9e3442eaa781b0e2191b8f8b470855
2
+ // alef:hash:a73f3f13c65d02941aef62a37b9b2051ea03b9a31b9017f47182d51888d6138e
3
3
  // Re-generate with: alef generate
4
4
  #![allow(dead_code, unused_imports, unused_variables)]
5
5
  #![allow(
@@ -13,12 +13,15 @@
13
13
  clippy::unwrap_or_default,
14
14
  clippy::derivable_impls,
15
15
  clippy::needless_borrows_for_generic_args,
16
- clippy::unnecessary_fallible_conversions
16
+ clippy::unnecessary_fallible_conversions,
17
+ clippy::type_complexity,
18
+ clippy::useless_conversion,
19
+ clippy::clone_on_copy
17
20
  )]
18
21
 
19
22
  use magnus::{Error, IntoValueFromNative, Ruby, function, method, prelude::*, try_convert::TryConvertOwned};
20
- use std::collections::HashMap;
21
23
  use std::sync::Arc;
24
+ use std::sync::Mutex;
22
25
 
23
26
  fn json_to_ruby(handle: &Ruby, val: serde_json::Value) -> magnus::Value {
24
27
  use magnus::IntoValue;
@@ -423,7 +426,7 @@ impl FileMetrics {
423
426
  }
424
427
  }
425
428
 
426
- #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Default)]
429
+ #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
427
430
  #[serde(default)]
428
431
  #[magnus::wrap(class = "TreeSitterLanguagePack::StructureItem")]
429
432
  pub struct StructureItem {
@@ -466,6 +469,22 @@ impl magnus::TryConvert for StructureItem {
466
469
 
467
470
  unsafe impl TryConvertOwned for StructureItem {}
468
471
 
472
+ impl Default for StructureItem {
473
+ fn default() -> Self {
474
+ Self {
475
+ kind: Default::default(),
476
+ name: None,
477
+ visibility: None,
478
+ span: Default::default(),
479
+ children: vec![],
480
+ decorators: vec![],
481
+ doc_comment: None,
482
+ signature: None,
483
+ body_span: None,
484
+ }
485
+ }
486
+ }
487
+
469
488
  impl StructureItem {
470
489
  fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
471
490
  let ruby = unsafe { magnus::Ruby::get_unchecked() };
@@ -544,7 +563,7 @@ impl StructureItem {
544
563
  }
545
564
  }
546
565
 
547
- #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Default)]
566
+ #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
548
567
  #[serde(default)]
549
568
  #[magnus::wrap(class = "TreeSitterLanguagePack::CommentInfo")]
550
569
  pub struct CommentInfo {
@@ -582,6 +601,17 @@ impl magnus::TryConvert for CommentInfo {
582
601
 
583
602
  unsafe impl TryConvertOwned for CommentInfo {}
584
603
 
604
+ impl Default for CommentInfo {
605
+ fn default() -> Self {
606
+ Self {
607
+ text: String::new(),
608
+ kind: Default::default(),
609
+ span: Default::default(),
610
+ associated_node: None,
611
+ }
612
+ }
613
+ }
614
+
585
615
  impl CommentInfo {
586
616
  fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
587
617
  let ruby = unsafe { magnus::Ruby::get_unchecked() };
@@ -624,7 +654,7 @@ impl CommentInfo {
624
654
  }
625
655
  }
626
656
 
627
- #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Default)]
657
+ #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
628
658
  #[serde(default)]
629
659
  #[magnus::wrap(class = "TreeSitterLanguagePack::DocstringInfo")]
630
660
  pub struct DocstringInfo {
@@ -663,6 +693,18 @@ impl magnus::TryConvert for DocstringInfo {
663
693
 
664
694
  unsafe impl TryConvertOwned for DocstringInfo {}
665
695
 
696
+ impl Default for DocstringInfo {
697
+ fn default() -> Self {
698
+ Self {
699
+ text: String::new(),
700
+ format: Default::default(),
701
+ span: Default::default(),
702
+ associated_item: None,
703
+ parsed_sections: vec![],
704
+ }
705
+ }
706
+ }
707
+
666
708
  impl DocstringInfo {
667
709
  fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
668
710
  let ruby = unsafe { magnus::Ruby::get_unchecked() };
@@ -885,7 +927,7 @@ impl ImportInfo {
885
927
  }
886
928
  }
887
929
 
888
- #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Default)]
930
+ #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
889
931
  #[serde(default)]
890
932
  #[magnus::wrap(class = "TreeSitterLanguagePack::ExportInfo")]
891
933
  pub struct ExportInfo {
@@ -922,6 +964,16 @@ impl magnus::TryConvert for ExportInfo {
922
964
 
923
965
  unsafe impl TryConvertOwned for ExportInfo {}
924
966
 
967
+ impl Default for ExportInfo {
968
+ fn default() -> Self {
969
+ Self {
970
+ name: String::new(),
971
+ kind: Default::default(),
972
+ span: Default::default(),
973
+ }
974
+ }
975
+ }
976
+
925
977
  impl ExportInfo {
926
978
  fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
927
979
  let ruby = unsafe { magnus::Ruby::get_unchecked() };
@@ -957,7 +1009,7 @@ impl ExportInfo {
957
1009
  }
958
1010
  }
959
1011
 
960
- #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Default)]
1012
+ #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
961
1013
  #[serde(default)]
962
1014
  #[magnus::wrap(class = "TreeSitterLanguagePack::SymbolInfo")]
963
1015
  pub struct SymbolInfo {
@@ -996,6 +1048,18 @@ impl magnus::TryConvert for SymbolInfo {
996
1048
 
997
1049
  unsafe impl TryConvertOwned for SymbolInfo {}
998
1050
 
1051
+ impl Default for SymbolInfo {
1052
+ fn default() -> Self {
1053
+ Self {
1054
+ name: String::new(),
1055
+ kind: Default::default(),
1056
+ span: Default::default(),
1057
+ type_annotation: None,
1058
+ doc: None,
1059
+ }
1060
+ }
1061
+ }
1062
+
999
1063
  impl SymbolInfo {
1000
1064
  fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
1001
1065
  let ruby = unsafe { magnus::Ruby::get_unchecked() };
@@ -1045,7 +1109,7 @@ impl SymbolInfo {
1045
1109
  }
1046
1110
  }
1047
1111
 
1048
- #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Default)]
1112
+ #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
1049
1113
  #[serde(default)]
1050
1114
  #[magnus::wrap(class = "TreeSitterLanguagePack::Diagnostic")]
1051
1115
  pub struct Diagnostic {
@@ -1082,6 +1146,16 @@ impl magnus::TryConvert for Diagnostic {
1082
1146
 
1083
1147
  unsafe impl TryConvertOwned for Diagnostic {}
1084
1148
 
1149
+ impl Default for Diagnostic {
1150
+ fn default() -> Self {
1151
+ Self {
1152
+ message: String::new(),
1153
+ severity: Default::default(),
1154
+ span: Default::default(),
1155
+ }
1156
+ }
1157
+ }
1158
+
1085
1159
  impl Diagnostic {
1086
1160
  fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
1087
1161
  let ruby = unsafe { magnus::Ruby::get_unchecked() };
@@ -1435,25 +1509,17 @@ impl PackConfig {
1435
1509
  }
1436
1510
 
1437
1511
  #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
1438
- #[serde(default)]
1439
- #[magnus::wrap(class = "TreeSitterLanguagePack::ProcessConfig")]
1440
- pub struct ProcessConfig {
1441
- language: String,
1442
- structure: bool,
1443
- imports: bool,
1444
- exports: bool,
1445
- comments: bool,
1446
- docstrings: bool,
1447
- symbols: bool,
1448
- diagnostics: bool,
1449
- chunk_max_size: Option<usize>,
1512
+ #[magnus::wrap(class = "TreeSitterLanguagePack::Point")]
1513
+ pub struct Point {
1514
+ row: usize,
1515
+ column: usize,
1450
1516
  }
1451
1517
 
1452
- unsafe impl IntoValueFromNative for ProcessConfig {}
1518
+ unsafe impl IntoValueFromNative for Point {}
1453
1519
 
1454
- impl magnus::TryConvert for ProcessConfig {
1520
+ impl magnus::TryConvert for Point {
1455
1521
  fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
1456
- if let Ok(r) = <&ProcessConfig as magnus::TryConvert>::try_convert(val) {
1522
+ if let Ok(r) = <&Point as magnus::TryConvert>::try_convert(val) {
1457
1523
  return Ok(r.clone());
1458
1524
  }
1459
1525
  let json_str: String = if let Ok(s) = <String as magnus::TryConvert>::try_convert(val) {
@@ -1462,246 +1528,360 @@ impl magnus::TryConvert for ProcessConfig {
1462
1528
  val.funcall::<_, _, String>("to_json", ()).map_err(|e| {
1463
1529
  magnus::Error::new(
1464
1530
  unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1465
- format!("no implicit conversion into ProcessConfig: {}", e),
1531
+ format!("no implicit conversion into Point: {}", e),
1466
1532
  )
1467
1533
  })?
1468
1534
  };
1469
- serde_json::from_str::<ProcessConfig>(&json_str).map_err(|e| {
1535
+ serde_json::from_str::<Point>(&json_str).map_err(|e| {
1470
1536
  magnus::Error::new(
1471
1537
  unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1472
- format!("failed to deserialize ProcessConfig: {}", e),
1538
+ format!("failed to deserialize Point: {}", e),
1473
1539
  )
1474
1540
  })
1475
1541
  }
1476
1542
  }
1477
1543
 
1478
- unsafe impl TryConvertOwned for ProcessConfig {}
1544
+ unsafe impl TryConvertOwned for Point {}
1479
1545
 
1480
- impl Default for ProcessConfig {
1481
- fn default() -> Self {
1482
- tree_sitter_language_pack::ProcessConfig::default().into()
1546
+ impl Point {
1547
+ fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
1548
+ let ruby = unsafe { magnus::Ruby::get_unchecked() };
1549
+ let args = magnus::scan_args::scan_args::<(), (Option<magnus::RHash>,), (), (), (), ()>(args)?;
1550
+ let (kwargs_opt,) = args.optional;
1551
+ let kwargs = kwargs_opt.unwrap_or_else(|| ruby.hash_new());
1552
+ Ok(Self {
1553
+ row: kwargs
1554
+ .get(ruby.to_symbol("row"))
1555
+ .and_then(|v| usize::try_convert(v).ok())
1556
+ .unwrap_or_default(),
1557
+ column: kwargs
1558
+ .get(ruby.to_symbol("column"))
1559
+ .and_then(|v| usize::try_convert(v).ok())
1560
+ .unwrap_or_default(),
1561
+ })
1562
+ }
1563
+
1564
+ fn row(&self) -> usize {
1565
+ self.row
1566
+ }
1567
+
1568
+ fn column(&self) -> usize {
1569
+ self.column
1483
1570
  }
1484
1571
  }
1485
1572
 
1486
- impl ProcessConfig {
1573
+ #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
1574
+ #[magnus::wrap(class = "TreeSitterLanguagePack::ByteRange")]
1575
+ pub struct ByteRange {
1576
+ start: usize,
1577
+ end: usize,
1578
+ }
1579
+
1580
+ unsafe impl IntoValueFromNative for ByteRange {}
1581
+
1582
+ impl magnus::TryConvert for ByteRange {
1583
+ fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
1584
+ if let Ok(r) = <&ByteRange as magnus::TryConvert>::try_convert(val) {
1585
+ return Ok(r.clone());
1586
+ }
1587
+ let json_str: String = if let Ok(s) = <String as magnus::TryConvert>::try_convert(val) {
1588
+ s
1589
+ } else {
1590
+ val.funcall::<_, _, String>("to_json", ()).map_err(|e| {
1591
+ magnus::Error::new(
1592
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1593
+ format!("no implicit conversion into ByteRange: {}", e),
1594
+ )
1595
+ })?
1596
+ };
1597
+ serde_json::from_str::<ByteRange>(&json_str).map_err(|e| {
1598
+ magnus::Error::new(
1599
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1600
+ format!("failed to deserialize ByteRange: {}", e),
1601
+ )
1602
+ })
1603
+ }
1604
+ }
1605
+
1606
+ unsafe impl TryConvertOwned for ByteRange {}
1607
+
1608
+ impl ByteRange {
1487
1609
  fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
1488
1610
  let ruby = unsafe { magnus::Ruby::get_unchecked() };
1489
1611
  let args = magnus::scan_args::scan_args::<(), (Option<magnus::RHash>,), (), (), (), ()>(args)?;
1490
1612
  let (kwargs_opt,) = args.optional;
1491
1613
  let kwargs = kwargs_opt.unwrap_or_else(|| ruby.hash_new());
1492
1614
  Ok(Self {
1493
- language: kwargs
1494
- .get(ruby.to_symbol("language"))
1495
- .and_then(|v| String::try_convert(v).ok())
1615
+ start: kwargs
1616
+ .get(ruby.to_symbol("start"))
1617
+ .and_then(|v| usize::try_convert(v).ok())
1618
+ .unwrap_or_default(),
1619
+ end: kwargs
1620
+ .get(ruby.to_symbol("end"))
1621
+ .and_then(|v| usize::try_convert(v).ok())
1496
1622
  .unwrap_or_default(),
1497
- structure: kwargs
1498
- .get(ruby.to_symbol("structure"))
1499
- .and_then(|v| bool::try_convert(v).ok())
1500
- .unwrap_or(true),
1501
- imports: kwargs
1502
- .get(ruby.to_symbol("imports"))
1503
- .and_then(|v| bool::try_convert(v).ok())
1504
- .unwrap_or(true),
1505
- exports: kwargs
1506
- .get(ruby.to_symbol("exports"))
1507
- .and_then(|v| bool::try_convert(v).ok())
1508
- .unwrap_or(true),
1509
- comments: kwargs
1510
- .get(ruby.to_symbol("comments"))
1511
- .and_then(|v| bool::try_convert(v).ok())
1512
- .unwrap_or(false),
1513
- docstrings: kwargs
1514
- .get(ruby.to_symbol("docstrings"))
1515
- .and_then(|v| bool::try_convert(v).ok())
1516
- .unwrap_or(false),
1517
- symbols: kwargs
1518
- .get(ruby.to_symbol("symbols"))
1519
- .and_then(|v| bool::try_convert(v).ok())
1520
- .unwrap_or(false),
1521
- diagnostics: kwargs
1522
- .get(ruby.to_symbol("diagnostics"))
1523
- .and_then(|v| bool::try_convert(v).ok())
1524
- .unwrap_or(false),
1525
- chunk_max_size: kwargs
1526
- .get(ruby.to_symbol("chunk_max_size"))
1527
- .and_then(|v| usize::try_convert(v).ok()),
1528
1623
  })
1529
1624
  }
1530
1625
 
1531
- fn language(&self) -> String {
1532
- self.language.clone()
1626
+ fn start(&self) -> usize {
1627
+ self.start
1533
1628
  }
1534
1629
 
1535
- fn structure(&self) -> bool {
1536
- self.structure
1630
+ fn end(&self) -> usize {
1631
+ self.end
1537
1632
  }
1633
+ }
1538
1634
 
1539
- fn imports(&self) -> bool {
1540
- self.imports
1541
- }
1635
+ #[derive(Clone)]
1636
+ #[magnus::wrap(class = "TreeSitterLanguagePack::Parser")]
1637
+ pub struct Parser {
1638
+ inner: Arc<std::sync::Mutex<tree_sitter_language_pack::Parser>>,
1639
+ }
1542
1640
 
1543
- fn exports(&self) -> bool {
1544
- self.exports
1545
- }
1641
+ unsafe impl IntoValueFromNative for Parser {}
1546
1642
 
1547
- fn comments(&self) -> bool {
1548
- self.comments
1643
+ impl magnus::TryConvert for Parser {
1644
+ fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
1645
+ let r: &Parser = magnus::TryConvert::try_convert(val)?;
1646
+ Ok(r.clone())
1549
1647
  }
1648
+ }
1550
1649
 
1551
- fn docstrings(&self) -> bool {
1552
- self.docstrings
1650
+ unsafe impl TryConvertOwned for Parser {}
1651
+
1652
+ impl Parser {
1653
+ fn set_language(&self, name: String) -> Result<(), Error> {
1654
+ self.inner.lock().unwrap().set_language(&name).map_err(|e| {
1655
+ magnus::Error::new(
1656
+ unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
1657
+ e.to_string(),
1658
+ )
1659
+ })?;
1660
+ Ok(())
1553
1661
  }
1554
1662
 
1555
- fn symbols(&self) -> bool {
1556
- self.symbols
1663
+ fn parse(&self, source: String) -> Option<Tree> {
1664
+ self.inner
1665
+ .lock()
1666
+ .unwrap()
1667
+ .parse(&source)
1668
+ .map(|v| Tree { inner: Arc::new(v) })
1557
1669
  }
1558
1670
 
1559
- fn diagnostics(&self) -> bool {
1560
- self.diagnostics
1671
+ fn parse_bytes(&self, source: Vec<u8>) -> Option<Tree> {
1672
+ self.inner
1673
+ .lock()
1674
+ .unwrap()
1675
+ .parse_bytes(&source)
1676
+ .map(|v| Tree { inner: Arc::new(v) })
1561
1677
  }
1562
1678
 
1563
- fn chunk_max_size(&self) -> Option<usize> {
1564
- self.chunk_max_size
1679
+ fn reset(&self) -> () {
1680
+ self.inner.lock().unwrap().reset()
1565
1681
  }
1682
+ }
1566
1683
 
1567
- fn with_chunking(&self, max_size: usize) -> ProcessConfig {
1568
- let core_self = tree_sitter_language_pack::ProcessConfig {
1569
- language: self.language.clone().into(),
1684
+ #[derive(Clone)]
1685
+ #[magnus::wrap(class = "TreeSitterLanguagePack::Tree")]
1686
+ pub struct Tree {
1687
+ inner: Arc<tree_sitter_language_pack::Tree>,
1688
+ }
1570
1689
 
1571
- structure: self.structure,
1690
+ unsafe impl IntoValueFromNative for Tree {}
1572
1691
 
1573
- imports: self.imports,
1692
+ impl magnus::TryConvert for Tree {
1693
+ fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
1694
+ let r: &Tree = magnus::TryConvert::try_convert(val)?;
1695
+ Ok(r.clone())
1696
+ }
1697
+ }
1574
1698
 
1575
- exports: self.exports,
1699
+ unsafe impl TryConvertOwned for Tree {}
1576
1700
 
1577
- comments: self.comments,
1701
+ impl Tree {
1702
+ fn root_node(&self) -> Node {
1703
+ Node {
1704
+ inner: Arc::new(self.inner.root_node()),
1705
+ }
1706
+ }
1578
1707
 
1579
- docstrings: self.docstrings,
1708
+ fn walk(&self) -> TreeCursor {
1709
+ TreeCursor {
1710
+ inner: Arc::new(std::sync::Mutex::new(self.inner.walk())),
1711
+ }
1712
+ }
1713
+ }
1580
1714
 
1581
- symbols: self.symbols,
1715
+ #[derive(Clone)]
1716
+ #[magnus::wrap(class = "TreeSitterLanguagePack::Node")]
1717
+ pub struct Node {
1718
+ inner: Arc<tree_sitter_language_pack::Node>,
1719
+ }
1582
1720
 
1583
- diagnostics: self.diagnostics,
1721
+ unsafe impl IntoValueFromNative for Node {}
1584
1722
 
1585
- chunk_max_size: self.chunk_max_size,
1586
- };
1587
- core_self.with_chunking(max_size).into()
1723
+ impl magnus::TryConvert for Node {
1724
+ fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
1725
+ let r: &Node = magnus::TryConvert::try_convert(val)?;
1726
+ Ok(r.clone())
1588
1727
  }
1728
+ }
1589
1729
 
1590
- fn all(&self) -> ProcessConfig {
1591
- let core_self = tree_sitter_language_pack::ProcessConfig {
1592
- language: self.language.clone().into(),
1730
+ unsafe impl TryConvertOwned for Node {}
1593
1731
 
1594
- structure: self.structure,
1732
+ impl Node {
1733
+ fn clone(&self) -> Node {
1734
+ Self {
1735
+ inner: self.inner.clone(),
1736
+ }
1737
+ }
1595
1738
 
1596
- imports: self.imports,
1739
+ fn kind(&self) -> String {
1740
+ self.inner.kind()
1741
+ }
1597
1742
 
1598
- exports: self.exports,
1743
+ fn kind_id(&self) -> u16 {
1744
+ self.inner.kind_id()
1745
+ }
1599
1746
 
1600
- comments: self.comments,
1747
+ fn start_byte(&self) -> usize {
1748
+ self.inner.start_byte()
1749
+ }
1601
1750
 
1602
- docstrings: self.docstrings,
1751
+ fn end_byte(&self) -> usize {
1752
+ self.inner.end_byte()
1753
+ }
1603
1754
 
1604
- symbols: self.symbols,
1755
+ fn byte_range(&self) -> ByteRange {
1756
+ self.inner.byte_range().into()
1757
+ }
1605
1758
 
1606
- diagnostics: self.diagnostics,
1759
+ fn start_position(&self) -> Point {
1760
+ self.inner.start_position().into()
1761
+ }
1607
1762
 
1608
- chunk_max_size: self.chunk_max_size,
1609
- };
1610
- core_self.all().into()
1763
+ fn end_position(&self) -> Point {
1764
+ self.inner.end_position().into()
1611
1765
  }
1612
1766
 
1613
- fn minimal(&self) -> ProcessConfig {
1614
- let core_self = tree_sitter_language_pack::ProcessConfig {
1615
- language: self.language.clone().into(),
1767
+ fn is_named(&self) -> bool {
1768
+ self.inner.is_named()
1769
+ }
1616
1770
 
1617
- structure: self.structure,
1771
+ fn is_error(&self) -> bool {
1772
+ self.inner.is_error()
1773
+ }
1618
1774
 
1619
- imports: self.imports,
1775
+ fn is_missing(&self) -> bool {
1776
+ self.inner.is_missing()
1777
+ }
1620
1778
 
1621
- exports: self.exports,
1779
+ fn is_extra(&self) -> bool {
1780
+ self.inner.is_extra()
1781
+ }
1622
1782
 
1623
- comments: self.comments,
1783
+ fn has_error(&self) -> bool {
1784
+ self.inner.has_error()
1785
+ }
1624
1786
 
1625
- docstrings: self.docstrings,
1787
+ fn parent(&self) -> Option<Node> {
1788
+ self.inner.parent().map(|v| Node { inner: Arc::new(v) })
1789
+ }
1626
1790
 
1627
- symbols: self.symbols,
1791
+ fn child(&self, index: u32) -> Option<Node> {
1792
+ self.inner.child(index).map(|v| Node { inner: Arc::new(v) })
1793
+ }
1628
1794
 
1629
- diagnostics: self.diagnostics,
1795
+ fn child_count(&self) -> usize {
1796
+ self.inner.child_count()
1797
+ }
1630
1798
 
1631
- chunk_max_size: self.chunk_max_size,
1632
- };
1633
- core_self.minimal().into()
1799
+ fn named_child(&self, index: u32) -> Option<Node> {
1800
+ self.inner.named_child(index).map(|v| Node { inner: Arc::new(v) })
1801
+ }
1802
+
1803
+ fn named_child_count(&self) -> usize {
1804
+ self.inner.named_child_count()
1805
+ }
1806
+
1807
+ fn child_by_field_name(&self, name: String) -> Option<Node> {
1808
+ self.inner
1809
+ .child_by_field_name(&name)
1810
+ .map(|v| Node { inner: Arc::new(v) })
1811
+ }
1812
+
1813
+ fn to_sexp(&self) -> String {
1814
+ self.inner.to_sexp()
1815
+ }
1816
+
1817
+ fn walk(&self) -> TreeCursor {
1818
+ TreeCursor {
1819
+ inner: Arc::new(std::sync::Mutex::new(self.inner.walk())),
1820
+ }
1634
1821
  }
1635
1822
  }
1636
1823
 
1637
1824
  #[derive(Clone)]
1638
- #[magnus::wrap(class = "TreeSitterLanguagePack::LanguageRegistry")]
1639
- pub struct LanguageRegistry {
1640
- inner: Arc<tree_sitter_language_pack::LanguageRegistry>,
1825
+ #[magnus::wrap(class = "TreeSitterLanguagePack::TreeCursor")]
1826
+ pub struct TreeCursor {
1827
+ inner: Arc<std::sync::Mutex<tree_sitter_language_pack::TreeCursor>>,
1641
1828
  }
1642
1829
 
1643
- unsafe impl IntoValueFromNative for LanguageRegistry {}
1830
+ unsafe impl IntoValueFromNative for TreeCursor {}
1644
1831
 
1645
- impl magnus::TryConvert for LanguageRegistry {
1832
+ impl magnus::TryConvert for TreeCursor {
1646
1833
  fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
1647
- let r: &LanguageRegistry = magnus::TryConvert::try_convert(val)?;
1834
+ let r: &TreeCursor = magnus::TryConvert::try_convert(val)?;
1648
1835
  Ok(r.clone())
1649
1836
  }
1650
1837
  }
1651
1838
 
1652
- unsafe impl TryConvertOwned for LanguageRegistry {}
1653
-
1654
- impl LanguageRegistry {
1655
- fn add_extra_libs_dir(&self, dir: String) -> () {
1656
- self.inner.add_extra_libs_dir(std::path::PathBuf::from(dir))
1657
- }
1839
+ unsafe impl TryConvertOwned for TreeCursor {}
1658
1840
 
1659
- fn get_language(&self, name: String) -> Result<Language, Error> {
1660
- let result = self.inner.get_language(&name).map_err(|e| {
1661
- magnus::Error::new(
1662
- unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
1663
- e.to_string(),
1664
- )
1665
- })?;
1666
- Ok(Language {
1667
- inner: Arc::new(result),
1668
- })
1841
+ impl TreeCursor {
1842
+ fn node(&self) -> Node {
1843
+ Node {
1844
+ inner: Arc::new(self.inner.lock().unwrap().node()),
1845
+ }
1669
1846
  }
1670
1847
 
1671
- fn available_languages(&self) -> Vec<String> {
1672
- self.inner.available_languages()
1848
+ fn goto_first_child(&self) -> bool {
1849
+ self.inner.lock().unwrap().goto_first_child()
1673
1850
  }
1674
1851
 
1675
- fn has_language(&self, name: String) -> bool {
1676
- self.inner.has_language(&name)
1852
+ fn goto_parent(&self) -> bool {
1853
+ self.inner.lock().unwrap().goto_parent()
1677
1854
  }
1678
1855
 
1679
- fn language_count(&self) -> usize {
1680
- self.inner.language_count()
1856
+ fn goto_next_sibling(&self) -> bool {
1857
+ self.inner.lock().unwrap().goto_next_sibling()
1681
1858
  }
1682
1859
 
1683
- fn process(&self, source: String, config: ProcessConfig) -> Result<ProcessResult, Error> {
1684
- Err(magnus::Error::new(
1685
- unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
1686
- "Not implemented: process",
1687
- ))
1860
+ fn field_name(&self) -> Option<String> {
1861
+ self.inner.lock().unwrap().field_name()
1688
1862
  }
1689
1863
  }
1690
1864
 
1691
- #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Default)]
1692
- #[magnus::wrap(class = "TreeSitterLanguagePack::ParserManifest")]
1693
- pub struct ParserManifest {
1694
- version: String,
1695
- platforms: HashMap<String, PlatformBundle>,
1696
- languages: HashMap<String, LanguageInfo>,
1697
- groups: HashMap<String, Vec<String>>,
1865
+ #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
1866
+ #[serde(default)]
1867
+ #[magnus::wrap(class = "TreeSitterLanguagePack::ProcessConfig")]
1868
+ pub struct ProcessConfig {
1869
+ language: String,
1870
+ structure: bool,
1871
+ imports: bool,
1872
+ exports: bool,
1873
+ comments: bool,
1874
+ docstrings: bool,
1875
+ symbols: bool,
1876
+ diagnostics: bool,
1877
+ chunk_max_size: Option<usize>,
1698
1878
  }
1699
1879
 
1700
- unsafe impl IntoValueFromNative for ParserManifest {}
1880
+ unsafe impl IntoValueFromNative for ProcessConfig {}
1701
1881
 
1702
- impl magnus::TryConvert for ParserManifest {
1882
+ impl magnus::TryConvert for ProcessConfig {
1703
1883
  fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
1704
- if let Ok(r) = <&ParserManifest as magnus::TryConvert>::try_convert(val) {
1884
+ if let Ok(r) = <&ProcessConfig as magnus::TryConvert>::try_convert(val) {
1705
1885
  return Ok(r.clone());
1706
1886
  }
1707
1887
  let json_str: String = if let Ok(s) = <String as magnus::TryConvert>::try_convert(val) {
@@ -1710,194 +1890,229 @@ impl magnus::TryConvert for ParserManifest {
1710
1890
  val.funcall::<_, _, String>("to_json", ()).map_err(|e| {
1711
1891
  magnus::Error::new(
1712
1892
  unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1713
- format!("no implicit conversion into ParserManifest: {}", e),
1893
+ format!("no implicit conversion into ProcessConfig: {}", e),
1714
1894
  )
1715
1895
  })?
1716
1896
  };
1717
- serde_json::from_str::<ParserManifest>(&json_str).map_err(|e| {
1897
+ serde_json::from_str::<ProcessConfig>(&json_str).map_err(|e| {
1718
1898
  magnus::Error::new(
1719
1899
  unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1720
- format!("failed to deserialize ParserManifest: {}", e),
1900
+ format!("failed to deserialize ProcessConfig: {}", e),
1721
1901
  )
1722
1902
  })
1723
1903
  }
1724
1904
  }
1725
1905
 
1726
- unsafe impl TryConvertOwned for ParserManifest {}
1906
+ unsafe impl TryConvertOwned for ProcessConfig {}
1727
1907
 
1728
- impl ParserManifest {
1908
+ impl Default for ProcessConfig {
1909
+ fn default() -> Self {
1910
+ tree_sitter_language_pack::ProcessConfig::default().into()
1911
+ }
1912
+ }
1913
+
1914
+ impl ProcessConfig {
1729
1915
  fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
1730
1916
  let ruby = unsafe { magnus::Ruby::get_unchecked() };
1731
1917
  let args = magnus::scan_args::scan_args::<(), (Option<magnus::RHash>,), (), (), (), ()>(args)?;
1732
1918
  let (kwargs_opt,) = args.optional;
1733
1919
  let kwargs = kwargs_opt.unwrap_or_else(|| ruby.hash_new());
1734
1920
  Ok(Self {
1735
- version: kwargs
1736
- .get(ruby.to_symbol("version"))
1921
+ language: kwargs
1922
+ .get(ruby.to_symbol("language"))
1737
1923
  .and_then(|v| String::try_convert(v).ok())
1738
1924
  .unwrap_or_default(),
1739
- platforms: kwargs
1740
- .get(ruby.to_symbol("platforms"))
1741
- .and_then(|v| <HashMap<String, PlatformBundle>>::try_convert(v).ok())
1742
- .unwrap_or_default(),
1743
- languages: kwargs
1744
- .get(ruby.to_symbol("languages"))
1745
- .and_then(|v| <HashMap<String, LanguageInfo>>::try_convert(v).ok())
1746
- .unwrap_or_default(),
1747
- groups: kwargs
1748
- .get(ruby.to_symbol("groups"))
1749
- .and_then(|v| <HashMap<String, Vec<String>>>::try_convert(v).ok())
1750
- .unwrap_or_default(),
1925
+ structure: kwargs
1926
+ .get(ruby.to_symbol("structure"))
1927
+ .and_then(|v| bool::try_convert(v).ok())
1928
+ .unwrap_or(true),
1929
+ imports: kwargs
1930
+ .get(ruby.to_symbol("imports"))
1931
+ .and_then(|v| bool::try_convert(v).ok())
1932
+ .unwrap_or(true),
1933
+ exports: kwargs
1934
+ .get(ruby.to_symbol("exports"))
1935
+ .and_then(|v| bool::try_convert(v).ok())
1936
+ .unwrap_or(true),
1937
+ comments: kwargs
1938
+ .get(ruby.to_symbol("comments"))
1939
+ .and_then(|v| bool::try_convert(v).ok())
1940
+ .unwrap_or(false),
1941
+ docstrings: kwargs
1942
+ .get(ruby.to_symbol("docstrings"))
1943
+ .and_then(|v| bool::try_convert(v).ok())
1944
+ .unwrap_or(false),
1945
+ symbols: kwargs
1946
+ .get(ruby.to_symbol("symbols"))
1947
+ .and_then(|v| bool::try_convert(v).ok())
1948
+ .unwrap_or(false),
1949
+ diagnostics: kwargs
1950
+ .get(ruby.to_symbol("diagnostics"))
1951
+ .and_then(|v| bool::try_convert(v).ok())
1952
+ .unwrap_or(false),
1953
+ chunk_max_size: kwargs
1954
+ .get(ruby.to_symbol("chunk_max_size"))
1955
+ .and_then(|v| usize::try_convert(v).ok()),
1751
1956
  })
1752
1957
  }
1753
1958
 
1754
- fn version(&self) -> String {
1755
- self.version.clone()
1959
+ fn language(&self) -> String {
1960
+ self.language.clone()
1756
1961
  }
1757
1962
 
1758
- fn platforms(&self) -> HashMap<String, PlatformBundle> {
1759
- self.platforms.clone()
1963
+ fn structure(&self) -> bool {
1964
+ self.structure
1760
1965
  }
1761
1966
 
1762
- fn languages(&self) -> HashMap<String, LanguageInfo> {
1763
- self.languages.clone()
1967
+ fn imports(&self) -> bool {
1968
+ self.imports
1764
1969
  }
1765
1970
 
1766
- fn groups(&self) -> HashMap<String, Vec<String>> {
1767
- self.groups.clone()
1971
+ fn exports(&self) -> bool {
1972
+ self.exports
1768
1973
  }
1769
- }
1770
1974
 
1771
- #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Default)]
1772
- #[magnus::wrap(class = "TreeSitterLanguagePack::PlatformBundle")]
1773
- pub struct PlatformBundle {
1774
- url: String,
1775
- sha256: String,
1776
- size: u64,
1777
- }
1975
+ fn comments(&self) -> bool {
1976
+ self.comments
1977
+ }
1778
1978
 
1779
- unsafe impl IntoValueFromNative for PlatformBundle {}
1979
+ fn docstrings(&self) -> bool {
1980
+ self.docstrings
1981
+ }
1780
1982
 
1781
- impl magnus::TryConvert for PlatformBundle {
1782
- fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
1783
- if let Ok(r) = <&PlatformBundle as magnus::TryConvert>::try_convert(val) {
1784
- return Ok(r.clone());
1785
- }
1786
- let json_str: String = if let Ok(s) = <String as magnus::TryConvert>::try_convert(val) {
1787
- s
1788
- } else {
1789
- val.funcall::<_, _, String>("to_json", ()).map_err(|e| {
1790
- magnus::Error::new(
1791
- unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1792
- format!("no implicit conversion into PlatformBundle: {}", e),
1793
- )
1794
- })?
1795
- };
1796
- serde_json::from_str::<PlatformBundle>(&json_str).map_err(|e| {
1797
- magnus::Error::new(
1798
- unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1799
- format!("failed to deserialize PlatformBundle: {}", e),
1800
- )
1801
- })
1983
+ fn symbols(&self) -> bool {
1984
+ self.symbols
1802
1985
  }
1803
- }
1804
1986
 
1805
- unsafe impl TryConvertOwned for PlatformBundle {}
1987
+ fn diagnostics(&self) -> bool {
1988
+ self.diagnostics
1989
+ }
1806
1990
 
1807
- impl PlatformBundle {
1808
- fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
1809
- let ruby = unsafe { magnus::Ruby::get_unchecked() };
1810
- let args = magnus::scan_args::scan_args::<(), (Option<magnus::RHash>,), (), (), (), ()>(args)?;
1811
- let (kwargs_opt,) = args.optional;
1812
- let kwargs = kwargs_opt.unwrap_or_else(|| ruby.hash_new());
1813
- Ok(Self {
1814
- url: kwargs
1815
- .get(ruby.to_symbol("url"))
1816
- .and_then(|v| String::try_convert(v).ok())
1817
- .unwrap_or_default(),
1818
- sha256: kwargs
1819
- .get(ruby.to_symbol("sha256"))
1820
- .and_then(|v| String::try_convert(v).ok())
1821
- .unwrap_or_default(),
1822
- size: kwargs
1823
- .get(ruby.to_symbol("size"))
1824
- .and_then(|v| u64::try_convert(v).ok())
1825
- .unwrap_or_default(),
1826
- })
1991
+ fn chunk_max_size(&self) -> Option<usize> {
1992
+ self.chunk_max_size
1827
1993
  }
1828
1994
 
1829
- fn url(&self) -> String {
1830
- self.url.clone()
1995
+ fn with_chunking(&self, max_size: usize) -> ProcessConfig {
1996
+ let core_self = tree_sitter_language_pack::ProcessConfig {
1997
+ language: self.language.clone().into(),
1998
+
1999
+ structure: self.structure,
2000
+
2001
+ imports: self.imports,
2002
+
2003
+ exports: self.exports,
2004
+
2005
+ comments: self.comments,
2006
+
2007
+ docstrings: self.docstrings,
2008
+
2009
+ symbols: self.symbols,
2010
+
2011
+ diagnostics: self.diagnostics,
2012
+
2013
+ chunk_max_size: self.chunk_max_size,
2014
+ };
2015
+ core_self.with_chunking(max_size).into()
1831
2016
  }
1832
2017
 
1833
- fn sha256(&self) -> String {
1834
- self.sha256.clone()
2018
+ fn all(&self) -> ProcessConfig {
2019
+ let core_self = tree_sitter_language_pack::ProcessConfig {
2020
+ language: self.language.clone().into(),
2021
+
2022
+ structure: self.structure,
2023
+
2024
+ imports: self.imports,
2025
+
2026
+ exports: self.exports,
2027
+
2028
+ comments: self.comments,
2029
+
2030
+ docstrings: self.docstrings,
2031
+
2032
+ symbols: self.symbols,
2033
+
2034
+ diagnostics: self.diagnostics,
2035
+
2036
+ chunk_max_size: self.chunk_max_size,
2037
+ };
2038
+ core_self.all().into()
1835
2039
  }
1836
2040
 
1837
- fn size(&self) -> u64 {
1838
- self.size
2041
+ fn minimal(&self) -> ProcessConfig {
2042
+ let core_self = tree_sitter_language_pack::ProcessConfig {
2043
+ language: self.language.clone().into(),
2044
+
2045
+ structure: self.structure,
2046
+
2047
+ imports: self.imports,
2048
+
2049
+ exports: self.exports,
2050
+
2051
+ comments: self.comments,
2052
+
2053
+ docstrings: self.docstrings,
2054
+
2055
+ symbols: self.symbols,
2056
+
2057
+ diagnostics: self.diagnostics,
2058
+
2059
+ chunk_max_size: self.chunk_max_size,
2060
+ };
2061
+ core_self.minimal().into()
1839
2062
  }
1840
2063
  }
1841
2064
 
1842
- #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Default)]
1843
- #[magnus::wrap(class = "TreeSitterLanguagePack::LanguageInfo")]
1844
- pub struct LanguageInfo {
1845
- group: String,
1846
- size: u64,
2065
+ #[derive(Clone)]
2066
+ #[magnus::wrap(class = "TreeSitterLanguagePack::LanguageRegistry")]
2067
+ pub struct LanguageRegistry {
2068
+ inner: Arc<tree_sitter_language_pack::LanguageRegistry>,
1847
2069
  }
1848
2070
 
1849
- unsafe impl IntoValueFromNative for LanguageInfo {}
2071
+ unsafe impl IntoValueFromNative for LanguageRegistry {}
1850
2072
 
1851
- impl magnus::TryConvert for LanguageInfo {
2073
+ impl magnus::TryConvert for LanguageRegistry {
1852
2074
  fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
1853
- if let Ok(r) = <&LanguageInfo as magnus::TryConvert>::try_convert(val) {
1854
- return Ok(r.clone());
1855
- }
1856
- let json_str: String = if let Ok(s) = <String as magnus::TryConvert>::try_convert(val) {
1857
- s
1858
- } else {
1859
- val.funcall::<_, _, String>("to_json", ()).map_err(|e| {
1860
- magnus::Error::new(
1861
- unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1862
- format!("no implicit conversion into LanguageInfo: {}", e),
1863
- )
1864
- })?
1865
- };
1866
- serde_json::from_str::<LanguageInfo>(&json_str).map_err(|e| {
2075
+ let r: &LanguageRegistry = magnus::TryConvert::try_convert(val)?;
2076
+ Ok(r.clone())
2077
+ }
2078
+ }
2079
+
2080
+ unsafe impl TryConvertOwned for LanguageRegistry {}
2081
+
2082
+ impl LanguageRegistry {
2083
+ fn get_language(&self, name: String) -> Result<Language, Error> {
2084
+ let result = self.inner.get_language(&name).map_err(|e| {
1867
2085
  magnus::Error::new(
1868
- unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1869
- format!("failed to deserialize LanguageInfo: {}", e),
2086
+ unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
2087
+ e.to_string(),
1870
2088
  )
2089
+ })?;
2090
+ Ok(Language {
2091
+ inner: Arc::new(result),
1871
2092
  })
1872
2093
  }
1873
- }
1874
2094
 
1875
- unsafe impl TryConvertOwned for LanguageInfo {}
2095
+ fn available_languages(&self) -> Vec<String> {
2096
+ self.inner.available_languages()
2097
+ }
1876
2098
 
1877
- impl LanguageInfo {
1878
- fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
1879
- let ruby = unsafe { magnus::Ruby::get_unchecked() };
1880
- let args = magnus::scan_args::scan_args::<(), (Option<magnus::RHash>,), (), (), (), ()>(args)?;
1881
- let (kwargs_opt,) = args.optional;
1882
- let kwargs = kwargs_opt.unwrap_or_else(|| ruby.hash_new());
1883
- Ok(Self {
1884
- group: kwargs
1885
- .get(ruby.to_symbol("group"))
1886
- .and_then(|v| String::try_convert(v).ok())
1887
- .unwrap_or_default(),
1888
- size: kwargs
1889
- .get(ruby.to_symbol("size"))
1890
- .and_then(|v| u64::try_convert(v).ok())
1891
- .unwrap_or_default(),
1892
- })
2099
+ fn has_language(&self, name: String) -> bool {
2100
+ self.inner.has_language(&name)
1893
2101
  }
1894
2102
 
1895
- fn group(&self) -> String {
1896
- self.group.clone()
2103
+ fn language_count(&self) -> usize {
2104
+ self.inner.language_count()
1897
2105
  }
1898
2106
 
1899
- fn size(&self) -> u64 {
1900
- self.size
2107
+ fn process(&self, source: String, config: ProcessConfig) -> Result<ProcessResult, Error> {
2108
+ let config_core: tree_sitter_language_pack::ProcessConfig = config.into();
2109
+ let result = self.inner.process(&source, &config_core).map_err(|e| {
2110
+ magnus::Error::new(
2111
+ unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
2112
+ e.to_string(),
2113
+ )
2114
+ })?;
2115
+ Ok(result.into())
1901
2116
  }
1902
2117
  }
1903
2118
 
@@ -1919,45 +2134,10 @@ impl magnus::TryConvert for DownloadManager {
1919
2134
  unsafe impl TryConvertOwned for DownloadManager {}
1920
2135
 
1921
2136
  impl DownloadManager {
1922
- fn cache_dir(&self) -> String {
1923
- self.inner.cache_dir().to_string_lossy().to_string()
1924
- }
1925
-
1926
2137
  fn installed_languages(&self) -> Vec<String> {
1927
2138
  self.inner.installed_languages()
1928
2139
  }
1929
2140
 
1930
- fn ensure_languages(&self, names: Vec<String>) -> Result<(), Error> {
1931
- Err(magnus::Error::new(
1932
- unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
1933
- "Not implemented: ensure_languages",
1934
- ))
1935
- }
1936
-
1937
- fn ensure_group(&self, group: String) -> Result<(), Error> {
1938
- self.inner.ensure_group(&group).map_err(|e| {
1939
- magnus::Error::new(
1940
- unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
1941
- e.to_string(),
1942
- )
1943
- })?;
1944
- Ok(())
1945
- }
1946
-
1947
- fn lib_path(&self, name: String) -> String {
1948
- self.inner.lib_path(&name).to_string_lossy().to_string()
1949
- }
1950
-
1951
- fn fetch_manifest(&self) -> Result<ParserManifest, Error> {
1952
- let result = self.inner.fetch_manifest().map_err(|e| {
1953
- magnus::Error::new(
1954
- unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
1955
- e.to_string(),
1956
- )
1957
- })?;
1958
- Ok(result.into())
1959
- }
1960
-
1961
2141
  fn download_all_best_effort(&self) -> Result<usize, Error> {
1962
2142
  let result = self.inner.download_all_best_effort().map_err(|e| {
1963
2143
  magnus::Error::new(
@@ -1998,44 +2178,6 @@ unsafe impl TryConvertOwned for Language {}
1998
2178
 
1999
2179
  impl Language {}
2000
2180
 
2001
- #[derive(Clone)]
2002
- #[magnus::wrap(class = "TreeSitterLanguagePack::Parser")]
2003
- pub struct Parser {
2004
- inner: Arc<tree_sitter_language_pack::Parser>,
2005
- }
2006
-
2007
- unsafe impl IntoValueFromNative for Parser {}
2008
-
2009
- impl magnus::TryConvert for Parser {
2010
- fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
2011
- let r: &Parser = magnus::TryConvert::try_convert(val)?;
2012
- Ok(r.clone())
2013
- }
2014
- }
2015
-
2016
- unsafe impl TryConvertOwned for Parser {}
2017
-
2018
- impl Parser {}
2019
-
2020
- #[derive(Clone)]
2021
- #[magnus::wrap(class = "TreeSitterLanguagePack::Tree")]
2022
- pub struct Tree {
2023
- inner: Arc<tree_sitter_language_pack::Tree>,
2024
- }
2025
-
2026
- unsafe impl IntoValueFromNative for Tree {}
2027
-
2028
- impl magnus::TryConvert for Tree {
2029
- fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
2030
- let r: &Tree = magnus::TryConvert::try_convert(val)?;
2031
- Ok(r.clone())
2032
- }
2033
- }
2034
-
2035
- unsafe impl TryConvertOwned for Tree {}
2036
-
2037
- impl Tree {}
2038
-
2039
2181
  #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
2040
2182
  pub enum StructureKind {
2041
2183
  Function,
@@ -2068,15 +2210,26 @@ impl magnus::IntoValue for StructureKind {
2068
2210
 
2069
2211
  impl magnus::TryConvert for StructureKind {
2070
2212
  fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
2071
- let s: String = magnus::TryConvert::try_convert(val)?;
2072
- // Try deserializing as JSON first (handles JSON strings like "\"markdown\"")
2213
+ // For data enums with fields (e.g., PageAction), try to deserialize from JSON first.
2214
+ // For unit enums or when passed as a string, fall back to string-based conversion.
2215
+ let json_str: String = if let Ok(s) = <String as magnus::TryConvert>::try_convert(val) {
2216
+ s
2217
+ } else {
2218
+ val.funcall::<_, _, String>("to_json", ()).map_err(|e| {
2219
+ magnus::Error::new(
2220
+ unsafe { Ruby::get_unchecked() }.exception_type_error(),
2221
+ format!("no implicit conversion into StructureKind: {}", e),
2222
+ )
2223
+ })?
2224
+ };
2225
+ // Try deserializing as JSON first (handles JSON strings like "\"markdown\"" or "{\"click\":{\"selector\":\"...\"}}\"")
2073
2226
  // If that fails, try treating it as a plain string value and wrap in quotes
2074
2227
  // If both fail, try as Custom variant (for untagged enum support)
2075
- serde_json::from_str(&s)
2076
- .or_else(|_| serde_json::from_str(&format!("\"{s}\"")))
2228
+ serde_json::from_str(&json_str)
2229
+ .or_else(|_| serde_json::from_str(&format!("\"{json_str}\"")))
2077
2230
  .or_else(|_| {
2078
2231
  // Try as a JSON string for Custom variant (untagged enums accept any remaining value)
2079
- match serde_json::to_value(&s) {
2232
+ match serde_json::to_value(&json_str) {
2080
2233
  Ok(val) => serde_json::from_value(val),
2081
2234
  Err(e) => Err(e),
2082
2235
  }
@@ -2115,10 +2268,12 @@ impl magnus::IntoValue for CommentKind {
2115
2268
  impl magnus::TryConvert for CommentKind {
2116
2269
  fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
2117
2270
  let s: String = magnus::TryConvert::try_convert(val)?;
2271
+ // Accept the serde wire name (snake_case), the PascalCase Rust variant name,
2272
+ // and a lowercase fallback so fixtures written in any of those styles work.
2118
2273
  match s.as_str() {
2119
- "line" => Ok(CommentKind::Line),
2120
- "block" => Ok(CommentKind::Block),
2121
- "doc" => Ok(CommentKind::Doc),
2274
+ "line" | "Line" => Ok(CommentKind::Line),
2275
+ "block" | "Block" => Ok(CommentKind::Block),
2276
+ "doc" | "Doc" => Ok(CommentKind::Doc),
2122
2277
  other => Err(magnus::Error::new(
2123
2278
  unsafe { Ruby::get_unchecked() }.exception_arg_error(),
2124
2279
  format!("invalid CommentKind value: {other}"),
@@ -2157,15 +2312,26 @@ impl magnus::IntoValue for DocstringFormat {
2157
2312
 
2158
2313
  impl magnus::TryConvert for DocstringFormat {
2159
2314
  fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
2160
- let s: String = magnus::TryConvert::try_convert(val)?;
2161
- // Try deserializing as JSON first (handles JSON strings like "\"markdown\"")
2315
+ // For data enums with fields (e.g., PageAction), try to deserialize from JSON first.
2316
+ // For unit enums or when passed as a string, fall back to string-based conversion.
2317
+ let json_str: String = if let Ok(s) = <String as magnus::TryConvert>::try_convert(val) {
2318
+ s
2319
+ } else {
2320
+ val.funcall::<_, _, String>("to_json", ()).map_err(|e| {
2321
+ magnus::Error::new(
2322
+ unsafe { Ruby::get_unchecked() }.exception_type_error(),
2323
+ format!("no implicit conversion into DocstringFormat: {}", e),
2324
+ )
2325
+ })?
2326
+ };
2327
+ // Try deserializing as JSON first (handles JSON strings like "\"markdown\"" or "{\"click\":{\"selector\":\"...\"}}\"")
2162
2328
  // If that fails, try treating it as a plain string value and wrap in quotes
2163
2329
  // If both fail, try as Custom variant (for untagged enum support)
2164
- serde_json::from_str(&s)
2165
- .or_else(|_| serde_json::from_str(&format!("\"{s}\"")))
2330
+ serde_json::from_str(&json_str)
2331
+ .or_else(|_| serde_json::from_str(&format!("\"{json_str}\"")))
2166
2332
  .or_else(|_| {
2167
2333
  // Try as a JSON string for Custom variant (untagged enums accept any remaining value)
2168
- match serde_json::to_value(&s) {
2334
+ match serde_json::to_value(&json_str) {
2169
2335
  Ok(val) => serde_json::from_value(val),
2170
2336
  Err(e) => Err(e),
2171
2337
  }
@@ -2204,10 +2370,12 @@ impl magnus::IntoValue for ExportKind {
2204
2370
  impl magnus::TryConvert for ExportKind {
2205
2371
  fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
2206
2372
  let s: String = magnus::TryConvert::try_convert(val)?;
2373
+ // Accept the serde wire name (snake_case), the PascalCase Rust variant name,
2374
+ // and a lowercase fallback so fixtures written in any of those styles work.
2207
2375
  match s.as_str() {
2208
- "named" => Ok(ExportKind::Named),
2209
- "default" => Ok(ExportKind::Default),
2210
- "re_export" => Ok(ExportKind::ReExport),
2376
+ "named" | "Named" => Ok(ExportKind::Named),
2377
+ "default" | "Default" => Ok(ExportKind::Default),
2378
+ "re_export" | "ReExport" => Ok(ExportKind::ReExport),
2211
2379
  other => Err(magnus::Error::new(
2212
2380
  unsafe { Ruby::get_unchecked() }.exception_arg_error(),
2213
2381
  format!("invalid ExportKind value: {other}"),
@@ -2249,15 +2417,26 @@ impl magnus::IntoValue for SymbolKind {
2249
2417
 
2250
2418
  impl magnus::TryConvert for SymbolKind {
2251
2419
  fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
2252
- let s: String = magnus::TryConvert::try_convert(val)?;
2253
- // Try deserializing as JSON first (handles JSON strings like "\"markdown\"")
2420
+ // For data enums with fields (e.g., PageAction), try to deserialize from JSON first.
2421
+ // For unit enums or when passed as a string, fall back to string-based conversion.
2422
+ let json_str: String = if let Ok(s) = <String as magnus::TryConvert>::try_convert(val) {
2423
+ s
2424
+ } else {
2425
+ val.funcall::<_, _, String>("to_json", ()).map_err(|e| {
2426
+ magnus::Error::new(
2427
+ unsafe { Ruby::get_unchecked() }.exception_type_error(),
2428
+ format!("no implicit conversion into SymbolKind: {}", e),
2429
+ )
2430
+ })?
2431
+ };
2432
+ // Try deserializing as JSON first (handles JSON strings like "\"markdown\"" or "{\"click\":{\"selector\":\"...\"}}\"")
2254
2433
  // If that fails, try treating it as a plain string value and wrap in quotes
2255
2434
  // If both fail, try as Custom variant (for untagged enum support)
2256
- serde_json::from_str(&s)
2257
- .or_else(|_| serde_json::from_str(&format!("\"{s}\"")))
2435
+ serde_json::from_str(&json_str)
2436
+ .or_else(|_| serde_json::from_str(&format!("\"{json_str}\"")))
2258
2437
  .or_else(|_| {
2259
2438
  // Try as a JSON string for Custom variant (untagged enums accept any remaining value)
2260
- match serde_json::to_value(&s) {
2439
+ match serde_json::to_value(&json_str) {
2261
2440
  Ok(val) => serde_json::from_value(val),
2262
2441
  Err(e) => Err(e),
2263
2442
  }
@@ -2296,10 +2475,12 @@ impl magnus::IntoValue for DiagnosticSeverity {
2296
2475
  impl magnus::TryConvert for DiagnosticSeverity {
2297
2476
  fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
2298
2477
  let s: String = magnus::TryConvert::try_convert(val)?;
2478
+ // Accept the serde wire name (snake_case), the PascalCase Rust variant name,
2479
+ // and a lowercase fallback so fixtures written in any of those styles work.
2299
2480
  match s.as_str() {
2300
- "error" => Ok(DiagnosticSeverity::Error),
2301
- "warning" => Ok(DiagnosticSeverity::Warning),
2302
- "info" => Ok(DiagnosticSeverity::Info),
2481
+ "error" | "Error" => Ok(DiagnosticSeverity::Error),
2482
+ "warning" | "Warning" => Ok(DiagnosticSeverity::Warning),
2483
+ "info" | "Info" => Ok(DiagnosticSeverity::Info),
2303
2484
  other => Err(magnus::Error::new(
2304
2485
  unsafe { Ruby::get_unchecked() }.exception_arg_error(),
2305
2486
  format!("invalid DiagnosticSeverity value: {other}"),
@@ -2355,7 +2536,7 @@ fn get_parser(name: String) -> Result<Parser, Error> {
2355
2536
  )
2356
2537
  })?;
2357
2538
  Ok(Parser {
2358
- inner: Arc::new(result),
2539
+ inner: Arc::new(std::sync::Mutex::new(result)),
2359
2540
  })
2360
2541
  }
2361
2542
 
@@ -2378,7 +2559,9 @@ fn language_count() -> usize {
2378
2559
  fn process(args: &[magnus::Value]) -> Result<ProcessResult, Error> {
2379
2560
  let args = magnus::scan_args::scan_args::<(String,), (Option<magnus::Value>,), (), (), (), ()>(args)?;
2380
2561
  let (source,) = args.required;
2562
+
2381
2563
  let (config,) = args.optional;
2564
+
2382
2565
  let config_core: tree_sitter_language_pack::ProcessConfig = match config {
2383
2566
  Some(_v) if !_v.is_nil() => {
2384
2567
  let binding_val: ProcessConfig = ProcessConfig::try_convert(_v).map_err(|e| {
@@ -2403,6 +2586,7 @@ fn process(args: &[magnus::Value]) -> Result<ProcessResult, Error> {
2403
2586
  fn init(args: &[magnus::Value]) -> Result<(), Error> {
2404
2587
  let args = magnus::scan_args::scan_args::<(), (Option<magnus::Value>,), (), (), (), ()>(args)?;
2405
2588
  let (config,) = args.optional;
2589
+
2406
2590
  let config_core: tree_sitter_language_pack::PackConfig = match config {
2407
2591
  Some(_v) if !_v.is_nil() => {
2408
2592
  let binding_val: PackConfig = PackConfig::try_convert(_v).map_err(|e| {
@@ -2427,6 +2611,7 @@ fn init(args: &[magnus::Value]) -> Result<(), Error> {
2427
2611
  fn configure(args: &[magnus::Value]) -> Result<(), Error> {
2428
2612
  let args = magnus::scan_args::scan_args::<(), (Option<magnus::Value>,), (), (), (), ()>(args)?;
2429
2613
  let (config,) = args.optional;
2614
+
2430
2615
  let config_core: tree_sitter_language_pack::PackConfig = match config {
2431
2616
  Some(_v) if !_v.is_nil() => {
2432
2617
  let binding_val: PackConfig = PackConfig::try_convert(_v).map_err(|e| {
@@ -2469,6 +2654,16 @@ fn download_all() -> Result<usize, Error> {
2469
2654
  Ok(result)
2470
2655
  }
2471
2656
 
2657
+ fn download_group(name: String) -> Result<usize, Error> {
2658
+ let result = tree_sitter_language_pack::download_group(&name).map_err(|e| {
2659
+ magnus::Error::new(
2660
+ unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
2661
+ e.to_string(),
2662
+ )
2663
+ })?;
2664
+ Ok(result)
2665
+ }
2666
+
2472
2667
  fn manifest_languages() -> Result<Vec<String>, Error> {
2473
2668
  let result = tree_sitter_language_pack::manifest_languages().map_err(|e| {
2474
2669
  magnus::Error::new(
@@ -2608,7 +2803,7 @@ impl From<StructureItem> for tree_sitter_language_pack::StructureItem {
2608
2803
  visibility: val.visibility,
2609
2804
  span: val.span.into(),
2610
2805
  children: val.children.into_iter().map(Into::into).collect(),
2611
- decorators: val.decorators,
2806
+ decorators: val.decorators.into_iter().collect(),
2612
2807
  doc_comment: val.doc_comment,
2613
2808
  signature: val.signature,
2614
2809
  body_span: val.body_span.map(Into::into),
@@ -2625,7 +2820,7 @@ impl From<tree_sitter_language_pack::StructureItem> for StructureItem {
2625
2820
  visibility: val.visibility,
2626
2821
  span: val.span.into(),
2627
2822
  children: val.children.into_iter().map(Into::into).collect(),
2628
- decorators: val.decorators,
2823
+ decorators: val.decorators.into_iter().collect(),
2629
2824
  doc_comment: val.doc_comment,
2630
2825
  signature: val.signature,
2631
2826
  body_span: val.body_span.map(Into::into),
@@ -2710,7 +2905,7 @@ impl From<ImportInfo> for tree_sitter_language_pack::ImportInfo {
2710
2905
  fn from(val: ImportInfo) -> Self {
2711
2906
  Self {
2712
2907
  source: val.source,
2713
- items: val.items,
2908
+ items: val.items.into_iter().collect(),
2714
2909
  alias: val.alias,
2715
2910
  is_wildcard: val.is_wildcard,
2716
2911
  span: val.span.into(),
@@ -2723,7 +2918,7 @@ impl From<tree_sitter_language_pack::ImportInfo> for ImportInfo {
2723
2918
  fn from(val: tree_sitter_language_pack::ImportInfo) -> Self {
2724
2919
  Self {
2725
2920
  source: val.source,
2726
- items: val.items,
2921
+ items: val.items.into_iter().collect(),
2727
2922
  alias: val.alias,
2728
2923
  is_wildcard: val.is_wildcard,
2729
2924
  span: val.span.into(),
@@ -2836,9 +3031,9 @@ impl From<ChunkContext> for tree_sitter_language_pack::ChunkContext {
2836
3031
  language: val.language,
2837
3032
  chunk_index: val.chunk_index,
2838
3033
  total_chunks: val.total_chunks,
2839
- node_types: val.node_types,
2840
- context_path: val.context_path,
2841
- symbols_defined: val.symbols_defined,
3034
+ node_types: val.node_types.into_iter().collect(),
3035
+ context_path: val.context_path.into_iter().collect(),
3036
+ symbols_defined: val.symbols_defined.into_iter().collect(),
2842
3037
  comments: val.comments.into_iter().map(Into::into).collect(),
2843
3038
  docstrings: val.docstrings.into_iter().map(Into::into).collect(),
2844
3039
  has_error_nodes: val.has_error_nodes,
@@ -2853,9 +3048,9 @@ impl From<tree_sitter_language_pack::ChunkContext> for ChunkContext {
2853
3048
  language: val.language,
2854
3049
  chunk_index: val.chunk_index,
2855
3050
  total_chunks: val.total_chunks,
2856
- node_types: val.node_types,
2857
- context_path: val.context_path,
2858
- symbols_defined: val.symbols_defined,
3051
+ node_types: val.node_types.into_iter().collect(),
3052
+ context_path: val.context_path.into_iter().collect(),
3053
+ symbols_defined: val.symbols_defined.into_iter().collect(),
2859
3054
  comments: val.comments.into_iter().map(Into::into).collect(),
2860
3055
  docstrings: val.docstrings.into_iter().map(Into::into).collect(),
2861
3056
  has_error_nodes: val.has_error_nodes,
@@ -2868,8 +3063,8 @@ impl From<PackConfig> for tree_sitter_language_pack::PackConfig {
2868
3063
  fn from(val: PackConfig) -> Self {
2869
3064
  Self {
2870
3065
  cache_dir: val.cache_dir.map(Into::into),
2871
- languages: val.languages,
2872
- groups: val.groups,
3066
+ languages: val.languages.map(|v| v.into_iter().collect()),
3067
+ groups: val.groups.map(|v| v.into_iter().collect()),
2873
3068
  }
2874
3069
  }
2875
3070
  }
@@ -2879,108 +3074,82 @@ impl From<tree_sitter_language_pack::PackConfig> for PackConfig {
2879
3074
  fn from(val: tree_sitter_language_pack::PackConfig) -> Self {
2880
3075
  Self {
2881
3076
  cache_dir: val.cache_dir.map(|p| p.to_string_lossy().to_string()),
2882
- languages: val.languages,
2883
- groups: val.groups,
2884
- }
2885
- }
2886
- }
2887
-
2888
- #[allow(clippy::redundant_closure, clippy::useless_conversion)]
2889
- impl From<ProcessConfig> for tree_sitter_language_pack::ProcessConfig {
2890
- fn from(val: ProcessConfig) -> Self {
2891
- Self {
2892
- language: val.language.into(),
2893
- structure: val.structure,
2894
- imports: val.imports,
2895
- exports: val.exports,
2896
- comments: val.comments,
2897
- docstrings: val.docstrings,
2898
- symbols: val.symbols,
2899
- diagnostics: val.diagnostics,
2900
- chunk_max_size: val.chunk_max_size,
2901
- }
2902
- }
2903
- }
2904
-
2905
- #[allow(clippy::redundant_closure, clippy::useless_conversion)]
2906
- impl From<tree_sitter_language_pack::ProcessConfig> for ProcessConfig {
2907
- fn from(val: tree_sitter_language_pack::ProcessConfig) -> Self {
2908
- Self {
2909
- language: val.language.to_string(),
2910
- structure: val.structure,
2911
- imports: val.imports,
2912
- exports: val.exports,
2913
- comments: val.comments,
2914
- docstrings: val.docstrings,
2915
- symbols: val.symbols,
2916
- diagnostics: val.diagnostics,
2917
- chunk_max_size: val.chunk_max_size,
3077
+ languages: val.languages.map(|v| v.into_iter().collect()),
3078
+ groups: val.groups.map(|v| v.into_iter().collect()),
2918
3079
  }
2919
3080
  }
2920
3081
  }
2921
3082
 
2922
3083
  #[allow(clippy::redundant_closure, clippy::useless_conversion)]
2923
- impl From<ParserManifest> for tree_sitter_language_pack::download::ParserManifest {
2924
- fn from(val: ParserManifest) -> Self {
3084
+ impl From<Point> for tree_sitter_language_pack::Point {
3085
+ fn from(val: Point) -> Self {
2925
3086
  Self {
2926
- version: val.version,
2927
- platforms: val.platforms.into_iter().map(|(k, v)| (k.into(), v.into())).collect(),
2928
- languages: val.languages.into_iter().map(|(k, v)| (k.into(), v.into())).collect(),
2929
- groups: val.groups.into_iter().collect(),
3087
+ row: val.row,
3088
+ column: val.column,
2930
3089
  }
2931
3090
  }
2932
3091
  }
2933
3092
 
2934
3093
  #[allow(clippy::redundant_closure, clippy::useless_conversion)]
2935
- impl From<tree_sitter_language_pack::download::ParserManifest> for ParserManifest {
2936
- fn from(val: tree_sitter_language_pack::download::ParserManifest) -> Self {
3094
+ impl From<tree_sitter_language_pack::Point> for Point {
3095
+ fn from(val: tree_sitter_language_pack::Point) -> Self {
2937
3096
  Self {
2938
- version: val.version,
2939
- platforms: val.platforms.into_iter().map(|(k, v)| (k, v.into())).collect(),
2940
- languages: val.languages.into_iter().map(|(k, v)| (k, v.into())).collect(),
2941
- groups: val.groups.into_iter().collect(),
3097
+ row: val.row,
3098
+ column: val.column,
2942
3099
  }
2943
3100
  }
2944
3101
  }
2945
3102
 
2946
3103
  #[allow(clippy::redundant_closure, clippy::useless_conversion)]
2947
- impl From<PlatformBundle> for tree_sitter_language_pack::download::PlatformBundle {
2948
- fn from(val: PlatformBundle) -> Self {
3104
+ impl From<ByteRange> for tree_sitter_language_pack::ByteRange {
3105
+ fn from(val: ByteRange) -> Self {
2949
3106
  Self {
2950
- url: val.url,
2951
- sha256: val.sha256,
2952
- size: val.size,
3107
+ start: val.start,
3108
+ end: val.end,
2953
3109
  }
2954
3110
  }
2955
3111
  }
2956
3112
 
2957
3113
  #[allow(clippy::redundant_closure, clippy::useless_conversion)]
2958
- impl From<tree_sitter_language_pack::download::PlatformBundle> for PlatformBundle {
2959
- fn from(val: tree_sitter_language_pack::download::PlatformBundle) -> Self {
3114
+ impl From<tree_sitter_language_pack::ByteRange> for ByteRange {
3115
+ fn from(val: tree_sitter_language_pack::ByteRange) -> Self {
2960
3116
  Self {
2961
- url: val.url,
2962
- sha256: val.sha256,
2963
- size: val.size,
3117
+ start: val.start,
3118
+ end: val.end,
2964
3119
  }
2965
3120
  }
2966
3121
  }
2967
3122
 
2968
3123
  #[allow(clippy::redundant_closure, clippy::useless_conversion)]
2969
- impl From<LanguageInfo> for tree_sitter_language_pack::download::LanguageInfo {
2970
- fn from(val: LanguageInfo) -> Self {
3124
+ impl From<ProcessConfig> for tree_sitter_language_pack::ProcessConfig {
3125
+ fn from(val: ProcessConfig) -> Self {
2971
3126
  Self {
2972
- group: val.group,
2973
- size: val.size,
3127
+ language: val.language.into(),
3128
+ structure: val.structure,
3129
+ imports: val.imports,
3130
+ exports: val.exports,
3131
+ comments: val.comments,
3132
+ docstrings: val.docstrings,
3133
+ symbols: val.symbols,
3134
+ diagnostics: val.diagnostics,
3135
+ chunk_max_size: val.chunk_max_size,
2974
3136
  }
2975
3137
  }
2976
3138
  }
2977
3139
 
2978
3140
  #[allow(clippy::redundant_closure, clippy::useless_conversion)]
2979
- impl From<tree_sitter_language_pack::download::LanguageInfo> for LanguageInfo {
2980
- fn from(val: tree_sitter_language_pack::download::LanguageInfo) -> Self {
3141
+ impl From<tree_sitter_language_pack::ProcessConfig> for ProcessConfig {
3142
+ fn from(val: tree_sitter_language_pack::ProcessConfig) -> Self {
2981
3143
  Self {
2982
- group: val.group,
2983
- size: val.size,
3144
+ language: val.language.to_string(),
3145
+ structure: val.structure,
3146
+ imports: val.imports,
3147
+ exports: val.exports,
3148
+ comments: val.comments,
3149
+ docstrings: val.docstrings,
3150
+ symbols: val.symbols,
3151
+ diagnostics: val.diagnostics,
3152
+ chunk_max_size: val.chunk_max_size,
2984
3153
  }
2985
3154
  }
2986
3155
  }
@@ -3150,214 +3319,400 @@ fn error_to_magnus_err(e: tree_sitter_language_pack::error::Error) -> magnus::Er
3150
3319
  fn ruby_init(ruby: &Ruby) -> Result<(), Error> {
3151
3320
  let module = ruby.define_module("TreeSitterLanguagePack")?;
3152
3321
 
3322
+ // Ensure JSON library is loaded for Hash#to_json
3323
+ let _ = ruby.eval::<magnus::Value>("require \"json\"");
3324
+
3153
3325
  let class = module.define_class("Span", ruby.class_object())?;
3326
+
3154
3327
  class.define_singleton_method("new", function!(Span::new, -1))?;
3328
+
3155
3329
  class.define_method("start_byte", method!(Span::start_byte, 0))?;
3330
+
3156
3331
  class.define_method("end_byte", method!(Span::end_byte, 0))?;
3332
+
3157
3333
  class.define_method("start_line", method!(Span::start_line, 0))?;
3334
+
3158
3335
  class.define_method("start_column", method!(Span::start_column, 0))?;
3336
+
3159
3337
  class.define_method("end_line", method!(Span::end_line, 0))?;
3338
+
3160
3339
  class.define_method("end_column", method!(Span::end_column, 0))?;
3161
3340
 
3162
3341
  let class = module.define_class("ProcessResult", ruby.class_object())?;
3342
+
3163
3343
  class.define_singleton_method("new", function!(ProcessResult::new, -1))?;
3344
+
3164
3345
  class.define_method("language", method!(ProcessResult::language, 0))?;
3346
+
3165
3347
  class.define_method("metrics", method!(ProcessResult::metrics, 0))?;
3348
+
3166
3349
  class.define_method("structure", method!(ProcessResult::structure, 0))?;
3350
+
3167
3351
  class.define_method("imports", method!(ProcessResult::imports, 0))?;
3352
+
3168
3353
  class.define_method("exports", method!(ProcessResult::exports, 0))?;
3354
+
3169
3355
  class.define_method("comments", method!(ProcessResult::comments, 0))?;
3356
+
3170
3357
  class.define_method("docstrings", method!(ProcessResult::docstrings, 0))?;
3358
+
3171
3359
  class.define_method("symbols", method!(ProcessResult::symbols, 0))?;
3360
+
3172
3361
  class.define_method("diagnostics", method!(ProcessResult::diagnostics, 0))?;
3362
+
3173
3363
  class.define_method("chunks", method!(ProcessResult::chunks, 0))?;
3174
3364
 
3175
3365
  let class = module.define_class("FileMetrics", ruby.class_object())?;
3366
+
3176
3367
  class.define_singleton_method("new", function!(FileMetrics::new, -1))?;
3368
+
3177
3369
  class.define_method("total_lines", method!(FileMetrics::total_lines, 0))?;
3370
+
3178
3371
  class.define_method("code_lines", method!(FileMetrics::code_lines, 0))?;
3372
+
3179
3373
  class.define_method("comment_lines", method!(FileMetrics::comment_lines, 0))?;
3374
+
3180
3375
  class.define_method("blank_lines", method!(FileMetrics::blank_lines, 0))?;
3376
+
3181
3377
  class.define_method("total_bytes", method!(FileMetrics::total_bytes, 0))?;
3378
+
3182
3379
  class.define_method("node_count", method!(FileMetrics::node_count, 0))?;
3380
+
3183
3381
  class.define_method("error_count", method!(FileMetrics::error_count, 0))?;
3382
+
3184
3383
  class.define_method("max_depth", method!(FileMetrics::max_depth, 0))?;
3185
3384
 
3186
3385
  let class = module.define_class("StructureItem", ruby.class_object())?;
3386
+
3187
3387
  class.define_singleton_method("new", function!(StructureItem::new, -1))?;
3388
+
3188
3389
  class.define_method("kind", method!(StructureItem::kind, 0))?;
3390
+
3189
3391
  class.define_method("name", method!(StructureItem::name, 0))?;
3392
+
3190
3393
  class.define_method("visibility", method!(StructureItem::visibility, 0))?;
3394
+
3191
3395
  class.define_method("span", method!(StructureItem::span, 0))?;
3396
+
3192
3397
  class.define_method("children", method!(StructureItem::children, 0))?;
3398
+
3193
3399
  class.define_method("decorators", method!(StructureItem::decorators, 0))?;
3400
+
3194
3401
  class.define_method("doc_comment", method!(StructureItem::doc_comment, 0))?;
3402
+
3195
3403
  class.define_method("signature", method!(StructureItem::signature, 0))?;
3404
+
3196
3405
  class.define_method("body_span", method!(StructureItem::body_span, 0))?;
3197
3406
 
3198
3407
  let class = module.define_class("CommentInfo", ruby.class_object())?;
3408
+
3199
3409
  class.define_singleton_method("new", function!(CommentInfo::new, -1))?;
3410
+
3200
3411
  class.define_method("text", method!(CommentInfo::text, 0))?;
3412
+
3201
3413
  class.define_method("kind", method!(CommentInfo::kind, 0))?;
3414
+
3202
3415
  class.define_method("span", method!(CommentInfo::span, 0))?;
3416
+
3203
3417
  class.define_method("associated_node", method!(CommentInfo::associated_node, 0))?;
3204
3418
 
3205
3419
  let class = module.define_class("DocstringInfo", ruby.class_object())?;
3420
+
3206
3421
  class.define_singleton_method("new", function!(DocstringInfo::new, -1))?;
3422
+
3207
3423
  class.define_method("text", method!(DocstringInfo::text, 0))?;
3424
+
3208
3425
  class.define_method("format", method!(DocstringInfo::format, 0))?;
3426
+
3209
3427
  class.define_method("span", method!(DocstringInfo::span, 0))?;
3428
+
3210
3429
  class.define_method("associated_item", method!(DocstringInfo::associated_item, 0))?;
3430
+
3211
3431
  class.define_method("parsed_sections", method!(DocstringInfo::parsed_sections, 0))?;
3212
3432
 
3213
3433
  let class = module.define_class("DocSection", ruby.class_object())?;
3434
+
3214
3435
  class.define_singleton_method("new", function!(DocSection::new, -1))?;
3436
+
3215
3437
  class.define_method("kind", method!(DocSection::kind, 0))?;
3438
+
3216
3439
  class.define_method("name", method!(DocSection::name, 0))?;
3440
+
3217
3441
  class.define_method("description", method!(DocSection::description, 0))?;
3218
3442
 
3219
3443
  let class = module.define_class("ImportInfo", ruby.class_object())?;
3444
+
3220
3445
  class.define_singleton_method("new", function!(ImportInfo::new, -1))?;
3446
+
3221
3447
  class.define_method("source", method!(ImportInfo::source, 0))?;
3448
+
3222
3449
  class.define_method("items", method!(ImportInfo::items, 0))?;
3450
+
3223
3451
  class.define_method("alias", method!(ImportInfo::alias, 0))?;
3452
+
3224
3453
  class.define_method("is_wildcard", method!(ImportInfo::is_wildcard, 0))?;
3454
+
3225
3455
  class.define_method("span", method!(ImportInfo::span, 0))?;
3226
3456
 
3227
3457
  let class = module.define_class("ExportInfo", ruby.class_object())?;
3458
+
3228
3459
  class.define_singleton_method("new", function!(ExportInfo::new, -1))?;
3460
+
3229
3461
  class.define_method("name", method!(ExportInfo::name, 0))?;
3462
+
3230
3463
  class.define_method("kind", method!(ExportInfo::kind, 0))?;
3464
+
3231
3465
  class.define_method("span", method!(ExportInfo::span, 0))?;
3232
3466
 
3233
3467
  let class = module.define_class("SymbolInfo", ruby.class_object())?;
3468
+
3234
3469
  class.define_singleton_method("new", function!(SymbolInfo::new, -1))?;
3470
+
3235
3471
  class.define_method("name", method!(SymbolInfo::name, 0))?;
3472
+
3236
3473
  class.define_method("kind", method!(SymbolInfo::kind, 0))?;
3474
+
3237
3475
  class.define_method("span", method!(SymbolInfo::span, 0))?;
3476
+
3238
3477
  class.define_method("type_annotation", method!(SymbolInfo::type_annotation, 0))?;
3478
+
3239
3479
  class.define_method("doc", method!(SymbolInfo::doc, 0))?;
3240
3480
 
3241
3481
  let class = module.define_class("Diagnostic", ruby.class_object())?;
3482
+
3242
3483
  class.define_singleton_method("new", function!(Diagnostic::new, -1))?;
3484
+
3243
3485
  class.define_method("message", method!(Diagnostic::message, 0))?;
3486
+
3244
3487
  class.define_method("severity", method!(Diagnostic::severity, 0))?;
3488
+
3245
3489
  class.define_method("span", method!(Diagnostic::span, 0))?;
3246
3490
 
3247
3491
  let class = module.define_class("CodeChunk", ruby.class_object())?;
3492
+
3248
3493
  class.define_singleton_method("new", function!(CodeChunk::new, -1))?;
3494
+
3249
3495
  class.define_method("content", method!(CodeChunk::content, 0))?;
3496
+
3250
3497
  class.define_method("start_byte", method!(CodeChunk::start_byte, 0))?;
3498
+
3251
3499
  class.define_method("end_byte", method!(CodeChunk::end_byte, 0))?;
3500
+
3252
3501
  class.define_method("start_line", method!(CodeChunk::start_line, 0))?;
3502
+
3253
3503
  class.define_method("end_line", method!(CodeChunk::end_line, 0))?;
3504
+
3254
3505
  class.define_method("metadata", method!(CodeChunk::metadata, 0))?;
3506
+
3255
3507
  class.define_method("to_s", method!(CodeChunk::to_s, 0))?;
3256
3508
 
3257
3509
  let class = module.define_class("ChunkContext", ruby.class_object())?;
3510
+
3258
3511
  class.define_singleton_method("new", function!(ChunkContext::new, -1))?;
3512
+
3259
3513
  class.define_method("language", method!(ChunkContext::language, 0))?;
3514
+
3260
3515
  class.define_method("chunk_index", method!(ChunkContext::chunk_index, 0))?;
3516
+
3261
3517
  class.define_method("total_chunks", method!(ChunkContext::total_chunks, 0))?;
3518
+
3262
3519
  class.define_method("node_types", method!(ChunkContext::node_types, 0))?;
3520
+
3263
3521
  class.define_method("context_path", method!(ChunkContext::context_path, 0))?;
3522
+
3264
3523
  class.define_method("symbols_defined", method!(ChunkContext::symbols_defined, 0))?;
3524
+
3265
3525
  class.define_method("comments", method!(ChunkContext::comments, 0))?;
3526
+
3266
3527
  class.define_method("docstrings", method!(ChunkContext::docstrings, 0))?;
3528
+
3267
3529
  class.define_method("has_error_nodes", method!(ChunkContext::has_error_nodes, 0))?;
3268
3530
 
3269
3531
  let class = module.define_class("PackConfig", ruby.class_object())?;
3532
+
3270
3533
  class.define_singleton_method("new", function!(PackConfig::new, -1))?;
3534
+
3271
3535
  class.define_method("cache_dir", method!(PackConfig::cache_dir, 0))?;
3536
+
3272
3537
  class.define_method("languages", method!(PackConfig::languages, 0))?;
3538
+
3273
3539
  class.define_method("groups", method!(PackConfig::groups, 0))?;
3274
3540
 
3541
+ let class = module.define_class("Point", ruby.class_object())?;
3542
+
3543
+ class.define_singleton_method("new", function!(Point::new, -1))?;
3544
+
3545
+ class.define_method("row", method!(Point::row, 0))?;
3546
+
3547
+ class.define_method("column", method!(Point::column, 0))?;
3548
+
3549
+ let class = module.define_class("ByteRange", ruby.class_object())?;
3550
+
3551
+ class.define_singleton_method("new", function!(ByteRange::new, -1))?;
3552
+
3553
+ class.define_method("start", method!(ByteRange::start, 0))?;
3554
+
3555
+ class.define_method("end", method!(ByteRange::end, 0))?;
3556
+
3557
+ let class = module.define_class("Parser", ruby.class_object())?;
3558
+
3559
+ let class = module.define_class("Tree", ruby.class_object())?;
3560
+
3561
+ class.define_method("root_node", method!(Tree::root_node, 0))?;
3562
+
3563
+ class.define_method("walk", method!(Tree::walk, 0))?;
3564
+
3565
+ let class = module.define_class("Node", ruby.class_object())?;
3566
+
3567
+ class.define_method("clone", method!(Node::clone, 0))?;
3568
+
3569
+ class.define_method("kind", method!(Node::kind, 0))?;
3570
+
3571
+ class.define_method("kind_id", method!(Node::kind_id, 0))?;
3572
+
3573
+ class.define_method("start_byte", method!(Node::start_byte, 0))?;
3574
+
3575
+ class.define_method("end_byte", method!(Node::end_byte, 0))?;
3576
+
3577
+ class.define_method("byte_range", method!(Node::byte_range, 0))?;
3578
+
3579
+ class.define_method("start_position", method!(Node::start_position, 0))?;
3580
+
3581
+ class.define_method("end_position", method!(Node::end_position, 0))?;
3582
+
3583
+ class.define_method("is_named", method!(Node::is_named, 0))?;
3584
+
3585
+ class.define_method("is_error", method!(Node::is_error, 0))?;
3586
+
3587
+ class.define_method("is_missing", method!(Node::is_missing, 0))?;
3588
+
3589
+ class.define_method("is_extra", method!(Node::is_extra, 0))?;
3590
+
3591
+ class.define_method("has_error", method!(Node::has_error, 0))?;
3592
+
3593
+ class.define_method("parent", method!(Node::parent, 0))?;
3594
+
3595
+ class.define_method("child", method!(Node::child, 1))?;
3596
+
3597
+ class.define_method("child_count", method!(Node::child_count, 0))?;
3598
+
3599
+ class.define_method("named_child", method!(Node::named_child, 1))?;
3600
+
3601
+ class.define_method("named_child_count", method!(Node::named_child_count, 0))?;
3602
+
3603
+ class.define_method("child_by_field_name", method!(Node::child_by_field_name, 1))?;
3604
+
3605
+ class.define_method("to_sexp", method!(Node::to_sexp, 0))?;
3606
+
3607
+ class.define_method("walk", method!(Node::walk, 0))?;
3608
+
3609
+ let class = module.define_class("TreeCursor", ruby.class_object())?;
3610
+
3611
+ class.define_method("node", method!(TreeCursor::node, 0))?;
3612
+
3613
+ class.define_method("field_name", method!(TreeCursor::field_name, 0))?;
3614
+
3275
3615
  let class = module.define_class("ProcessConfig", ruby.class_object())?;
3616
+
3276
3617
  class.define_singleton_method("new", function!(ProcessConfig::new, -1))?;
3618
+
3277
3619
  class.define_method("language", method!(ProcessConfig::language, 0))?;
3620
+
3278
3621
  class.define_method("structure", method!(ProcessConfig::structure, 0))?;
3622
+
3279
3623
  class.define_method("imports", method!(ProcessConfig::imports, 0))?;
3624
+
3280
3625
  class.define_method("exports", method!(ProcessConfig::exports, 0))?;
3626
+
3281
3627
  class.define_method("comments", method!(ProcessConfig::comments, 0))?;
3628
+
3282
3629
  class.define_method("docstrings", method!(ProcessConfig::docstrings, 0))?;
3630
+
3283
3631
  class.define_method("symbols", method!(ProcessConfig::symbols, 0))?;
3632
+
3284
3633
  class.define_method("diagnostics", method!(ProcessConfig::diagnostics, 0))?;
3634
+
3285
3635
  class.define_method("chunk_max_size", method!(ProcessConfig::chunk_max_size, 0))?;
3636
+
3286
3637
  class.define_method("with_chunking", method!(ProcessConfig::with_chunking, 1))?;
3638
+
3287
3639
  class.define_method("all", method!(ProcessConfig::all, 0))?;
3640
+
3288
3641
  class.define_method("minimal", method!(ProcessConfig::minimal, 0))?;
3289
3642
 
3290
3643
  let class = module.define_class("LanguageRegistry", ruby.class_object())?;
3291
- class.define_method("add_extra_libs_dir", method!(LanguageRegistry::add_extra_libs_dir, 1))?;
3644
+
3292
3645
  class.define_method("get_language", method!(LanguageRegistry::get_language, 1))?;
3646
+
3293
3647
  class.define_method("available_languages", method!(LanguageRegistry::available_languages, 0))?;
3294
- class.define_method("has_language", method!(LanguageRegistry::has_language, 1))?;
3295
- class.define_method("language_count", method!(LanguageRegistry::language_count, 0))?;
3296
- class.define_method("process", method!(LanguageRegistry::process, 2))?;
3297
3648
 
3298
- let class = module.define_class("ParserManifest", ruby.class_object())?;
3299
- class.define_singleton_method("new", function!(ParserManifest::new, -1))?;
3300
- class.define_method("version", method!(ParserManifest::version, 0))?;
3301
- class.define_method("platforms", method!(ParserManifest::platforms, 0))?;
3302
- class.define_method("languages", method!(ParserManifest::languages, 0))?;
3303
- class.define_method("groups", method!(ParserManifest::groups, 0))?;
3649
+ class.define_method("has_language", method!(LanguageRegistry::has_language, 1))?;
3304
3650
 
3305
- let class = module.define_class("PlatformBundle", ruby.class_object())?;
3306
- class.define_singleton_method("new", function!(PlatformBundle::new, -1))?;
3307
- class.define_method("url", method!(PlatformBundle::url, 0))?;
3308
- class.define_method("sha256", method!(PlatformBundle::sha256, 0))?;
3309
- class.define_method("size", method!(PlatformBundle::size, 0))?;
3651
+ class.define_method("language_count", method!(LanguageRegistry::language_count, 0))?;
3310
3652
 
3311
- let class = module.define_class("LanguageInfo", ruby.class_object())?;
3312
- class.define_singleton_method("new", function!(LanguageInfo::new, -1))?;
3313
- class.define_method("group", method!(LanguageInfo::group, 0))?;
3314
- class.define_method("size", method!(LanguageInfo::size, 0))?;
3653
+ class.define_method("process", method!(LanguageRegistry::process, 2))?;
3315
3654
 
3316
3655
  let class = module.define_class("DownloadManager", ruby.class_object())?;
3317
- class.define_method("cache_dir", method!(DownloadManager::cache_dir, 0))?;
3656
+
3318
3657
  class.define_method("installed_languages", method!(DownloadManager::installed_languages, 0))?;
3319
- class.define_method("ensure_languages", method!(DownloadManager::ensure_languages, 1))?;
3320
- class.define_method("ensure_group", method!(DownloadManager::ensure_group, 1))?;
3321
- class.define_method("lib_path", method!(DownloadManager::lib_path, 1))?;
3322
- class.define_method("fetch_manifest", method!(DownloadManager::fetch_manifest, 0))?;
3658
+
3323
3659
  class.define_method(
3324
3660
  "download_all_best_effort",
3325
3661
  method!(DownloadManager::download_all_best_effort, 0),
3326
3662
  )?;
3663
+
3327
3664
  class.define_method("clean_cache", method!(DownloadManager::clean_cache, 0))?;
3328
3665
 
3329
3666
  let _class = module.define_class("Language", ruby.class_object())?;
3330
3667
 
3331
- let _class = module.define_class("Parser", ruby.class_object())?;
3332
-
3333
- let _class = module.define_class("Tree", ruby.class_object())?;
3334
-
3335
3668
  module.define_module_function(
3336
3669
  "detect_language_from_extension",
3337
3670
  function!(detect_language_from_extension, 1),
3338
3671
  )?;
3672
+
3339
3673
  module.define_module_function("detect_language_from_path", function!(detect_language_from_path, 1))?;
3674
+
3340
3675
  module.define_module_function(
3341
3676
  "detect_language_from_content",
3342
3677
  function!(detect_language_from_content, 1),
3343
3678
  )?;
3679
+
3344
3680
  module.define_module_function("get_highlights_query", function!(get_highlights_query, 1))?;
3681
+
3345
3682
  module.define_module_function("get_injections_query", function!(get_injections_query, 1))?;
3683
+
3346
3684
  module.define_module_function("get_locals_query", function!(get_locals_query, 1))?;
3685
+
3347
3686
  module.define_module_function("get_language", function!(get_language, 1))?;
3687
+
3348
3688
  module.define_module_function("get_parser", function!(get_parser, 1))?;
3689
+
3349
3690
  module.define_module_function("detect_language", function!(detect_language, 1))?;
3691
+
3350
3692
  module.define_module_function("available_languages", function!(available_languages, 0))?;
3693
+
3351
3694
  module.define_module_function("has_language", function!(has_language, 1))?;
3695
+
3352
3696
  module.define_module_function("language_count", function!(language_count, 0))?;
3697
+
3353
3698
  module.define_module_function("process", function!(process, -1))?;
3699
+
3354
3700
  module.define_module_function("init", function!(init, -1))?;
3701
+
3355
3702
  module.define_module_function("configure", function!(configure, -1))?;
3703
+
3356
3704
  module.define_module_function("download", function!(download, 1))?;
3705
+
3357
3706
  module.define_module_function("download_all", function!(download_all, 0))?;
3707
+
3708
+ module.define_module_function("download_group", function!(download_group, 1))?;
3709
+
3358
3710
  module.define_module_function("manifest_languages", function!(manifest_languages, 0))?;
3711
+
3359
3712
  module.define_module_function("downloaded_languages", function!(downloaded_languages, 0))?;
3713
+
3360
3714
  module.define_module_function("clean_cache", function!(clean_cache, 0))?;
3715
+
3361
3716
  module.define_module_function("cache_dir", function!(cache_dir, 0))?;
3362
3717
 
3363
3718
  Ok(())