mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Use Comment wrapper
This commit is contained in:
parent
27a86cb7df
commit
f88e13f539
4 changed files with 78 additions and 36 deletions
|
@ -99,6 +99,49 @@ impl<'a> Lifetime<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Comment<'a> {
|
||||
pub fn text(&self) -> SmolStr {
|
||||
self.syntax().leaf_text().unwrap().clone()
|
||||
}
|
||||
|
||||
pub fn flavor(&self) -> CommentFlavor {
|
||||
let text = self.text();
|
||||
if text.starts_with("///") {
|
||||
CommentFlavor::Doc
|
||||
} else if text.starts_with("//!") {
|
||||
CommentFlavor::ModuleDoc
|
||||
} else if text.starts_with("//") {
|
||||
CommentFlavor::Line
|
||||
} else {
|
||||
CommentFlavor::Multiline
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prefix(&self) -> &'static str {
|
||||
self.flavor().prefix()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CommentFlavor {
|
||||
Line,
|
||||
Doc,
|
||||
ModuleDoc,
|
||||
Multiline
|
||||
}
|
||||
|
||||
impl CommentFlavor {
|
||||
pub fn prefix(&self) -> &'static str {
|
||||
use self::CommentFlavor::*;
|
||||
match *self {
|
||||
Line => "//",
|
||||
Doc => "///",
|
||||
ModuleDoc => "//!",
|
||||
Multiline => "/*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Name<'a> {
|
||||
pub fn text(&self) -> SmolStr {
|
||||
let ident = self.syntax().first_child()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue