Skip to content

Commit 78587c2

Browse files
committed
Move doc comments to the API module
1 parent 41bc29c commit 78587c2

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

src/api.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ impl<L: Language> SyntaxNode<L> {
149149
pub fn new_root(green: GreenNode) -> SyntaxNode<L> {
150150
SyntaxNode::from(cursor::SyntaxNode::new_root(green))
151151
}
152+
/// Returns a green tree, equal to the green tree this node
153+
/// belongs two, except with this node substitute. The complexity
154+
/// of operation is proportional to the depth of the tree
152155
pub fn replace_with(&self, replacement: GreenNode) -> GreenNode {
153156
self.raw.replace_with(replacement)
154157
}
@@ -217,10 +220,12 @@ impl<L: Language> SyntaxNode<L> {
217220
self.raw.prev_sibling_or_token().map(NodeOrToken::from)
218221
}
219222

223+
/// Return the leftmost token in the subtree of this node.
220224
pub fn first_token(&self) -> Option<SyntaxToken<L>> {
221225
self.raw.first_token().map(SyntaxToken::from)
222226
}
223227

228+
/// Return the rightmost token in the subtree of this node.
224229
pub fn last_token(&self) -> Option<SyntaxToken<L>> {
225230
self.raw.last_token().map(SyntaxToken::from)
226231
}
@@ -244,24 +249,37 @@ impl<L: Language> SyntaxNode<L> {
244249
self.raw.descendants_with_tokens().map(NodeOrToken::from)
245250
}
246251

252+
/// Traverse the subtree rooted at the current node (including the current
253+
/// node) in preorder, excluding tokens.
247254
pub fn preorder(&self) -> impl Iterator<Item = WalkEvent<SyntaxNode<L>>> {
248255
self.raw.preorder().map(|event| event.map(SyntaxNode::from))
249256
}
250257

258+
/// Traverse the subtree rooted at the current node (including the current
259+
/// node) in preorder, including tokens.
251260
pub fn preorder_with_tokens(&self) -> impl Iterator<Item = WalkEvent<SyntaxElement<L>>> {
252261
self.raw.preorder_with_tokens().map(|event| event.map(NodeOrToken::from))
253262
}
254263

264+
/// Find a token in the subtree corresponding to this node, which covers the offset.
265+
/// Precondition: offset must be withing node's range.
255266
pub fn token_at_offset(&self, offset: TextSize) -> TokenAtOffset<SyntaxToken<L>> {
256267
self.raw.token_at_offset(offset).map(SyntaxToken::from)
257268
}
258269

270+
/// Return the deepest node or token in the current subtree that fully
271+
/// contains the range. If the range is empty and is contained in two leaf
272+
/// nodes, either one can be returned. Precondition: range must be contained
273+
/// withing the current node
259274
pub fn covering_element(&self, range: TextRange) -> SyntaxElement<L> {
260275
NodeOrToken::from(self.raw.covering_element(range))
261276
}
262277
}
263278

