@@ -602,18 +602,6 @@ final class SwiftCompletionTests: XCTestCase {
602
602
)
603
603
)
604
604
605
- // Not valid for the current session.
606
- // We explicitly keep the session and fail any requests that don't match so that the editor
607
- // can rely on `.triggerFromIncompleteCompletions` always being fast.
608
- await assertThrowsError (
609
- try await testClient. send (
610
- CompletionRequest (
611
- textDocument: TextDocumentIdentifier ( uri) ,
612
- position: Position ( line: 7 , utf16index: 0 ) ,
613
- context: CompletionContext ( triggerKind: . triggerFromIncompleteCompletions)
614
- )
615
- )
616
- )
617
605
assertEqual (
618
606
1 ,
619
607
countFs (
@@ -711,14 +699,15 @@ final class SwiftCompletionTests: XCTestCase {
711
699
)
712
700
713
701
// 'fA '
714
- await assertThrowsError (
702
+ assertEqual (
715
703
try await testClient. send (
716
704
CompletionRequest (
717
705
textDocument: TextDocumentIdentifier ( uri) ,
718
706
position: Position ( line: 7 , utf16index: 12 ) ,
719
707
context: CompletionContext ( triggerKind: . triggerFromIncompleteCompletions)
720
708
)
721
- )
709
+ ) . items,
710
+ [ ]
722
711
)
723
712
724
713
testClient. send (
@@ -897,6 +886,65 @@ final class SwiftCompletionTests: XCTestCase {
897
886
)
898
887
}
899
888
889
+ func testTriggerFromIncompleteAfterStartingStringLiteral( ) async throws {
890
+ let testClient = try await TestSourceKitLSPClient ( )
891
+ let uri = DocumentURI . for ( . swift)
892
+ let positions = testClient. openDocument (
893
+ """
894
+ func foo(_ x: String) {}
895
+
896
+ func test() {
897
+ foo1️⃣
898
+ }
899
+ """ ,
900
+ uri: uri
901
+ )
902
+
903
+ // The following is a pattern that VS Code sends. Make sure we don't return an error.
904
+ // - Insert `()``, changing the line to `foo()``
905
+ // - Invoke code completion after `(`
906
+ // - Insert `""`, changing the line to `foo("")`
907
+ // - Insert `d` inside the string literal, changing the line to `foo("d")`
908
+ // - Ask for completion with the `triggerFromIncompleteCompletions` flag set.
909
+ // Since this isn't actually re-filtering but is a completely new code completion session. When we detect this, we
910
+ // should just start a new session and return the results.
911
+ var position = positions [ " 1️⃣ " ]
912
+ testClient. send (
913
+ DidChangeTextDocumentNotification (
914
+ textDocument: VersionedTextDocumentIdentifier ( uri, version: position. utf16index) ,
915
+ contentChanges: [ TextDocumentContentChangeEvent ( range: Range ( position) , text: " () " ) ]
916
+ )
917
+ )
918
+ position. utf16index += 1
919
+ let initialCompletionResults = try await testClient. send (
920
+ CompletionRequest ( textDocument: TextDocumentIdentifier ( uri) , position: position)
921
+ )
922
+ // Test that we get the "abc" result which makes VS Code think that we are still in the same completion session when doing hte second completion.
923
+ XCTAssert ( initialCompletionResults. items. contains ( where: { $0. label == #""abc""# } ) )
924
+ testClient. send (
925
+ DidChangeTextDocumentNotification (
926
+ textDocument: VersionedTextDocumentIdentifier ( uri, version: position. utf16index) ,
927
+ contentChanges: [ TextDocumentContentChangeEvent ( range: Range ( position) , text: " \" \" " ) ]
928
+ )
929
+ )
930
+ position. utf16index += 1
931
+ testClient. send (
932
+ DidChangeTextDocumentNotification (
933
+ textDocument: VersionedTextDocumentIdentifier ( uri, version: position. utf16index) ,
934
+ contentChanges: [ TextDocumentContentChangeEvent ( range: Range ( position) , text: " d " ) ]
935
+ )
936
+ )
937
+ let secondCompletionResults = try await testClient. send (
938
+ CompletionRequest (
939
+ textDocument: TextDocumentIdentifier ( uri) ,
940
+ position: position,
941
+ context: CompletionContext ( triggerKind: . triggerFromIncompleteCompletions)
942
+ )
943
+ )
944
+ // We shouldn't be getting code completion results for inside the string literal.
945
+ XCTAssert ( secondCompletionResults. items. isEmpty)
946
+ }
947
+
900
948
}
901
949
902
950
private func countFs( _ response: CompletionList ) -> Int {
0 commit comments