@@ -513,4 +513,146 @@ final class WorkspaceTests: XCTestCase {
513
513
let diag = try XCTUnwrap ( fullReport. items. first)
514
514
XCTAssertEqual ( diag. message, " Cannot convert value of type 'String' to specified type 'Int' " )
515
515
}
516
+
517
+ func testIntegrationTest( ) async throws {
518
+ // This test is doing the same as `test-sourcekit-lsp` in the `swift-integration-tests` repo.
519
+ let ws = try await SwiftPMTestWorkspace (
520
+ files: [
521
+ " Sources/clib/include/clib.h " : """
522
+ #ifndef CLIB_H
523
+ #define CLIB_H
524
+
525
+ void clib_func(void);
526
+ void clib_other(void);
527
+
528
+ #endif // CLIB_H
529
+ """ ,
530
+ " Sources/clib/clib.c " : """
531
+ #include " clib.h "
532
+
533
+ void 1️⃣clib_func(void) {2️⃣}
534
+ """ ,
535
+ " Sources/exec/main.swift " : """
536
+ import lib
537
+ import clib
538
+
539
+ Lib().3️⃣foo()
540
+ 4️⃣clib_func()
541
+ """ ,
542
+ " Sources/lib/lib.swift " : """
543
+ public struct Lib {
544
+ public func 5️⃣foo() {}
545
+ public init() {}
546
+ }
547
+ """ ,
548
+ ] ,
549
+ manifest: """
550
+ // swift-tools-version:5.5
551
+ import PackageDescription
552
+
553
+ let package = Package(
554
+ name: " pkg " ,
555
+ targets: [
556
+ .target(name: " exec " , dependencies: [ " lib " , " clib " ]),
557
+ .target(name: " lib " , dependencies: []),
558
+ .target(name: " clib " , dependencies: []),
559
+ ]
560
+ )
561
+ """ ,
562
+ build: true
563
+ )
564
+ let ( mainUri, mainPositions) = try ws. openDocument ( " main.swift " )
565
+ _ = try await ws. testClient. send ( PollIndexRequest ( ) )
566
+
567
+ let fooDefinitionResponse = try await ws. testClient. send (
568
+ DefinitionRequest ( textDocument: TextDocumentIdentifier ( mainUri) , position: mainPositions [ " 3️⃣ " ] )
569
+ )
570
+ XCTAssertEqual (
571
+ fooDefinitionResponse,
572
+ . locations( [
573
+ Location ( uri: try ws. uri ( for: " lib.swift " ) , range: try Range ( ws. position ( of: " 5️⃣ " , in: " lib.swift " ) ) )
574
+ ] )
575
+ )
576
+
577
+ let clibFuncDefinitionResponse = try await ws. testClient. send (
578
+ DefinitionRequest ( textDocument: TextDocumentIdentifier ( mainUri) , position: mainPositions [ " 4️⃣ " ] )
579
+ )
580
+ XCTAssertEqual (
581
+ clibFuncDefinitionResponse,
582
+ . locations( [
583
+ Location ( uri: try ws. uri ( for: " clib.c " ) , range: try Range ( ws. position ( of: " 1️⃣ " , in: " clib.c " ) ) )
584
+ ] )
585
+ )
586
+
587
+ let swiftCompletionResponse = try await ws. testClient. send (
588
+ CompletionRequest ( textDocument: TextDocumentIdentifier ( mainUri) , position: mainPositions [ " 3️⃣ " ] )
589
+ )
590
+ XCTAssertEqual (
591
+ swiftCompletionResponse. items,
592
+ [
593
+ CompletionItem (
594
+ label: " foo() " ,
595
+ kind: . method,
596
+ detail: " Void " ,
597
+ deprecated: false ,
598
+ filterText: " foo() " ,
599
+ insertText: " foo() " ,
600
+ insertTextFormat: . plain,
601
+ textEdit: . textEdit( TextEdit ( range: Range ( mainPositions [ " 3️⃣ " ] ) , newText: " foo() " ) )
602
+ ) ,
603
+ CompletionItem (
604
+ label: " self " ,
605
+ kind: . keyword,
606
+ detail: " Lib " ,
607
+ deprecated: false ,
608
+ filterText: " self " ,
609
+ insertText: " self " ,
610
+ insertTextFormat: . plain,
611
+ textEdit: . textEdit( TextEdit ( range: Range ( mainPositions [ " 3️⃣ " ] ) , newText: " self " ) )
612
+ ) ,
613
+ ]
614
+ )
615
+
616
+ let ( clibcUri, clibcPositions) = try ws. openDocument ( " clib.c " )
617
+
618
+ let cCompletionResponse = try await ws. testClient. send (
619
+ CompletionRequest ( textDocument: TextDocumentIdentifier ( clibcUri) , position: clibcPositions [ " 2️⃣ " ] )
620
+ )
621
+ XCTAssertEqual (
622
+ cCompletionResponse. items,
623
+ [
624
+ // rdar://73762053: This should also suggest clib_other
625
+ CompletionItem (
626
+ label: " clib_func " ,
627
+ kind: . text,
628
+ deprecated: true ,
629
+ sortText: " 41b99800clib_func " ,
630
+ filterText: " clib_func " ,
631
+ insertText: " clib_func " ,
632
+ insertTextFormat: . plain,
633
+ textEdit: . textEdit( TextEdit ( range: Range ( clibcPositions [ " 2️⃣ " ] ) , newText: " clib_func " ) )
634
+ ) ,
635
+ CompletionItem (
636
+ label: " include " ,
637
+ kind: . text,
638
+ deprecated: true ,
639
+ sortText: " 41d85b70include " ,
640
+ filterText: " include " ,
641
+ insertText: " include " ,
642
+ insertTextFormat: . plain,
643
+ textEdit: . textEdit( TextEdit ( range: Range ( clibcPositions [ " 2️⃣ " ] ) , newText: " include " ) )
644
+ ) ,
645
+ CompletionItem (
646
+ label: " void " ,
647
+ kind: . text,
648
+ deprecated: true ,
649
+ sortText: " 41e677bbvoid " ,
650
+ filterText: " void " ,
651
+ insertText: " void " ,
652
+ insertTextFormat: . plain,
653
+ textEdit: . textEdit( TextEdit ( range: Range ( clibcPositions [ " 2️⃣ " ] ) , newText: " void " ) )
654
+ ) ,
655
+ ]
656
+ )
657
+ }
516
658
}
0 commit comments