Skip to content

Commit 8128450

Browse files
committed
[CursorInfo] Always add module name to response
To simplify clients, have the cursorinfo result be consistent whether requesting a symbol within the current module or not, ie. do not skip adding the module name. Resolves rdar://77003299
1 parent 9415bec commit 8128450

File tree

8 files changed

+161
-25
lines changed

8 files changed

+161
-25
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// REQUIRES: objc_interop
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: mkdir -p %t/frameworks/LibA.framework/Modules/LibA.swiftmodule %t/mods %t/mods
5+
// RUN: split-file %s %t
6+
7+
// RUN: %target-swift-frontend -module-name LibB -emit-module -emit-module-path %t/mods/LibB.swiftmodule -emit-module-source-info-path %t/mods/LibB.swiftsourceinfo %t/libB.swift
8+
// RUN: %target-swift-frontend -module-name LibC -emit-module -emit-module-path %t/mods/LibC.swiftmodule %t/libC.swift
9+
// RUN: %target-swift-frontend -module-name LibA -emit-module -emit-module-path %t/frameworks/LibA.framework/Modules/LibA.swiftmodule/%target-swiftmodule-name -import-underlying-module -disable-implicit-concurrency-module-import -F %t/frameworks -I %t/mods %t/libA.swift
10+
// RUN: %swift-ide-test -print-module -print-interface -source-filename dummy -module-to-print LibA -F %t/frameworks -target %target-triple &> %t/generated.swift
11+
12+
// Check that we always include module name, regardless of whether we have
13+
// source information or not. If we have source information, we should also
14+
// output it.
15+
16+
//--- use.swift
17+
18+
import LibA
19+
20+
// RUN: %sourcekitd-test -req=cursor -pos=%(line+1):8 -print-raw-response %t/use.swift -- -F %t/frameworks -target %target-triple %t/use.swift | %FileCheck %s --check-prefix=CHECKSWIFT
21+
let _: ASwiftType
22+
// CHECKSWIFT: key.name: "ASwiftType"
23+
// CHECKSWIFT: key.modulename: "LibA"
24+
// CHECKSWIFT: key.decl_lang: source.lang.swift
25+
26+
// RUN: %sourcekitd-test -req=cursor -pos=%(line+1):8 -print-raw-response %t/use.swift -- -F %t/frameworks -target %target-triple %t/use.swift | %FileCheck %s --check-prefix=CHECKOBJC
27+
let _: AObjcType
28+
// CHECKOBJC: key.name: "AObjcType"
29+
// CHECKOBJC: key.modulename: "LibA"
30+
// CHECKOBJC: key.decl_lang: source.lang.objc
31+
32+
//--- libA.swift
33+
34+
import LibB
35+
import LibC
36+
import LibD
37+
38+
public class ASwiftType {
39+
public func aTypes(swift: ASwiftType, objc: AObjcType, sub: ASubType) {}
40+
public func others(b: BType, c: CType, d: DType) {}
41+
}
42+
43+
// LibA is a mixed framework with no source info and a submodule
44+
// RUN: %sourcekitd-test -req=interface-gen-open -module LibA -- -F %t/frameworks -target %target-triple == -req=cursor -pos=12:36 -print-raw-response | %FileCheck %s --check-prefix=CHECKA
45+
// CHECKA: key.name: "ASwiftType"
46+
// CHECKA: key.modulename: "LibA"
47+
// CHECKA: key.decl_lang: source.lang.swift
48+
49+
//--- frameworks/LibA.framework/module.map
50+
framework module LibA {
51+
header "LibA.h"
52+
export *
53+
54+
module Sub {
55+
header "LibASub.h"
56+
}
57+
}
58+
59+
//--- frameworks/LibA.framework/Headers/LibA.h
60+
@interface AObjcType
61+
@end
62+
63+
// RUN: %sourcekitd-test -req=interface-gen-open -module LibA -- -F %t/frameworks -target %target-triple == -req=cursor -pos=12:54 -print-raw-response | %FileCheck %s --check-prefix=CHECKAOBJ
64+
// CHECKAOBJ: key.name: "AObjcType"
65+
// CHECKAOBJ: key.line: [[@LINE-5]]
66+
// CHECKAOBJ: key.column: 12
67+
// CHECKAOBJ: key.filepath: {{.*}}LibA.h
68+
// CHECKAOBJ: key.modulename: "LibA"
69+
// CHECKAOBJ: key.decl_lang: source.lang.objc
70+
71+
//--- frameworks/LibA.framework/Headers/LibASub.h
72+
@interface ASubType
73+
@end
74+
75+
// RUN: %sourcekitd-test -req=interface-gen-open -module LibA -- -F %t/frameworks -target %target-triple == -req=cursor -pos=12:70 -print-raw-response | %FileCheck %s --check-prefix=CHECKASUB
76+
// CHECKASUB: key.name: "ASubType"
77+
// CHECKASUB: key.line: [[@LINE-5]]
78+
// CHECKASUB: key.column: 12
79+
// CHECKASUB: key.filepath: {{.*}}LibASub.h
80+
// CHECKASUB: key.modulename: "LibA.Sub"
81+
// CHECKASUB: key.decl_lang: source.lang.objc
82+
83+
//--- libB.swift
84+
public class BType {}
85+
86+
// LibB has source info
87+
// RUN: %sourcekitd-test -req=interface-gen-open -module LibA -- -F %t/frameworks -target %target-triple == -req=cursor -pos=14:32 -print-raw-response | %FileCheck %s --check-prefix=CHECKB
88+
// CHECKB: key.name: "BType"
89+
// CHECKB: key.line: [[@LINE-5]]
90+
// CHECKB: key.column: 14
91+
// CHECKB: key.filepath: {{.*}}libB.swift
92+
// CHECKB: key.modulename: "LibB"
93+
// CHECKB: key.decl_lang: source.lang.swift
94+
95+
//--- libC.swift
96+
public class CType {}
97+
98+
// LibC has no source info
99+
// RUN: %sourcekitd-test -req=interface-gen-open -module LibA -- -F %t/frameworks -target %target-triple == -req=cursor -pos=14:47 -print-raw-response | %FileCheck %s --check-prefix=CHECKC
100+
// CHECKC: key.name: "CType"
101+
// CHECKC: key.modulename: "LibC"
102+
// CHECKC: key.decl_lang: source.lang.swift
103+
104+
//--- mods/LibD.h
105+
@interface DType
106+
@end
107+
108+
// RUN: %sourcekitd-test -req=interface-gen-open -module LibA -- -F %t/frameworks -target %target-triple == -req=cursor -pos=14:57 -print-raw-response | %FileCheck %s --check-prefix=CHECKD
109+
// CHECKD: key.name: "DType"
110+
// CHECKD: key.line: [[@LINE-5]]
111+
// CHECKD: key.column: 12
112+
// CHECKD: key.filepath: {{.*}}LibD.h
113+
// CHECKD: key.modulename: "LibD"
114+
// CHECKD: key.decl_lang: source.lang.objc
115+
116+
//--- mods/module.map
117+
module LibD {
118+
header "LibD.h"
119+
export *
120+
}

