@@ -61,16 +61,28 @@ pub struct SyntaxEdit {
61
61
}
62
62
63
63
impl SyntaxEdit {
64
+ /// Root of the modified syntax tree
64
65
pub fn root ( & self ) -> & SyntaxNode {
65
66
& self . root
66
67
}
67
68
69
+ /// Which syntax elements in the modified syntax tree were modified as part
70
+ /// of the edit.
71
+ ///
72
+ /// Note that for syntax nodes, only the upper-most parent of a set of
73
+ /// changes is included, not any child elements that may have been modified.
68
74
pub fn changed_elements ( & self ) -> & [ SyntaxElement ] {
69
75
self . changed_elements . as_slice ( )
70
76
}
71
77
72
- pub fn find_annotation ( & self , annotation : SyntaxAnnotation ) -> Option < & [ SyntaxElement ] > {
73
- self . annotations . get ( & annotation) . as_ref ( ) . map ( |it| it. as_slice ( ) )
78
+ /// Finds which syntax elements have been annotated with the given
79
+ /// annotation.
80
+ ///
81
+ /// Note that an annotation might not appear in the modified syntax tree if
82
+ /// the syntax elements that were annotated did not make it into the final
83
+ /// syntax tree.
84
+ pub fn find_annotation ( & self , annotation : SyntaxAnnotation ) -> & [ SyntaxElement ] {
85
+ self . annotations . get ( & annotation) . as_ref ( ) . map_or ( & [ ] , |it| it. as_slice ( ) )
74
86
}
75
87
}
76
88
@@ -83,9 +95,8 @@ impl SyntaxAnnotation {
83
95
pub fn new ( ) -> Self {
84
96
static COUNTER : AtomicU32 = AtomicU32 :: new ( 1 ) ;
85
97
86
- // We want the id to be unique across threads, but we don't want to
87
- // tie it to other `SeqCst` operations.
88
- let id = COUNTER . fetch_add ( 1 , Ordering :: AcqRel ) ;
98
+ // Only consistency within a thread matters, as SyntaxElements are !Send
99
+ let id = COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
89
100
90
101
Self ( NonZeroU32 :: new ( id) . expect ( "syntax annotation id overflow" ) )
91
102
}
@@ -328,6 +339,6 @@ mod tests {
328
339
329
340
let expect = expect ! [ ] ;
330
341
expect. assert_eq ( & edit. root . to_string ( ) ) ;
331
- assert_eq ! ( edit. find_annotation( placeholder_snippet) . map ( |it| it . len( ) ) , Some ( 2 ) ) ;
342
+ assert_eq ! ( edit. find_annotation( placeholder_snippet) . len( ) , 2 ) ;
332
343
}
333
344
}
0 commit comments