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:
bors[bot] 2021-03-02 08:04:38 +00:00 committed by GitHub
commit 2183d65c97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 430 additions and 5 deletions

View file

@ -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;

View file

@ -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) }),