10000 Move `MacroExpansion{Error|Warning|FixIt}Message` to the `SwiftSyntaxMacros` module by ahoppen · Pull Request #2338 · swiftlang/swift-syntax · GitHub
[go: up one dir, main page]

Skip to content

Move MacroExpansion{Error|Warning|FixIt}Message to the SwiftSyntaxMacros module #2338

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 1 commit into from
Nov 9, 2023
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
5 changes: 5 additions & 0 deletions Release Notes/511.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
- Issue: https://github.com/apple/swift-syntax/issues/2267
- Pull request: https://github.com/apple/swift-syntax/pull/2272

- `MacroExpansion{Error|Warning|FixIt}Message` moved to the `SwiftSyntaxMacros` module
- Description: Move the `MacroExpansion{Error|Warning|FixIt}Message` types from the `SwiftSyntaxMacroExpansion` module to `SwiftSyntaxMacros`. Deprecated typealiases in `SwiftSyntaxMacroExpansion` forward to `SwiftSyntaxMacros`.
- Pull request: https://github.com/apple/swift-syntax/pull/2338
- 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.

## API-Incompatible Changes

- Effect specifiers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,13 @@
//
//===----------------------------------------------------------------------===//

import SwiftDiagnostics
import SwiftSyntaxMacros

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

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

public var diagnosticID: SwiftDiagnostics.MessageID {
.init(domain: diagnosticDomain, id: "\(Self.self)")
}

public init(_ message: String) {
self.message = message
}
}

/// An warning during macro expansion that is described by its message.
///
/// This type allows macro authors to quickly generate warning messages based on
/// a string. For any non-trivial warning messages, it is encouraged to define a
/// custom type that conforms to `DiagnosticMessage`.
public struct MacroExpansionWarningMessage: DiagnosticMessage {
public let message: String

public var severity: SwiftDiagnostics.DiagnosticSeverity { .warning }

public var diagnosticID: SwiftDiagnostics.MessageID {
.init(domain: diagnosticDomain, id: "\(Self.self)")
}

public init(_ message: String) {
self.message = message
}
}

/// The message of a Fix-It that is specified by a string literal
///
/// This type allows macro authors to quickly generate Fix-It messages based on
/// a string. For any non-trivial Fix-It messages, it is encouraged to define a
/// custom type that conforms to `FixItMessage`.
public struct MacroExpansionFixItMessage: FixItMessage {
public var message: String

public var fixItID: SwiftDiagnostics.MessageID {
.init(domain: diagnosticDomain, id: "\(Self.self)")
}

public init(_ message: String) {
self.message = message
}
}
@available(*, deprecated, message: "MacroExpansionFixItMessage has been moved to the SwiftSyntaxMacros module")
public typealias MacroExpansionFixItMessage = SwiftSyntaxMacros.MacroExpansionFixItMessage
1 change: 1 addition & 0 deletions Sources/SwiftSyntaxMacros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_swift_syntax_library(SwiftSyntaxMacros

AbstractSourceLocation.swift
MacroExpansionContext.swift
MacroExpansionDiagnosticMessages.swift
)

target_link_swift_syntax_libraries(SwiftSyntaxMacros PUBLIC
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import SwiftDiagnostics

fileprivate let diagnosticDomain: String = "SwiftSyntaxMacros"

/// An error during macro expansion that is described by its message.
///
/// This type allows macro authors to quickly generate error messages based on a
/// string. For any non-trivial error messages, it is encouraged to define a
/// custom type that conforms to `DiagnosticMessage`.
public struct MacroExpansionErrorMessage: Error, DiagnosticMessage {
public let message: String

public var severity: SwiftDiagnostics.DiagnosticSeverity { .error }

public var diagnosticID: SwiftDiagnostics.MessageID {
.init(domain: diagnosticDomain, id: "\(Self.self)")
}

public init(_ message: String) {
self.message = message
}
}

/// An warning during macro expansion that is described by its message.
///
/// This type allows macro authors to quickly generate warning messages based on
/// a string. For any non-trivial warning messages, it is encouraged to define a
/// custom type that conforms to `DiagnosticMessage`.
public struct MacroExpansionWarningMessage: DiagnosticMessage {
public let message: String

public var severity: SwiftDiagnostics.DiagnosticSeverity { .warning }

public var diagnosticID: SwiftDiagnostics.MessageID {
.init(domain: diagnosticDomain, id: "\(Self.self)")
}

public init(_ message: String) {
self.message = message
}
}

/// The message of a Fix-It that is specified by a string literal
///
/// This type allows macro authors to quickly generate Fix-It messages based on
/// a string. For any non-trivial Fix-It messages, it is encouraged to define a
/// custom type that conforms to `FixItMessage`.
public struct MacroExpansionFixItMessage: FixItMessage {
public var message: String

public var fixItID: SwiftDiagnostics.MessageID {
.init(domain: diagnosticDomain, id: "\(Self.self)")
}

public init(_ message: String) {
self.message = message
}
}
0