File tree Expand file tree Collapse file tree 1 file changed +35
-3
lines changed Expand file tree Collapse file tree 1 file changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,8 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour
32
32
return None ;
33
33
}
34
34
35
- // Continuing non-doc line comments (like this one :) ) is annoying
36
- if prefix == "//" && comment_range. end ( ) == position. offset {
35
+ // Continuing single-line non-doc comments (like this one :) ) is annoying
36
+ if prefix == "//" && comment_range. end ( ) == position. offset && ! followed_by_comment ( & comment ) {
37
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
54
+ fn 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
+
54
65
fn node_indent ( file : & SourceFile , token : & SyntaxToken ) -> Option < SmolStr > {
55
66
let ws = match file. syntax ( ) . token_at_offset ( token. text_range ( ) . start ( ) ) {
56
67
TokenAtOffset :: Between ( l, r) => {
@@ -152,7 +163,7 @@ fn foo() {
152
163
}
153
164
154
165
#[ test]
155
- fn continues_code_comment_in_the_middle ( ) {
166
+ fn continues_code_comment_in_the_middle_of_line ( ) {
156
167
do_check (
157
168
r"
158
169
fn main() {
@@ -170,6 +181,27 @@ fn main() {
170
181
) ;
171
182
}
172
183
184
+ #[ test]
185
+ fn continues_code_comment_in_the_middle_several_lines ( ) {
186
+ do_check (
187
+ r"
188
+ fn main() {
189
+ // Fix<|>
190
+ // me
191
+ let x = 1 + 1;
192
+ }
193
+ " ,
194
+ r"
195
+ fn main() {
196
+ // Fix
197
+ // <|>
198
+ // me
199
+ let x = 1 + 1;
200
+ }
201
+ " ,
202
+ ) ;
203
+ }
204
+
173
205
#[ test]
174
206
fn does_not_continue_end_of_code_comment ( ) {
175
207
do_check_noop (
You can’t perform that action at this time.
0 commit comments