diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-02 08:04:38 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-02 08:04:38 +0000 |
commit | 2183d65c97c2487f93278efa4f4dc66e42706119 (patch) | |
tree | 751d4126cbac039ffe2913c59ec283b5dd3fb4d2 /crates/syntax/src/ast/edit.rs | |
parent | b7fa6dfabc7a5326c78aa19807fd6c30ca5d1b4b (diff) | |
parent | f5cde97aaeb00b8422abb0ade0e5c103252c54a0 (diff) |
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 <[email protected]>
Diffstat (limited to 'crates/syntax/src/ast/edit.rs')
-rw-r--r-- | crates/syntax/src/ast/edit.rs | 11 |
1 files changed, 7 insertions, 4 deletions
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<u8> for IndentLevel { | |||
595 | 595 | ||
596 | impl IndentLevel { | 596 | impl IndentLevel { |
597 | pub fn from_node(node: &SyntaxNode) -> IndentLevel { | 597 | pub fn from_node(node: &SyntaxNode) -> IndentLevel { |
598 | let first_token = match node.first_token() { | 598 | match node.first_token() { |
599 | Some(it) => it, | 599 | Some(it) => Self::from_token(&it), |
600 | None => return IndentLevel(0), | 600 | None => return IndentLevel(0), |
601 | }; | 601 | } |
602 | for ws in prev_tokens(first_token).filter_map(ast::Whitespace::cast) { | 602 | } |
603 | |||
604 | pub fn from_token(token: &SyntaxToken) -> IndentLevel { | ||
605 | for ws in prev_tokens(token.clone()).filter_map(ast::Whitespace::cast) { | ||
603 | let text = ws.syntax().text(); | 606 | let text = ws.syntax().text(); |
604 | if let Some(pos) = text.rfind('\n') { | 607 | if let Some(pos) = text.rfind('\n') { |
605 | let level = text[pos + 1..].chars().count() / 4; | 608 | let level = text[pos + 1..].chars().count() / 4; |