From 9eecba4dbf8e18ddb9f7f906af468e35a11d28a4 Mon Sep 17 00:00:00 2001 From: John Renner Date: Wed, 24 Feb 2021 11:25:10 -0800 Subject: Implement line<->block comment assist --- crates/syntax/src/ast/edit.rs | 11 +++++++---- crates/syntax/src/ast/token_ext.rs | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'crates/syntax') diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs index 824ebf41c..0b3b76d4a 100644 --- a/crates/syntax/src/ast/edit.rs +++ b/crates/syntax/src/ast/edit.rs @@ -595,11 +595,14 @@ impl ops::Add 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; diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs index 044e3e5e8..977eb8181 100644 --- a/crates/syntax/src/ast/token_ext.rs +++ b/crates/syntax/src/ast/token_ext.rs @@ -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) }), -- cgit v1.2.3