test/SourceKit/CursorInfo/cursor_info.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ func checkAnyIsAKeyword(x: Any) {}
261261
// CHECK3-NEXT: source.lang.swift
262262
// CHECK3-NEXT: Int{{$}}
263263
// CHECK3-NEXT: $sSiD
264+
// CHECK3-NEXT: cursor_info{{$}}
264265
// CHECK3-NEXT: <Declaration>let x: <Type usr="s:Si">Int</Type></Declaration>
265266
// CHECK3-NEXT: <decl.var.parameter><syntaxtype.keyword>let</syntaxtype.keyword> <decl.var.parameter.name>x</decl.var.parameter.name>: <decl.var.parameter.type><ref.struct usr="s:Si">Int</ref.struct></decl.var.parameter.type></decl.var.parameter>
266267

@@ -302,6 +303,7 @@ func checkAnyIsAKeyword(x: Any) {}
302303
// CHECK7-NEXT: source.lang.swift
303304
// CHECK7-NEXT: S1.Type
304305
// CHECK7-NEXT: $s
306+
// CHECK7-NEXT: cursor_info{{$}}
305307
// CHECK7-NEXT: <Declaration>struct S1</Declaration>
306308
// CHECK7-NEXT: <decl.struct><syntaxtype.keyword>struct</syntaxtype.keyword> <decl.name>S1</decl.name></decl.struct>
307309
// CHECK7-NEXT: <Class file="{{[^"]+}}cursor_info.swift" line="13" column="8"><Name>S1</Name><USR>s:11cursor_info2S1V</USR><Declaration>struct S1</Declaration><CommentParts><Abstract><Para>Aaa. S1. Bbb.</Para></Abstract></CommentParts></Class>
@@ -314,6 +316,7 @@ func checkAnyIsAKeyword(x: Any) {}
314316
// CHECK8-NEXT: (CC.Type) -> (Int) -> CC
315317
// CHECK8-NEXT: $s1x11cursor_info2CCCSi_tcD
316318
// CHECK8-NEXT: <Container>$s11cursor_info2CCCD</Container>
319+
// CHECK8-NEXT: cursor_info{{$}}
317320
// CHECK8-NEXT: <Declaration>init(x: <Type usr="s:Si">Int</Type>)</Declaration>
318321
// CHECK8-NEXT: <decl.function.constructor><syntaxtype.keyword>init</syntaxtype.keyword>(<decl.var.parameter><decl.var.parameter.argument_label>x</decl.var.parameter.argument_label>: <decl.var.parameter.type><ref.struct usr="s:Si">Int</ref.struct></decl.var.parameter.type></decl.var.parameter>)</decl.function.constructor>
319322

