Skip to content

[SourceKit] Add InterfaceGen test case for pure Swift system module #24685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/IDE/complete_from_swiftonly_systemmodule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// RUN: %t/SomeModule.swift

// RUN: %target-swift-ide-test -code-completion -sdk %t/SDK -iframework %t/SDK/Frameworks -source-filename %t/main.swift -code-completion-token=GLOBAL | %FileCheck --check-prefix GLOBAL %s
// RUN: %target-swift-ide-test -code-completion -sdk %t/SDK -iframework %t/SDK/Frameworks -source-filename %t/main.swift -code-completion-token=GLOBAL_TYPE | %FileCheck --check-prefix GLOBAL_TYPE %s
// RUN: %target-swift-ide-test -code-completion -sdk %t/SDK -iframework %t/SDK/Frameworks -source-filename %t/main.swift -code-completion-token=INSTANCE | %FileCheck --check-prefix INSTANCE %s
// RUN: %target-swift-ide-test -code-completion -sdk %t/SDK -iframework %t/SDK/Frameworks -source-filename %t/main.swift -code-completion-token=INITIALIZER | %FileCheck --check-prefix INITIALIZER %s

Expand All @@ -36,6 +37,10 @@ internal func internalFunc() {}
public func _secretFunc() {}
public func publicFunc() {}

internal class InternalClass {}
public class _SecretClass {}
public class PublicClass {}

// BEGIN main.swift
import SomeModule

