Skip to content

Commit cf3fbfd

Browse files
authored
Merge pull request #2338 from ahoppen/ahoppen/move-diag-messages
Move `MacroExpansion{Error|Warning|FixIt}Message` to the `SwiftSyntaxMacros` module
2 parents 5285907 + ce83709 commit cf3fbfd

File tree

4 files changed

+83
-53
lines changed

4 files changed

+83
-53
lines changed

Release Notes/511.md

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
- Issue: https://github.com/apple/swift-syntax/issues/2267
3131
- Pull request: https://github.com/apple/swift-syntax/pull/2272
3232

33+
- `MacroExpansion{Error|Warning|FixIt}Message` moved to the `SwiftSyntaxMacros` module
34+
- Description: Move the `MacroExpansion{Error|Warning|FixIt}Message` types from the `SwiftSyntaxMacroExpansion` module to `SwiftSyntaxMacros`. Deprecated typealiases in `SwiftSyntaxMacroExpansion` forward to `SwiftSyntaxMacros`.
35+
- Pull request: https://github.com/apple/swift-syntax/pull/2338
36+
- Notes: The expansion diagnostic messages were defined in `SwiftSyntaxMacroExpansion`, which is intended as an implementation detail of the plugin server and should not need to be imported by macros.
37+
3338
## API-Incompatible Changes
3439

3540
- Effect specifiers:

Sources/SwiftSyntaxMacroExpansion/MacroExpansionDiagnosticMessages.swift

+7-53
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,13 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import SwiftDiagnostics
13+
import SwiftSyntaxMacros
1414

15-
/// An error during macro expansion that is described by its message.
16-
///
17-
/// This type allows macro authors to quickly generate error messages based on a
18-
/// string. For any non-trivial error messages, it is encouraged to define a
19-
/// custom type that conforms to `DiagnosticMessage`.
20-
public struct MacroExpansionErrorMessage: Error, DiagnosticMessage {
21-
public let message: String
15+
@available(*, deprecated, message: "MacroExpansionErrorMessage has been moved to the SwiftSyntaxMacros module")
16+
public typealias MacroExpansionErrorMessage = SwiftSyntaxMacros.MacroExpansionErrorMessage
2217

23-
public var severity: SwiftDiagnostics.DiagnosticSeverity { .error }
18+
@available(*, deprecated, message: "MacroExpansionWarningMessage has been moved to the SwiftSyntaxMacros module")
19+
public typealias MacroExpansionWarningMessage = SwiftSyntaxMacros.MacroExpansionWarningMessage
2420

25-
public var diagnosticID: SwiftDiagnostics.MessageID {
26-
.init(domain: diagnosticDomain, id: "\(Self.self)")
27-
}
28-
29-
public init(_ message: String) {
30-
self.message = message
31-
}
32-
}
33-
34-
/// An warning during macro expansion that is described by its message.
35-
///
36-
/// This type allows macro authors to quickly generate warning messages based on
37-
/// a string. For any non-trivial warning messages, it is encouraged to define a
38-
/// custom type that conforms to `DiagnosticMessage`.
39-
public struct MacroExpansionWarningMessage: DiagnosticMessage {
40-
public let message: String
41-
42-
public var severity: SwiftDiagnostics.DiagnosticSeverity { .warning }
43-
44-
public var diagnosticID: SwiftDiagnostics.MessageID {
45-
.init(domain: diagnosticDomain, id: "\(Self.self)")
46-
}
47-
48-
public init(_ message: String) {
49-
self.message = message
50-
}
51-
}
52-
53-
/// The message of a Fix-It that is specified by a string literal
54-
///
55-
/// This type allows macro authors to quickly generate Fix-It messages based on
56-
/// a string. For any non-trivial Fix-It messages, it is encouraged to define a
57-
/// custom type that conforms to `FixItMessage`.
58-
public struct MacroExpansionFixItMessage: FixItMessage {
59-
public var message: String
60-
61-
public var fixItID: SwiftDiagnostics.MessageID {
62-
.init(domain: diagnosticDomain, id: "\(Self.self)")
63-
}
64-
65-
public init(_ message: String) {
66-
self.message = message
67-
}
68-
}
21+
@available(*, deprecated, message: "MacroExpansionFixItMessage has been moved to the SwiftSyntaxMacros module")
22+
public typealias MacroExpansionFixItMessage = SwiftSyntaxMacros.MacroExpansionFixItMessage

Sources/SwiftSyntaxMacros/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ add_swift_syntax_library(SwiftSyntaxMacros
2222

2323
AbstractSourceLocation.swift
2424
MacroExpansionContext.swift
25+
MacroExpansionDiagnosticMessages.swift
2526
)
2627

2728
target_link_swift_syntax_libraries(SwiftSyntaxMacros PUBLIC
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import SwiftDiagnostics
14+
15+
fileprivate let diagnosticDomain: String = "SwiftSyntaxMacros"
16+
17+
/// An error during macro expansion that is described by its message.
18+
///
19+
/// This type allows macro authors to quickly generate error messages based on a
20+
/// string. For any non-trivial error messages, it is encouraged to define a
21+
/// custom type that conforms to `DiagnosticMessage`.
22+
public struct MacroExpansionErrorMessage: Error, DiagnosticMessage {
23+
public let message: String
24+
25+
public var severity: SwiftDiagnostics.DiagnosticSeverity { .error }
26+
27+
public var diagnosticID: SwiftDiagnostics.MessageID {
28+
.init(domain: diagnosticDomain, id: "\(Self.self)")
29+
}
30+
31+
public init(_ message: String) {
32+
self.message = message
33+
}
34+
}
35+
36+
/// An warning during macro expansion that is described by its message.
37+
///
38+
/// This type allows macro authors to quickly generate warning messages based on
39+
/// a string. For any non-trivial warning messages, it is encouraged to define a
40+
/// custom type that conforms to `DiagnosticMessage`.
41+
public struct MacroExpansionWarningMessage: DiagnosticMessage {
42+
public let message: String
43+
44+
public var severity: SwiftDiagnostics.DiagnosticSeverity { .warning }
45+
46+
public var diagnosticID: SwiftDiagnostics.MessageID {
47+
.init(domain: diagnosticDomain, id: "\(Self.self)")
48+
}
49+
50+
public init(_ message: String) {
51+
self.message = message
52+
}
53+
}
54+
55+
/// The message of a Fix-It that is specified by a string literal
56+
///
57+
/// This type allows macro authors to quickly generate Fix-It messages based on
58+
/// a string. For any non-trivial Fix-It messages, it is encouraged to define a
59+
/// custom type that conforms to `FixItMessage`.
60+
public struct MacroExpansionFixItMessage: FixItMessage {
61+
public var message: String
62+
63+
public var fixItID: SwiftDiagnostics.MessageID {
64+
.init(domain: diagnosticDomain, id: "\(Self.self)")
65+
}
66+
67+
public init(_ message: String) {
68+
self.message = message
69+
}
70+
}

0 commit comments

Comments
 (0)