@@ -419,6 +422,7 @@ func checkAnyIsAKeyword(x: Any) {}
419422
// CHECK29-NEXT: source.lang.swift
420423
// CHECK29-NEXT: (C3) -> ()
421424
// CHECK29-NEXT: $syycD
425+
// CHECK29-NEXT: cursor_info{{$}}
422426
// CHECK29-NEXT: <Declaration>deinit</Declaration>
423427
// CHECK29-NEXT: <decl.function.destructor><syntaxtype.keyword>deinit</syntaxtype.keyword></decl.function.destructor>
424428

@@ -429,6 +433,7 @@ func checkAnyIsAKeyword(x: Any) {}
429433
// CHECK30-NEXT: source.lang.swift
430434
// CHECK30-NEXT: (C3.Type) -> (Int) -> C3?
431435
// CHECK30-NEXT: $s1x11cursor_info2C3CSgSi_tcD
436+
// CHECK30-NEXT: cursor_info{{$}}
432437
// CHECK30-NEXT: <Declaration>init!(x: <Type usr="s:Si">Int</Type>)</Declaration>
433438
// CHECK30-NEXT: <decl.function.constructor><syntaxtype.keyword>init</syntaxtype.keyword>!(<decl.var.parameter><decl.var.parameter.argument_label>x</decl.var.parameter.argument_label>: <decl.var.parameter.type><ref.struct usr="s:Si">Int</ref.struct></decl.var.parameter.type></decl.var.parameter>)</decl.function.constructor>
434439

@@ -439,6 +444,7 @@ func checkAnyIsAKeyword(x: Any) {}
439444
// CHECK31-NEXT: source.lang.swift
440445
// CHECK31-NEXT: (C3.Type) -> (Int) -> C3?
441446
// CHECK31-NEXT: $s1y11cursor_info2C3CSgSi_tcD
447+
// CHECK31-NEXT: cursor_info{{$}}
442448
// CHECK31-NEXT: <Declaration>init?(y: <Type usr="s:Si">Int</Type>)</Declaration>
443449
// CHECK31-NEXT: <decl.function.constructor><syntaxtype.keyword>init</syntaxtype.keyword>?(<decl.var.parameter><decl.var.parameter.argument_label>y</decl.var.parameter.argument_label>: <decl.var.parameter.type><ref.struct usr="s:Si">Int</ref.struct></decl.var.parameter.type></decl.var.parameter>)</decl.function.constructor>
444450

