File tree Expand file tree Collapse file tree 2 files changed +59
-4
lines changed
crates/ide_db/src/helpers Expand file tree Collapse file tree 2 files changed +59
-4
lines changed Original file line number Diff line number Diff line change @@ -401,7 +401,7 @@ fn insert_use_(
401401 . children_with_tokens ( )
402402 . filter ( |child| match child {
403403 NodeOrToken :: Node ( node) => is_inner_attribute ( node. clone ( ) ) ,
404- NodeOrToken :: Token ( token) => is_inner_comment ( token. clone ( ) ) ,
404+ NodeOrToken :: Token ( token) => is_comment ( token. clone ( ) ) ,
405405 } )
406406 . last ( )
407407 {
@@ -440,7 +440,6 @@ fn is_inner_attribute(node: SyntaxNode) -> bool {
440440 ast:: Attr :: cast ( node) . map ( |attr| attr. kind ( ) ) == Some ( ast:: AttrKind :: Inner )
441441}
442442
443- fn is_inner_comment ( token : SyntaxToken ) -> bool {
444- ast:: Comment :: cast ( token) . and_then ( |comment| comment. kind ( ) . doc )
445- == Some ( ast:: CommentPlacement :: Inner )
443+ fn is_comment ( token : SyntaxToken ) -> bool {
444+ ast:: Comment :: cast ( token) . is_some ( )
446445}
Original file line number Diff line number Diff line change @@ -390,6 +390,62 @@ use foo::bar::Baz;"#,
390390 ) ;
391391}
392392
393+ #[ test]
394+ fn inserts_after_single_line_comments ( ) {
395+ check_none (
396+ "foo::bar::Baz" ,
397+ "// Represents a possible license header and/or general module comments" ,
398+ r#"// Represents a possible license header and/or general module comments
399+
400+ use foo::bar::Baz;"# ,
401+ ) ;
402+ }
403+
404+ #[ test]
405+ fn inserts_after_multiple_single_line_comments ( ) {
406+ check_none (
407+ "foo::bar::Baz" ,
408+ "// Represents a possible license header and/or general module comments
409+ // Second single-line comment
410+ // Third single-line comment" ,
411+ r#"// Represents a possible license header and/or general module comments
412+ // Second single-line comment
413+ // Third single-line comment
414+
415+ use foo::bar::Baz;"# ,
416+ ) ;
417+ }
418+
419+ #[ test]
420+ fn inserts_before_single_line_item_comments ( ) {
421+ check_none (
422+ "foo::bar::Baz" ,
423+ r#"// Represents a comment about a function
424+ fn foo() {}"# ,
425+ r#"use foo::bar::Baz;
426+
427+ // Represents a comment about a function
428+ fn foo() {}"# ,
429+ ) ;
430+ }
431+
432+ #[ test]
433+ fn inserts_after_single_line_header_comments_and_before_item ( ) {
434+ check_none (
435+ "foo::bar::Baz" ,
436+ r#"// Represents a possible license header
437+ // Line two of possible license header
438+
439+ fn foo() {}"# ,
440+ r#"// Represents a possible license header
441+ // Line two of possible license header
442+
443+ use foo::bar::Baz;
444+
445+ fn foo() {}"# ,
446+ ) ;
447+ }
448+
393449#[ test]
394450fn inserts_after_multiline_inner_comments ( ) {
395451 check_none (
You can’t perform that action at this time.
0 commit comments