mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Implement line<->block comment assist
This commit is contained in:
parent
a307e4f31f
commit
9eecba4dbf
4 changed files with 427 additions and 5 deletions
|
@ -595,11 +595,14 @@ impl ops::Add<u8> for IndentLevel {
|
|||
|
||||
impl IndentLevel {
|
||||
pub fn from_node(node: &SyntaxNode) -> IndentLevel {
|
||||
let first_token = match node.first_token() {
|
||||
Some(it) => it,
|
||||
match node.first_token() {
|
||||
Some(it) => Self::from_token(&it),
|
||||
None => return IndentLevel(0),
|
||||
};
|
||||
for ws in prev_tokens(first_token).filter_map(ast::Whitespace::cast) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_token(token: &SyntaxToken) -> IndentLevel {
|
||||
for ws in prev_tokens(token.clone()).filter_map(ast::Whitespace::cast) {
|
||||
let text = ws.syntax().text();
|
||||
if let Some(pos) = text.rfind('\n') {
|
||||
let level = text[pos + 1..].chars().count() / 4;
|
||||
|
|
|
@ -85,8 +85,9 @@ pub enum CommentPlacement {
|
|||
}
|
||||
|
||||
impl CommentKind {
|
||||
const BY_PREFIX: [(&'static str, CommentKind); 8] = [
|
||||
const BY_PREFIX: [(&'static str, CommentKind); 9] = [
|
||||
("/**/", CommentKind { shape: CommentShape::Block, doc: None }),
|
||||
("/***", CommentKind { shape: CommentShape::Block, doc: None }),
|
||||
("////", CommentKind { shape: CommentShape::Line, doc: None }),
|
||||
("///", CommentKind { shape: CommentShape::Line, doc: Some(CommentPlacement::Outer) }),
|
||||
("//!", CommentKind { shape: CommentShape::Line, doc: Some(CommentPlacement::Inner) }),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue