@@ -212,10 +212,9 @@ final class CallHierarchyTests: XCTestCase {
212212 result,
213213 [
214214 CallHierarchyItem (
215- name: " foo " ,
215+ name: " FilePathIndex:: foo" ,
216216 kind: . method,
217217 tags: nil ,
218- detail: " FilePathIndex " ,
219218 uri: try project. uri ( for: " lib.cpp " ) ,
220219 range: try Range ( project. position ( of: " 2️⃣ " , in: " lib.cpp " ) ) ,
221220 selectionRange: try Range ( project. position ( of: " 2️⃣ " , in: " lib.cpp " ) ) ,
@@ -583,10 +582,9 @@ final class CallHierarchyTests: XCTestCase {
583582 [
584583 CallHierarchyIncomingCall (
585584 from: CallHierarchyItem (
586- name: " foo() " ,
585+ name: " MyClass. foo()" ,
587586 kind: . method,
588587 tags: nil ,
589- detail: " MyClass " ,
590588 uri: project. fileURI,
591589 range: Range ( project. positions [ " 1️⃣ " ] ) ,
592590 selectionRange: Range ( project. positions [ " 1️⃣ " ] ) ,
@@ -764,4 +762,92 @@ final class CallHierarchyTests: XCTestCase {
764762 ]
765763 )
766764 }
765+
766+ func testInitializerInCallHierarchy( ) async throws {
767+ try await SkipUnless . indexOnlyHasContainedByRelationsToIndexedDecls ( )
768+ let project = try await IndexedSingleSwiftFileTestProject (
769+ """
770+ func 1️⃣foo() {}
771+
772+ struct Bar {
773+ 2️⃣init() {
774+ 3️⃣foo()
775+ }
776+ }
777+ """
778+ )
779+ let prepare = try await project. testClient. send (
780+ CallHierarchyPrepareRequest (
781+ textDocument: TextDocumentIdentifier ( project. fileURI) ,
782+ position: project. positions [ " 1️⃣ " ]
783+ )
784+ )
785+ let initialItem = try XCTUnwrap ( prepare? . only)
786+ let calls = try await project. testClient. send ( CallHierarchyIncomingCallsRequest ( item: initialItem) )
787+ XCTAssertEqual (
788+ calls,
789+ [
790+ CallHierarchyIncomingCall (
791+ from: CallHierarchyItem (
792+ name: " Bar.init() " ,
793+ kind: . constructor,
794+ tags: nil ,
795+ uri: project. fileURI,
796+ range: Range ( project. positions [ " 2️⃣ " ] ) ,
797+ selectionRange: Range ( project. positions [ " 2️⃣ " ] ) ,
798+ data: . dictionary( [
799+ " usr " : . string( " s:4test3BarVACycfc " ) ,
800+ " uri " : . string( project. fileURI. stringValue) ,
801+ ] )
802+ ) ,
803+ fromRanges: [ Range ( project. positions [ " 3️⃣ " ] ) ]
804+ )
805+ ]
806+ )
807+ }
808+
809+ func testCallHierarchyOfNestedClass( ) async throws {
810+ try await SkipUnless . indexOnlyHasContainedByRelationsToIndexedDecls ( )
811+ let project = try await IndexedSingleSwiftFileTestProject (
812+ """
813+ func 1️⃣foo() {}
814+
815+ struct Outer {
816+ struct Bar {
817+ 2️⃣init() {
818+ 3️⃣foo()
819+ }
820+ }
821+ }
822+ """
823+ )
824+ let prepare = try await project. testClient. send (
825+ CallHierarchyPrepareRequest (
826+ textDocument: TextDocumentIdentifier ( project. fileURI) ,
827+ position: project. positions [ " 1️⃣ " ]
828+ )
829+ )
830+ let initialItem = try XCTUnwrap ( prepare? . only)
831+ let calls = try await project. testClient. send ( CallHierarchyIncomingCallsRequest ( item: initialItem) )
832+ XCTAssertEqual (
833+ calls,
834+ [
835+ CallHierarchyIncomingCall (
836+ from: CallHierarchyItem (
837+ name: " Bar.init() " ,
838+ kind: . constructor,
839+ tags: nil ,
840+ uri: project. fileURI,
841+ range: Range ( project. positions [ " 2️⃣ " ] ) ,
842+ selectionRange: Range ( project. positions [ " 2️⃣ " ] ) ,
843+ data: . dictionary( [
844+ " usr " : . string( " s:4test5OuterV3BarVAEycfc " ) ,
845+ " uri " : . string( project. fileURI. stringValue) ,
846+ ] )
847+ ) ,
848+ fromRanges: [ Range ( project. positions [ " 3️⃣ " ] ) ]
849+ )
850+ ]
851+ )
852+ }
767853}
0 commit comments