aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/typing/on_enter.rs38
1 files changed, 35 insertions, 3 deletions
diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs
index 7c979694d..6bcf2d72b 100644
--- a/crates/ra_ide/src/typing/on_enter.rs
+++ b/crates/ra_ide/src/typing/on_enter.rs
@@ -32,8 +32,8 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour
32 return None; 32 return None;
33 } 33 }
34 34
35 // Continuing non-doc line comments (like this one :) ) is annoying 35 // Continuing single-line non-doc comments (like this one :) ) is annoying
36 if prefix == "//" && comment_range.end() == position.offset { 36 if prefix == "//" && comment_range.end() == position.offset && !followed_by_comment(&comment) {
37 return None; 37 return None;
38 } 38 }
39 39
@@ -51,6 +51,17 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour
51 ) 51 )
52} 52}
53 53
54fn followed_by_comment(comment: &ast::Comment) -> bool {
55 let ws = match comment.syntax().next_token().and_then(ast::Whitespace::cast) {
56 Some(it) => it,
57 None => return false,
58 };
59 if ws.spans_multiple_lines() {
60 return false;
61 }
62 ws.syntax().next_token().and_then(ast::Comment::cast).is_some()
63}
64
54fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option<SmolStr> { 65fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option<SmolStr> {
55 let ws = match file.syntax().token_at_offset(token.text_range().start()) { 66 let ws = match file.syntax().token_at_offset(token.text_range().start()) {
56 TokenAtOffset::Between(l, r) => { 67 TokenAtOffset::Between(l, r) => {
@@ -152,7 +163,7 @@ fn foo() {
152 } 163 }
153 164
154 #[test] 165 #[test]
155 fn continues_code_comment_in_the_middle() { 166 fn continues_code_comment_in_the_middle_of_line() {
156 do_check( 167 do_check(
157 r" 168 r"
158fn main() { 169fn main() {
@@ -171,6 +182,27 @@ fn main() {
171 } 182 }
172 183
173 #[test] 184 #[test]
185 fn continues_code_comment_in_the_middle_several_lines() {
186 do_check(
187 r"
188fn main() {
189 // Fix<|>
190 // me
191 let x = 1 + 1;
192}
193",
194 r"
195fn main() {
196 // Fix
197 // <|>
198 // me
199 let x = 1 + 1;
200}
201",
202 );
203 }
204
205 #[test]
174 fn does_not_continue_end_of_code_comment() { 206 fn does_not_continue_end_of_code_comment() {
175 do_check_noop( 207 do_check_noop(
176 r" 208 r"