mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Merge #7777
7777: Implement line<->block comment assist r=Veykril a=djrenren Fixes: https://github.com/rust-analyzer/rust-analyzer/issues/6515 Co-authored-by: John Renner <john@jrenner.net>
This commit is contained in:
commit
2183d65c97
4 changed files with 430 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