diff options
author | Adolfo OchagavĂa <[email protected]> | 2018-10-11 15:25:35 +0100 |
---|---|---|
committer | Adolfo OchagavĂa <[email protected]> | 2018-10-11 15:25:35 +0100 |
commit | f88e13f5393c75b02c3619ec432675c3316ee6e5 (patch) | |
tree | 9a4d2611dec98a083ae2f6b99a04f68962bf2f01 /crates/ra_syntax/src/ast | |
parent | 27a86cb7df5e1764c85f5eeb8bb85885072f782e (diff) |
Use Comment wrapper
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 18 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/mod.rs | 43 |
2 files changed, 61 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 2db6dff1b..b0b855eb4 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -227,6 +227,24 @@ impl<'a> AstNode<'a> for CastExpr<'a> { | |||
227 | 227 | ||
228 | impl<'a> CastExpr<'a> {} | 228 | impl<'a> CastExpr<'a> {} |
229 | 229 | ||
230 | // Comment | ||
231 | #[derive(Debug, Clone, Copy)] | ||
232 | pub struct Comment<'a> { | ||
233 | syntax: SyntaxNodeRef<'a>, | ||
234 | } | ||
235 | |||
236 | impl<'a> AstNode<'a> for Comment<'a> { | ||
237 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
238 | match syntax.kind() { | ||
239 | COMMENT => Some(Comment { syntax }), | ||
240 | _ => None, | ||
241 | } | ||
242 | } | ||
243 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | ||
244 | } | ||
245 | |||
246 | impl<'a> Comment<'a> {} | ||
247 | |||
230 | // Condition | 248 | // Condition |
231 | #[derive(Debug, Clone, Copy)] | 249 | #[derive(Debug, Clone, Copy)] |
232 | pub struct Condition<'a> { | 250 | pub struct Condition<'a> { |
diff --git a/crates/ra_syntax/src/ast/mod.rs b/crates/ra_syntax/src/ast/mod.rs index c1570b868..10dac72e5 100644 --- a/crates/ra_syntax/src/ast/mod.rs +++ b/crates/ra_syntax/src/ast/mod.rs | |||
@@ -99,6 +99,49 @@ impl<'a> Lifetime<'a> { | |||
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
102 | impl<'a> Comment<'a> { | ||
103 | pub fn text(&self) -> SmolStr { | ||
104 | self.syntax().leaf_text().unwrap().clone() | ||
105 | } | ||
106 | |||
107 | pub fn flavor(&self) -> CommentFlavor { | ||
108 | let text = self.text(); | ||
109 | if text.starts_with("///") { | ||
110 | CommentFlavor::Doc | ||
111 | } else if text.starts_with("//!") { | ||
112 | CommentFlavor::ModuleDoc | ||
113 | } else if text.starts_with("//") { | ||
114 | CommentFlavor::Line | ||
115 | } else { | ||
116 | CommentFlavor::Multiline | ||
117 | } | ||
118 | } | ||
119 | |||
120 | pub fn prefix(&self) -> &'static str { | ||
121 | self.flavor().prefix() | ||
122 | } | ||
123 | } | ||
124 | |||
125 | #[derive(Debug)] | ||
126 | pub enum CommentFlavor { | ||
127 | Line, | ||
128 | Doc, | ||
129 | ModuleDoc, | ||
130 | Multiline | ||
131 | } | ||
132 | |||
133 | impl CommentFlavor { | ||
134 | pub fn prefix(&self) -> &'static str { | ||
135 | use self::CommentFlavor::*; | ||
136 | match *self { | ||
137 | Line => "//", | ||
138 | Doc => "///", | ||
139 | ModuleDoc => "//!", | ||
140 | Multiline => "/*" | ||
141 | } | ||
142 | } | ||
143 | } | ||
144 | |||
102 | impl<'a> Name<'a> { | 145 | impl<'a> Name<'a> { |
103 | pub fn text(&self) -> SmolStr { | 146 | pub fn text(&self) -> SmolStr { |
104 | let ident = self.syntax().first_child() | 147 | let ident = self.syntax().first_child() |