Skip to content

Commit 63fa1ab

Browse files
committed
Add a domain to DiagnosticID
This should avoid clashes of diagnostic IDs with the same name from different modules.
1 parent 17bb400 commit 63fa1ab

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

Sources/Diagnostics/Message.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
/// same wording. Eg. it’s possible that the message contains more context when
1919
/// available.
2020
public struct MessageID: Hashable {
21-
private let value: String
21+
private let domain: String
22+
private let id: String
2223

23-
public init(_ value: String) {
24-
self.value = value
24+
public init(domain: String, id: String) {
25+
self.domain = domain
26+
self.id = id
2527
}
2628
}
2729

Sources/SwiftParser/Diagnostics/ParserDiagnosticMessages.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import Diagnostics
1414
import SwiftSyntax
1515

16+
let diagnosticDomain: String = "SwiftParser"
17+
1618
extension Syntax {
1719
// FIXME: These should be defined in gyb_syntax_support.
1820
var nodeTypeNameForDiagnostics: String? {
@@ -43,7 +45,7 @@ public protocol ParserError: DiagnosticMessage {
4345

4446
public extension ParserError {
4547
static var diagnosticID: MessageID {
46-
return MessageID("\(self)")
48+
return MessageID(domain: diagnosticDomain, id: "\(self)")
4749
}
4850

4951
var diagnosticID: MessageID {
@@ -65,7 +67,7 @@ public enum StaticParserError: String, DiagnosticMessage {
6567
public var message: String { self.rawValue }
6668

6769
public var diagnosticID: MessageID {
68-
MessageID("\(type(of: self)).\(self)")
70+
MessageID(domain: diagnosticDomain, id: "\(type(of: self)).\(self)")
6971
}
7072

7173
public var severity: DiagnosticSeverity { .error }

Tests/SwiftParserTest/DiagnosticInfrastructureTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ public class DiagnosticInfrastructureTests: XCTestCase {
99
}
1010

1111
let diag = TestDiagnostic()
12-
XCTAssertEqual(diag.diagnosticID, MessageID("TestDiagnostic"))
12+
XCTAssertEqual(diag.diagnosticID, MessageID(domain: "SwiftParser", id: "TestDiagnostic"))
1313
XCTAssertEqual(diag.message, "My test diagnostic")
1414
XCTAssertEqual(diag.severity, .error)
1515

16-
XCTAssertEqual(StaticParserError.throwsInReturnPosition.diagnosticID, MessageID("StaticParserDiagnosticMessage.throwsInReturnPosition"))
16+
XCTAssertEqual(StaticParserError.throwsInReturnPosition.diagnosticID, MessageID(domain: "SwiftParser", id: "StaticParserDiagnosticMessage.throwsInReturnPosition"))
1717
XCTAssertEqual(StaticParserError.throwsInReturnPosition.severity, .error)
1818
}
1919
}

0 commit comments

Comments
 (0)