@@ -449,6 +455,7 @@ func checkAnyIsAKeyword(x: Any) {}
449455
// CHECK32-NEXT: source.lang.swift
450456
// CHECK32-NEXT: (C3.Type) -> (Int) throws -> C3
451457
// CHECK32-NEXT: $s1z11cursor_info2C3CSi_tKcD
458+
// CHECK32-NEXT: cursor_info{{$}}
452459
// CHECK32-NEXT: <Declaration>init(z: <Type usr="s:Si">Int</Type>) throws</Declaration>
453460
// CHECK32-NEXT: <decl.function.constructor><syntaxtype.keyword>init</syntaxtype.keyword>(<decl.var.parameter><decl.var.parameter.argument_label>z</decl.var.parameter.argument_label>: <decl.var.parameter.type><ref.struct usr="s:Si">Int</ref.struct></decl.var.parameter.type></decl.var.parameter>) <syntaxtype.keyword>throws</syntaxtype.keyword></decl.function.constructor>
454461

@@ -757,6 +764,7 @@ func checkAnyIsAKeyword(x: Any) {}
757764
// CHECK87-NEXT: source.lang.swift
758765
// CHECK87-NEXT: HasLocalizationKey.Type
759766
// CHECK87-NEXT: $s
767+
// CHECK87-NEXT: cursor_info{{$}}
760768
// CHECK87-NEXT: <Declaration>struct HasLocalizationKey</Declaration>
761769
// CHECK87-NEXT: <decl.struct><syntaxtype.keyword>struct</syntaxtype.keyword> <decl.name>HasLocalizationKey</decl.name></decl.struct>
762770
// CHECK87-NEXT: <Class file="{{[^"]+}}cursor_info.swift" line="213" column="8"><Name>HasLocalizationKey</Name><USR>s:11cursor_info18HasLocalizationKeyV</USR><Declaration>struct HasLocalizationKey</Declaration><CommentParts><Abstract><Para>Brief.</Para></Abstract></CommentParts></Class>
@@ -769,6 +777,7 @@ func checkAnyIsAKeyword(x: Any) {}
769777
// CHECK88-NEXT: source.lang.swift
770778
// CHECK88-NEXT: () -> ()
771779
// CHECK88-NEXT: $s
780+
// CHECK88-NEXT: cursor_info{{$}}
772781
// CHECK88-NEXT: <Declaration>func hasLocalizationKey2()</Declaration>
773782
// CHECK88-NEXT: <decl.function.free><syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>hasLocalizationKey2</decl.name>()</decl.function.free>
774783
// CHECK88-NEXT: <Function file="{{[^"]+}}cursor_info.swift" line="216" column="6"><Name>hasLocalizationKey2()</Name><USR>s:11cursor_info19hasLocalizationKey2yyF</USR><Declaration>func hasLocalizationKey2()</Declaration><CommentParts></CommentParts></Function>

