Skip to content

Commit 6150fbe

Browse files
author
Nathan Hawes
committed
[sourcekitd][test] Test CursorInfo works correctly with modules loaded via a parseable interface
1 parent 1d4e666 commit 6150fbe

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// This is SomeFunc that serves some function
2+
/// - returns: 42
3+
public func SomeFunc() -> Int { return 42; }
4+
public struct XWrapper {
5+
/// This is x, a property of XWrapper
6+
public let x: Int
7+
public init(x: Int) {
8+
self.x = x
9+
}
10+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import SomeModule
2+
3+
func test() {
4+
print(SomeFunc())
5+
let wrapper = XWrapper(x: 43)
6+
print(wrapper.x)
7+
}
8+
9+
// RUN: %empty-directory(%t)
10+
// RUN: %empty-directory(%t/modulecache)
11+
//
12+
// Tests CursorInfo works with modules imported via their .swiftinterface file.
13+
// Setup builds a module interface (.swiftinterface) and doc file (.swiftdoc),
14+
// for SomeModule (built from the SomeModule.swift input) that is imported in
15+
// this file. No .swiftmodule is produced to force it into loading via the
16+
// .swiftinterface file.
17+
18+
// Setup phase 1: build the module interface (.swiftinterface) and doc (.swiftdoc).
19+
//
20+
// RUN: %target-swift-frontend -I %t -module-name SomeModule -emit-parseable-module-interface-path %t/SomeModule.swiftinterface -emit-module-doc-path %t/SomeModule.swiftdoc %S/Inputs/SomeModule.swift -emit-module -o /dev/null
21+
22+
// Actual test: Check the CusorInfo results of references to symbols in that
23+
// module, including the available refactoring actions, and associated doc
24+
// comments (from the .swiftdoc file).
25+
//
26+
// RUN: %sourcekitd-test -req=cursor -cursor-action -pos=1:8 %s -- -I %t -module-cache-path %t/modulecache -target %target-triple %s | %FileCheck %s -check-prefix=CHECK1
27+
// CHECK1: source.lang.swift.ref.module
28+
// CHECK1: SomeModule
29+
// CHECK1: ACTIONS BEGIN
30+
// CHECK1-NEXT: ACTIONS END
31+
32+
// RUN: %sourcekitd-test -req=cursor -cursor-action -pos=4:9 %s -- -I %t -module-cache-path %t/modulecache -target %target-triple %s | %FileCheck %s -check-prefix=CHECK2
33+
// CHECK2: source.lang.swift.ref.function.free
34+
// CHECK2: SomeFunc()
35+
// CHECK2: () -> Int
36+
// CHECK2: SomeModule
37+
// CHECK2: <CommentParts><Abstract><Para>This is SomeFunc that serves some function</Para></Abstract><ResultDiscussion><Para>42</Para></ResultDiscussion></CommentParts>
38+
// CHECK2: ACTIONS BEGIN
39+
// CHECK2-NEXT: source.refactoring.kind.rename.global
40+
// CHECK2-NEXT: Global Rename
41+
// CHECK2-NEXT: symbol without a declaration location cannot be renamed
42+
// CHECK2-NEXT: ACTIONS END
43+
44+
// RUN: %sourcekitd-test -req=cursor -cursor-action -pos=5:17 %s -- -I %t -module-cache-path %t/modulecache -target %target-triple %s | %FileCheck %s -check-prefix=CHECK3
45+
// CHECK3: source.lang.swift.ref.struct
46+
// CHECK3: XWrapper
47+
// CHECK3: XWrapper.Type
48+
// CHECK3: SomeModule
49+
// CHECK3: ACTIONS BEGIN
50+
// CHECK3-NEXT: source.refactoring.kind.rename.global
51+
// CHECK3-NEXT: Global Rename
52+
// CHECK3-NEXT: symbol without a declaration location cannot be renamed
53+
// CHECK3-NEXT: ACTIONS END
54+
55+
// RUN: %sourcekitd-test -req=cursor -cursor-action -pos=6:9 %s -- -I %t -module-cache-path %t/modulecache -target %target-triple %s | %FileCheck %s -check-prefix=CHECK4
56+
// CHECK4: source.lang.swift.ref.var.local
57+
// CHECK4: wrapper
58+
// CHECK4: XWrapper
59+
// CHECK4: ACTIONS BEGIN
60+
// CHECK4-NEXT: source.refactoring.kind.rename.local
61+
// CHECK4-NEXT: Local Rename
62+
// CHECK4-NEXT: ACTIONS END
63+
64+
// RUN: %sourcekitd-test -req=cursor -cursor-action -pos=6:17 %s -- -I %t -module-cache-path %t/modulecache -target %target-triple %s | %FileCheck %s -check-prefix=CHECK5
65+
// CHECK5: source.lang.swift.ref.var.instance
66+
// CHECK5: x
67+
// CHECK5: Int
68+
// CHECK5: SomeModule
69+
// CHECK5: <CommentParts><Abstract><Para>This is x, a property of XWrapper</Para></Abstract></CommentParts>
70+
// CHECK5: ACTIONS BEGIN
71+
// CHECK5-NEXT: source.refactoring.kind.rename.global
72+
// CHECK5-NEXT: Global Rename
73+
// CHECK5-NEXT: symbol without a declaration location cannot be renamed
74+
// CHECK5-NEXT: ACTIONS END

test/SourceKit/InterfaceGen/gen_swift_module.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ func f(s : inout [Int]) {
55
}
66

77
// RUN: %empty-directory(%t.mod)
8+
// RUN: %empty-directory(%t.mod/mcp)
89
// RUN: %swift -emit-module -o %t.mod/swift_mod.swiftmodule %S/Inputs/swift_mod.swift -parse-as-library
910
// RUN: %sourcekitd-test -req=interface-gen -module swift_mod -- -I %t.mod > %t.response
1011
// RUN: diff -u %s.response %t.response
@@ -30,5 +31,5 @@ func f(s : inout [Int]) {
3031

3132
// RUN: %empty-directory(%t.mod)
3233
// RUN: %swift -emit-module -o /dev/null -emit-parseable-module-interface-path %t.mod/swift_mod.swiftinterface %S/Inputs/swift_mod.swift -parse-as-library
33-
// RUN: %sourcekitd-test -req=interface-gen -module swift_mod -- -I %t.mod -module-cache-path %t/mcp > %t.response
34+
// RUN: %sourcekitd-test -req=interface-gen -module swift_mod -- -I %t.mod -module-cache-path %t.mod/mcp > %t.response
3435
// RUN: diff -u %s.from_swiftinterface.response %t.response

0 commit comments

Comments
 (0)