264279
impl<L: Language> SyntaxToken<L> {
280+
/// Returns a green tree, equal to the green tree this token
281+
/// belongs two, except with this token substitute. The complexity
282+
/// of operation is proportional to the depth of the tree
265283
pub fn replace_with(&self, new_token: GreenToken) -> GreenNode {
266284
self.raw.replace_with(new_token)
267285
}
@@ -305,10 +323,12 @@ impl<L: Language> SyntaxToken<L> {
305323
self.raw.siblings_with_tokens(direction).map(SyntaxElement::from)
306324
}
307325

326+
/// Next token in the tree (i.e, not necessary a sibling).
308327
pub fn next_token(&self) -> Option<SyntaxToken<L>> {
309328
self.raw.next_token().map(SyntaxToken::from)
310329
}
311330

331+
/// Previous token in the tree (i.e, not necessary a sibling).
312332
pub fn prev_token(&self) -> Option<SyntaxToken<L>> {
313333
self.raw.prev_token().map(SyntaxToken::from)
314334
}

src/cursor.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@ impl SyntaxNode {
209209
SyntaxNode::new(data)
210210
}
211211

212-
/// Returns a green tree, equal to the green tree this node
213-
/// belongs two, except with this node substitute. The complexity
214-
/// of operation is proportional to the depth of the tree
215212
pub fn replace_with(&self, replacement: GreenNode) -> GreenNode {
216213
assert_eq!(self.kind(), replacement.kind());
217214
match self.0.kind.as_child() {
@@ -334,13 +331,11 @@ impl SyntaxNode {
334331
Some(SyntaxElement::new(element, parent.clone(), index as u32, offset))
335332
}
336333

337-
/// Return the leftmost token in the subtree of this node
338334
#[inline]
339335
pub fn first_token(&self) -> Option<SyntaxToken> {
340336
self.first_child_or_token()?.first_token()
341337
}
342338

343-
/// Return the rightmost token in the subtree of this node
344339
#[inline]
345340
pub fn last_token(&self) -> Option<SyntaxToken> {
346341
self.last_child_or_token()?.last_token()
@@ -378,8 +373,6 @@ impl SyntaxNode {
378373
})
379374
}
380375

381-
/// Traverse the subtree rooted at the current node (including the current
382-
/// node) in preorder, excluding tokens.
383376
#[inline]
384377
pub fn preorder(&self) -> impl Iterator<Item = WalkEvent<SyntaxNode>> {
385378
let this = self.clone();
@@ -403,8 +396,6 @@ impl SyntaxNode {
403396
})
404397
}
405398

406-
/// Traverse the subtree rooted at the current node (including the current
407-
/// node) in preorder, including tokens.
408399
#[inline]
409400
pub fn preorder_with_tokens<'a>(&'a self) -> impl Iterator<Item = WalkEvent<SyntaxElement>> {
410401
let start: SyntaxElement = self.clone().into();
@@ -431,8 +422,6 @@ impl SyntaxNode {
431422
})
432423
}
433424

434-
/// Find a token in the subtree corresponding to this node, which covers the offset.
435-
/// Precondition: offset must be withing node's range.
436425
pub fn token_at_offset(&self, offset: TextSize) -> TokenAtOffset<SyntaxToken> {
437426
// TODO: this could be faster if we first drill-down to node, and only
438427
// then switch to token search. We should also replace explicit
@@ -470,10 +459,6 @@ impl SyntaxNode {
470459
}
471460
}
472461

473-
/// Return the deepest node or token in the current subtree that fully
474-
/// contains the range. If the range is empty and is contained in two leaf
475-
/// nodes, either one can be returned. Precondition: range must be contained
476-
/// withing the current node
477462
pub fn covering_element(&self, range: TextRange) -> SyntaxElement {
478463
let mut res: SyntaxElement = self.clone().into();
479464
loop {
@@ -504,9 +489,6 @@ impl SyntaxToken {
504489
SyntaxToken { parent, index, offset }
505490
}
506491

507-
/// Returns a green tree, equal to the green tree this token
508-
/// belongs two, except with this token substitute. The complexity
509-
/// of operation is proportional to the depth of the tree
510492
pub fn replace_with(&self, replacement: GreenToken) -> GreenNode {
511493
assert_eq!(self.kind(), replacement.kind());
512494
let mut replacement = Some(replacement);
@@ -580,7 +562,6 @@ impl SyntaxToken {
580562
})
581563
}
582564

583-
/// Next token in the tree (i.e, not necessary a sibling)
584565
pub fn next_token(&self) -> Option<SyntaxToken> {
585566
match self.next_sibling_or_token() {
586567
Some(element) => element.first_token(),
@@ -591,7 +572,7 @@ impl SyntaxToken {
591572
.and_then(|element| element.first_token()),
592573
}
593574
}
594-
/// Previous token in the tree (i.e, not necessary a sibling)
575+
595576
pub fn prev_token(&self) -> Option<SyntaxToken> {
596577
match self.prev_sibling_or_token() {
597578
Some(element) => element.last_token(),

0 commit comments

Comments
 (0)