@@ -478,7 +478,7 @@ final class LocalSwiftTests: XCTestCase {
478
478
// Expected Fix-it: Replace `let a` with `_` because it's never used
479
479
let expectedTextEdit = TextEdit ( range: Position ( line: 1 , utf16index: 7 ) ..< Position ( line: 1 , utf16index: 7 ) , newText: " ? " )
480
480
XCTAssertEqual ( fixit, CodeAction (
481
- title: " Insert '?'" ,
481
+ title: " chain the optional using '?' to access member 'bigEndian' only for non-'nil' base values " ,
482
482
kind: . quickFix,
483
483
diagnostics: nil ,
484
484
edit: WorkspaceEdit ( changes: [ uri: [ expectedTextEdit] ] , documentChanges: nil ) ,
@@ -493,7 +493,7 @@ final class LocalSwiftTests: XCTestCase {
493
493
// Expected Fix-it: Replace `let a` with `_` because it's never used
494
494
let expectedTextEdit = TextEdit ( range: Position ( line: 1 , utf16index: 7 ) ..< Position ( line: 1 , utf16index: 7 ) , newText: " ! " )
495
495
XCTAssertEqual ( fixit, CodeAction (
496
- title: " Insert '! '" ,
496
+ title: " force-unwrap using '!' to abort execution if the optional value contains 'nil '" ,
497
497
kind: . quickFix,
498
498
diagnostics: nil ,
499
499
edit: WorkspaceEdit ( changes: [ uri: [ expectedTextEdit] ] , documentChanges: nil ) ,
@@ -638,11 +638,11 @@ final class LocalSwiftTests: XCTestCase {
638
638
639
639
for fixit in quickFixes {
640
640
if fixit. title. contains ( " ! " ) {
641
- XCTAssertEqual ( fixit. title, " Insert '!'" )
641
+ XCTAssert ( fixit. title. starts ( with : " force-unwrap using '!'" ) )
642
642
expectedTextEdit. newText = " ! "
643
643
XCTAssertEqual ( fixit. edit, WorkspaceEdit ( changes: [ uri: [ expectedTextEdit] ] , documentChanges: nil ) )
644
644
} else {
645
- XCTAssertEqual ( fixit. title, " Insert '?'" )
645
+ XCTAssert ( fixit. title. starts ( with : " chain the optional using '?'" ) )
646
646
expectedTextEdit. newText = " ? "
647
647
XCTAssertEqual ( fixit. edit, WorkspaceEdit ( changes: [ uri: [ expectedTextEdit] ] , documentChanges: nil ) )
648
648
}
@@ -654,6 +654,97 @@ final class LocalSwiftTests: XCTestCase {
654
654
}
655
655
}
656
656
657
+ func testMuliEditFixitCodeActionPrimary( ) {
658
+ let url = URL ( fileURLWithPath: " /a.swift " )
659
+ let uri = DocumentURI ( url)
660
+
661
+ var diagnostic : Diagnostic ! = nil
662
+ sk. sendNoteSync ( DidOpenTextDocumentNotification ( textDocument: TextDocumentItem (
663
+ uri: uri, language: . swift, version: 12 ,
664
+ text: """
665
+ @available(*, introduced: 10, deprecated: 11)
666
+ func foo() {}
667
+ """
668
+ ) ) , { ( note: Notification < PublishDiagnosticsNotification > ) in
669
+ log ( " Received diagnostics for open - syntactic " )
670
+ } , { ( note: Notification < PublishDiagnosticsNotification > ) in
671
+ log ( " Received diagnostics for open - semantic " )
672
+ XCTAssertEqual ( note. params. diagnostics. count, 1 )
673
+ diagnostic = note. params. diagnostics. first!
674
+ } )
675
+
676
+ let request = CodeActionRequest (
677
+ range: Position ( line: 0 , utf16index: 1 ) ..< Position ( line: 0 , utf16index: 10 ) ,
678
+ context: CodeActionContext ( diagnostics: [ diagnostic] , only: nil ) ,
679
+ textDocument: TextDocumentIdentifier ( uri)
680
+ )
681
+ let response = try ! sk. sendSync ( request)
682
+
683
+ XCTAssertNotNil ( response)
684
+ guard case . codeActions( let codeActions) = response else {
685
+ XCTFail ( " Expected code actions as response " )
686
+ return
687
+ }
688
+ let quickFixes = codeActions. filter { $0. kind == . quickFix }
689
+ XCTAssertEqual ( quickFixes. count, 1 )
690
+ guard let fixit = quickFixes. first else { return }
691
+
692
+ XCTAssertEqual ( fixit. title, " Remove ': 10'... " )
693
+ XCTAssertEqual ( fixit. diagnostics? . count, 1 )
694
+ XCTAssertEqual ( fixit. edit? . changes ? [ uri] , [
695
+ TextEdit ( range: Position ( line: 0 , utf16index: 24 ) ..< Position ( line: 0 , utf16index: 28 ) , newText: " " ) ,
696
+ TextEdit ( range: Position ( line: 0 , utf16index: 40 ) ..< Position ( line: 0 , utf16index: 44 ) , newText: " " ) ,
697
+ ] )
698
+ }
699
+
700
+ func testMuliEditFixitCodeActionNote( ) {
701
+ let url = URL ( fileURLWithPath: " /a.swift " )
702
+ let uri = DocumentURI ( url)
703
+
704
+ var diagnostic : Diagnostic ! = nil
705
+ sk. sendNoteSync ( DidOpenTextDocumentNotification ( textDocument: TextDocumentItem (
706
+ uri: uri, language: . swift, version: 12 ,
707
+ text: """
708
+ @available(*, deprecated, renamed: " new(_:hotness:) " )
709
+ func old(and: Int, busted: Int) {}
710
+ func test() {
711
+ old(and: 1, busted: 2)
712
+ }
713
+ """
714
+ ) ) , { ( note: Notification < PublishDiagnosticsNotification > ) in
715
+ log ( " Received diagnostics for open - syntactic " )
716
+ } , { ( note: Notification < PublishDiagnosticsNotification > ) in
717
+ log ( " Received diagnostics for open - semantic " )
718
+ XCTAssertEqual ( note. params. diagnostics. count, 1 )
719
+ diagnostic = note. params. diagnostics. first!
720
+ } )
721
+
722
+ let request = CodeActionRequest (
723
+ range: Position ( line: 3 , utf16index: 2 ) ..< Position ( line: 3 , utf16index: 2 ) ,
724
+ context: CodeActionContext ( diagnostics: [ diagnostic] , only: nil ) ,
725
+ textDocument: TextDocumentIdentifier ( uri)
726
+ )
727
+ let response = try ! sk. sendSync ( request)
728
+
729
+ XCTAssertNotNil ( response)
730
+ guard case . codeActions( let codeActions) = response else {
731
+ XCTFail ( " Expected code actions as response " )
732
+ return
733
+ }
734
+ let quickFixes = codeActions. filter { $0. kind == . quickFix }
735
+ XCTAssertEqual ( quickFixes. count, 1 )
736
+ guard let fixit = quickFixes. first else { return }
737
+
738
+ XCTAssertEqual ( fixit. title, " use 'new(_:hotness:)' instead " )
739
+ XCTAssertEqual ( fixit. diagnostics? . count, 1 )
740
+ XCTAssert ( fixit. diagnostics? . first? . message. contains ( " is deprecated " ) == true )
741
+ XCTAssertEqual ( fixit. edit? . changes ? [ uri] , [
742
+ TextEdit ( range: Position ( line: 3 , utf16index: 2 ) ..< Position ( line: 3 , utf16index: 5 ) , newText: " new " ) ,
743
+ TextEdit ( range: Position ( line: 3 , utf16index: 6 ) ..< Position ( line: 3 , utf16index: 11 ) , newText: " " ) ,
744
+ TextEdit ( range: Position ( line: 3 , utf16index: 14 ) ..< Position ( line: 3 , utf16index: 20 ) , newText: " hotness " ) ,
745
+ ] )
746
+ }
747
+
657
748
func testXMLToMarkdownDeclaration( ) {
658
749
XCTAssertEqual ( try ! xmlDocumentationToMarkdown ( """
659
750
<Declaration>func foo(_ bar: <Type usr= " fake " >Baz</Type>)</Declaration>
0 commit comments