Expand All @@ -44,10 +49,21 @@ func test(value: SomeValue) {
// GLOBAL: Begin completions
// GLOBAL-NOT: _secretFunc
// GLOBAL-NOT: internalFunc
// GLOBAL-NOT: _SecretClass
// GLOBAL-NOT: InternalClass
// GLOBAL-DAG: Decl[Struct]/OtherModule[SomeModule]: SomeValue[#SomeValue#];
// GLOBAL-DAG: Decl[FreeFunction]/OtherModule[SomeModule]: publicFunc()[#Void#];
// GLOBAL-DAG: Decl[Class]/OtherModule[SomeModule]: PublicClass[#PublicClass#]; name=PublicClass
// GLOBAL: End completions

let _: #^GLOBAL_TYPE^#
// GLOBAL_TYPE: Begin completions
// GLOBAL_TYPE-NOT: InternalClass
// GLOBAL_TYPE-NOT: _SecretClass
// GLOBAL-TYPE-DAG: Decl[Struct]/OtherModule[SomeModule]: SomeValue[#SomeValue#];
// GLOBAL-TYPE-DAG: Decl[Class]/OtherModule[SomeModule]: PublicClass[#PublicClass#];
// GLOBAL_TYPE: End completions

let _ = value.#^INSTANCE^#
// INSTANCE: Begin completions, 3 items
// INSTANCE-DAG: Keyword[self]/CurrNominal: self[#SomeValue#];
Expand Down
36 changes: 36 additions & 0 deletions test/SourceKit/InterfaceGen/gen_swiftonly_systemmodule.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// RUN: %empty-directory(%t)

// RUN: mkdir -p %t/SDK/Frameworks/SomeModule.framework/Modules/SomeModule.swiftmodule
// RUN: %target-swift-frontend \
// RUN: -emit-module \
// RUN: -module-name SomeModule \
// RUN: -o %t/SDK/Frameworks/SomeModule.framework/Modules/SomeModule.swiftmodule/%module-target-triple.swiftmodule \
// RUN: -swift-version 5 \
// RUN: %s

// RUN: %sourcekitd-test -req=interface-gen -module SomeModule -- -Fsystem %t/SDK/Frameworks > %t.response
// RUN: diff -u %s.response %t.response

public struct SomeValue {
internal var internalValue: Int { return 1 }
public var _secretValue: Int { return 1 }
public var publicValue: Int { return 1 }

internal func internalMethod() -> Int { return 1 }
public func _secretMethod() -> Int { return 1 }
public func publicMethod() -> Int { return 1 }

internal init(internal: Int) {}
public init(_secret: Int) {}
public init(public: Int) {}
}

internal func internalFunc() {}
public func _secretFunc() {}
public func publicFunc() {}

internal class InternalClass {}
public class _SecretClass {
public var publicVarInSeretClass: Int = 0
}
public class PublicClass {}
285 changes: 285 additions & 0 deletions test/SourceKit/InterfaceGen/gen_swiftonly_systemmodule.swift.response
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
import SwiftOnoneSupport

public class PublicClass {
}

public struct SomeValue {

public var publicValue: Int { get }

public func publicMethod() -> Int

public init(public: Int)
}

public func publicFunc()


[
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 0,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 7,
key.length: 17
},
{
key.kind: source.lang.swift.syntaxtype.attribute.builtin,
key.offset: 26,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 33,
key.length: 5
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 39,
key.length: 11
},
{
key.kind: source.lang.swift.syntaxtype.attribute.builtin,
key.offset: 56,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 63,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 70,
key.length: 9
},
{
key.kind: source.lang.swift.syntaxtype.attribute.builtin,
key.offset: 87,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 94,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 98,
key.length: 11
},
{
key.kind: source.lang.swift.syntaxtype.typeidentifier,
key.offset: 111,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 117,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.attribute.builtin,
key.offset: 128,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 135,
key.length: 4
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 140,
key.length: 12
},
{
key.kind: source.lang.swift.syntaxtype.typeidentifier,
key.offset: 158,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.attribute.builtin,
key.offset: 167,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 174,
key.length: 4
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 179,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.typeidentifier,
key.offset: 187,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.attribute.builtin,
key.offset: 195,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 202,
key.length: 4
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 207,
key.length: 10
}
]
[
{
key.kind: source.lang.swift.ref.module,
key.offset: 7,
key.length: 17,
key.is_system: 1
},
{
key.kind: source.lang.swift.ref.struct,
key.offset: 111,
key.length: 3,
key.is_system: 1
},
{
key.kind: source.lang.swift.ref.struct,
key.offset: 158,
key.length: 3,
key.is_system: 1
},
{
key.kind: source.lang.swift.ref.struct,
key.offset: 187,
key.length: 3,
key.is_system: 1
}
]
[
{
key.kind: source.lang.swift.decl.class,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "PublicClass",
key.offset: 33,
key.length: 21,
key.runtime_name: "_TtC4main11PublicClass",
key.nameoffset: 39,
key.namelength: 11,
key.bodyoffset: 52,
key.bodylength: 1,
key.attributes: [
{
key.offset: 26,
key.length: 6,
key.attribute: source.decl.attribute.public
}
]
},
{
key.kind: source.lang.swift.decl.struct,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "SomeValue",
key.offset: 63,
key.length: 130,
key.nameoffset: 70,
key.namelength: 9,
key.bodyoffset: 81,
key.bodylength: 111,
key.attributes: [
{
key.offset: 56,
key.length: 6,
key.attribute: source.decl.attribute.public
}
],
key.substructure: [
{
key.kind: source.lang.swift.decl.var.instance,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "publicValue",
key.offset: 94,
key.length: 28,
key.typename: "Int",
key.nameoffset: 98,
key.namelength: 11,
key.bodyoffset: 116,
key.bodylength: 5,
key.attributes: [
{
key.offset: 87,
key.length: 6,
key.attribute: source.decl.attribute.public
}
]
},
{
key.kind: source.lang.swift.decl.function.method.instance,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "publicMethod()",
key.offset: 135,
key.length: 26,
key.typename: "Int",
key.nameoffset: 140,
key.namelength: 14,
key.attributes: [
{
key.offset: 128,
key.length: 6,
key.attribute: source.decl.attribute.public
}
]
},
{
key.kind: source.lang.swift.decl.function.method.instance,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "init(public:)",
key.offset: 174,
key.length: 17,
key.nameoffset: 174,
key.namelength: 17,
key.attributes: [
{
key.offset: 167,
key.length: 6,
key.attribute: source.decl.attribute.public
}
],
key.substructure: [
{
key.kind: source.lang.swift.decl.var.parameter,
key.name: "public",
key.offset: 179,
key.length: 11,
key.typename: "Int",
key.nameoffset: 179,
key.namelength: 6
}
]
}
]
},
{
key.kind: source.lang.swift.decl.function.free,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "publicFunc()",
key.offset: 202,
key.length: 17,
key.nameoffset: 207,
key.namelength: 12,
key.attributes: [
{
key.offset: 195,
key.length: 6,
key.attribute: source.decl.attribute.public
}
]
}
]