test/SourceKit/CursorInfo/cursor_opaque_result.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func test(value: MyStruct) {
2323
// OPAQUE-NEXT: (MyStruct) -> () -> some Comparable
2424
// OPAQUE-NEXT: $sQrycD
2525
// OPAQUE-NEXT: <Container>$s8MyModule0A6StructVD</Container>
26+
// OPAQUE-NEXT: MyModule{{$}}
2627
// OPAQUE-NEXT: <Declaration>public func foo() -&gt; some <Type usr="s:SL">Comparable</Type></Declaration>
2728
// OPAQUE-NEXT: <decl.function.method.instance><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>foo</decl.name>() -&gt; <decl.function.returntype><syntaxtype.keyword>some</syntaxtype.keyword> <ref.protocol usr="s:SL">Comparable</ref.protocol></decl.function.returntype></decl.function.method.instance>
2829

@@ -33,5 +34,6 @@ func test(value: MyStruct) {
3334
// ASSOC-NEXT: <Self where Self : P> (Self) -> () -> Self.Assoc
3435
// ASSOC-NEXT: $s5AssocQzycD
3536
// ASSOC-NEXT: <Container>$s8MyModule0A6StructVD</Container>
37+
// ASSOC-NEXT: MyModule{{$}}
3638
// ASSOC-NEXT: <Declaration>func bar() -&gt; <Type usr="s:8MyModule0A6StructV5Assoca">Assoc</Type></Declaration>
3739
// ASSOC-NEXT: <decl.function.method.instance><syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>bar</decl.name>() -&gt; <decl.function.returntype><ref.typealias usr="s:8MyModule0A6StructV5Assoca">Assoc</ref.typealias></decl.function.returntype></decl.function.method.instance>

test/SourceKit/CursorInfo/cursor_some_type.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func test(value: S) {
2626
// DECLSITE-NEXT: source.lang.swift
2727
// DECLSITE-NEXT: <T> (S) -> (T) -> some Base & Proto
2828
// DECLSITE-NEXT: $s1xQrx_tcluD
29+
// DECLSITE-NEXT: Test{{$}}
2930
// DECLSITE-NEXT: <Declaration>public func foo&lt;T&gt;(x: <Type usr=[[T_USR:.*]]>T</Type>) -&gt; some <Type usr=[[Base_USR:.*]]>Base</Type> &amp; <Type usr=[[Proto_USR:.*]]>Proto</Type></Declaration>
3031
// DECLSITE-NEXT: <decl.function.method.instance><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>foo</decl.name>&lt;<decl.generic_type_param usr=[[T_USR]]><decl.generic_type_param.name>T</decl.generic_type_param.name></decl.generic_type_param>&gt;(<decl.var.parameter><decl.var.parameter.argument_label>x</decl.var.parameter.argument_label>: <decl.var.parameter.type><ref.generic_type_param usr=[[T_USR]]>T</ref.generic_type_param></decl.var.parameter.type></decl.var.parameter>) -&gt; <decl.function.returntype><syntaxtype.keyword>some</syntaxtype.keyword> <ref.class usr=[[Base_USR]]>Base</ref.class> &amp; <ref.protocol usr=[[Proto_USR]]>Proto</ref.protocol></decl.function.returntype></decl.function.method.instance>
3132

@@ -36,6 +37,7 @@ func test(value: S) {
3637
// PROTO_AFTER_SOME-NEXT: source.lang.swift
3738
// PROTO_AFTER_SOME-NEXT: Proto.Protocol
3839
// PROTO_AFTER_SOME-NEXT: $s4Test5Proto_pmD
40+
// PROTO_AFTER_SOME-NEXT: Test{{$}}
3941
// PROTO_AFTER_SOME-NEXT: <Declaration>public protocol Proto</Declaration>
4042
// PROTO_AFTER_SOME-NEXT: <decl.protocol><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>protocol</syntaxtype.keyword> <decl.name>Proto</decl.name></decl.protocol>
4143

@@ -47,5 +49,6 @@ func test(value: S) {
4749
// USESITE-NEXT: <T> (S) -> (T) -> some Base & Proto
4850
// USESITE-NEXT: $s1xQrx_tcluD
4951
// USESITE-NEXT: <Container>$s4Test1SVD</Container>
52+
// USESITE-NEXT: Test{{$}}
5053
// USESITE-NEXT: <Declaration>public func foo&lt;T&gt;(x: <Type usr="s:4Test1SV3foo1xQrx_tlFQO1Txmfp">T</Type>) -&gt; some <Type usr=[[Base_USR:.*]]>Base</Type> &amp; <Type usr=[[Proto_USR:.*]]>Proto</Type></Declaration>
5154
// USESITE-NEXT: <decl.function.method.instance><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>foo</decl.name>&lt;<decl.generic_type_param usr="s:4Test1SV3foo1xQrx_tlFQO1Txmfp"><decl.generic_type_param.name>T</decl.generic_type_param.name></decl.generic_type_param>&gt;(<decl.var.parameter><decl.var.parameter.argument_label>x</decl.var.parameter.argument_label>: <decl.var.parameter.type><ref.generic_type_param usr="s:4Test1SV3foo1xQrx_tlFQO1Txmfp">T</ref.generic_type_param></decl.var.parameter.type></decl.var.parameter>) -&gt; <decl.function.returntype><syntaxtype.keyword>some</syntaxtype.keyword> <ref.class usr=[[Base_USR]]>Base</ref.class> &amp; <ref.protocol usr=[[Proto_USR]]>Proto</ref.protocol></decl.function.returntype></decl.function.method.instance>

test/SourceKit/CursorInfo/cursor_usr.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func foo(x: FooStruct1) -> S1 {}
2222
// CHECK_SANITY1-NEXT: source.lang.swift
2323
// CHECK_SANITY1-NEXT: S1.Type
2424
// CHECK_SANITY1-NEXT: $s10cursor_usr2S1VmD
25+
// CHECK_SANITY1-NEXT: cursor_usr{{$}}
2526
// CHECK_SANITY1-NEXT: <Declaration>struct S1</Declaration>
2627
// CHECK_SANITY1-NEXT: <decl.struct><syntaxtype.keyword>struct</syntaxtype.keyword> <decl.name>S1</decl.name></decl.struct>
2728

@@ -39,4 +40,3 @@ func foo(x: FooStruct1) -> S1 {}
3940
// CHECK1: source.lang.swift.decl.struct (5:8-5:10)
4041
// CHECK1: s1
4142
// CHECK1: <decl.struct><syntaxtype.keyword>struct</syntaxtype.keyword> <decl.name>S1</decl.name></decl.struct>
42-

test/SourceKit/CursorInfo/rdar_34348776.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ public struct MyStruct<T> {}
22
public typealias Alias<T> = MyStruct<T>
33
public typealias Aliased = Alias
44

5-
// RUN: %sourcekitd-test -req=cursor -pos=3:18 %s -- %s | %FileCheck %s
5+
// RUN: %sourcekitd-test -req=cursor -pos=3:18 %s -- %s -module-name AliasTest | %FileCheck %s
66

77
// CHECK: source.lang.swift.decl.typealias (3:18-3:25)
88
// CHECK-NEXT: Aliased
9-
// CHECK-NEXT: s:13rdar_343487767Aliaseda
9+
// CHECK-NEXT: s:9AliasTest7Aliaseda
1010
// CHECK-NEXT: source.lang.swift
1111
// CHECK-NEXT: Alias.Type
12-
// CHECK-NEXT: $s13rdar_343487765AliasamD
13-
// CHECK-NEXT: <Declaration>public typealias Aliased = <Type usr="s:13rdar_343487765Aliasa">Alias</Type></Declaration>
14-
// CHECK-NEXT: <decl.typealias><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>typealias</syntaxtype.keyword> <decl.name>Aliased</decl.name> = <ref.typealias usr="s:13rdar_343487765Aliasa">Alias</ref.typealias></decl.typealias>
12+
// CHECK-NEXT: $s9AliasTest0A0amD
13+
// CHECK-NEXT: AliasTest{{$}}
14+
// CHECK-NEXT: <Declaration>public typealias Aliased = <Type usr="s:9AliasTest0A0a">Alias</Type></Declaration>
15+
// CHECK-NEXT: <decl.typealias><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>typealias</syntaxtype.keyword> <decl.name>Aliased</decl.name> = <ref.typealias usr="s:9AliasTest0A0a">Alias</ref.typealias></decl.typealias>

0 commit comments

Comments
 (0)