Skip to content

Commit c7c0a45

Browse files
owenvahoppen
andcommitted
Annotate enums as frozen/nonexhaustive
Co-authored-by: Alex Hoppen <[email protected]>
1 parent 850f352 commit c7c0a45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+62
-56
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ See the [dedicated section][section] on the Swift project website.
2828
After you opened your PR, a maintainer will review it and test your changes in CI (*Continuous Integration*) by adding a `@swift-ci Please test` comment on the pull request. Once your PR is approved and CI has passed, the maintainer will merge your pull request.
2929

3030
Only contributors with [commit access](https://www.swift.org/contributing/#commit-access) are able to approve pull requests and trigger CI.
31+
32+
## API Design
33+
34+
### Public `enum`s
35+
36+
Enums should generally be marked as `@frozen` or `@nonexhaustive` to allow consistent behavior when switching over them in library-evolution and non-library-evolution builds. The default should be `@frozen` unless we expect to extend the enum without adopting a new LSP or BSP version, eg. because the type is part of an LSP extension. We do not need to anticipate the LSP/BSP specification changing since we plan to release a new major version of swift-tools-protocols when it gets updated to a new LSP or BSP specification version. Custom `CodingKey` enums should always be marked as `@nonexhaustive` because we want to be able to add new members to structs.

Sources/BuildServerProtocol/Messages/BuildTargetSourcesRequest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public struct SourceItem: Codable, Hashable, Sendable {
9494
}
9595
}
9696

97-
public enum SourceItemKind: Int, Codable, Hashable, Sendable {
97+
@frozen public enum SourceItemKind: Int, Codable, Hashable, Sendable {
9898
/// The source item references a normal file.
9999
case file = 1
100100

@@ -120,7 +120,7 @@ public struct SourceItemDataKind: RawRepresentable, Codable, Hashable, Sendable
120120

121121
/// **(BSP Extension)**
122122

123-
public enum SourceKitSourceItemKind: String, Codable {
123+
/*@nonexhaustive*/ public enum SourceKitSourceItemKind: String, Codable {
124124
/// A source file that belongs to the target
125125
case source = "source"
126126

Sources/BuildServerProtocol/Messages/OnBuildLogMessageNotification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public struct OnBuildLogMessageNotification: BSPNotification {
5050
}
5151
}
5252

53-
public enum StructuredLogKind: Codable, Hashable, Sendable {
53+
@frozen public enum StructuredLogKind: Codable, Hashable, Sendable {
5454
case begin(StructuredLogBegin)
5555
case report(StructuredLogReport)
5656
case end(StructuredLogEnd)

Sources/BuildServerProtocol/Messages/OnBuildTargetDidChangeNotification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public struct BuildTargetEvent: Codable, Hashable, Sendable {
5353
}
5454
}
5555

56-
public enum BuildTargetEventKind: Int, Codable, Hashable, Sendable {
56+
@frozen public enum BuildTargetEventKind: Int, Codable, Hashable, Sendable {
5757
/// The build target is new.
5858
case created = 1
5959

Sources/BuildServerProtocol/Messages/RegisterForChangeNotifications.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public struct RegisterForChanges: BSPRequest {
3636
}
3737
}
3838

39-
public enum RegisterAction: String, Hashable, Codable, Sendable {
39+
@frozen public enum RegisterAction: String, Hashable, Codable, Sendable {
4040
case register = "register"
4141
case unregister = "unregister"
4242
}

Sources/BuildServerProtocol/Messages/TaskFinishNotification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public struct TestFinishData: Codable, Hashable, Sendable {
165165

166166
}
167167

168-
public enum TestStatus: Int, Codable, Hashable, Sendable {
168+
@frozen public enum TestStatus: Int, Codable, Hashable, Sendable {
169169
/// The test passed successfully.
170170
case passed = 1
171171

Sources/BuildServerProtocol/SupportTypes/MessageType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import LanguageServerProtocol
1414

15-
public enum MessageType: Int, Sendable, Codable {
15+
@frozen public enum MessageType: Int, Sendable, Codable {
1616
/// An error message.
1717
case error = 1
1818

Sources/BuildServerProtocol/SupportTypes/StatusCode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public enum StatusCode: Int, Codable, Hashable, Sendable {
13+
@frozen public enum StatusCode: Int, Codable, Hashable, Sendable {
1414
/// Execution was successful.
1515
case ok = 1
1616

Sources/LanguageServerProtocol/Notifications/LogMessageNotification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public struct LogMessageNotification: LSPNotification, Hashable {
4444
}
4545
}
4646

47-
public enum StructuredLogKind: Codable, Hashable, Sendable {
47+
@frozen public enum StructuredLogKind: Codable, Hashable, Sendable {
4848
case begin(StructuredLogBegin)
4949
case report(StructuredLogReport)
5050
case end(StructuredLogEnd)

Sources/LanguageServerProtocol/Notifications/WorkDoneProgress.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct WorkDoneProgress: LSPNotification, Hashable {
2525
}
2626
}
2727

28-
public enum WorkDoneProgressKind: Codable, Hashable, Sendable {
28+
@frozen public enum WorkDoneProgressKind: Codable, Hashable, Sendable {
2929
case begin(WorkDoneProgressBegin)
3030
case report(WorkDoneProgressReport)
3131
case end(WorkDoneProgressEnd)

0 commit comments

Comments
 (0)