Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension SyntaxProtocol {
@_spi(ExperimentalLanguageFeatures)
public func warningGroupControl(
for diagnosticGroupIdentifier: DiagnosticGroupIdentifier,
globalControls: [DiagnosticGroupIdentifier: WarningGroupControl] = [:],
globalControls: [(DiagnosticGroupIdentifier, WarningGroupControl)] = [],
groupInheritanceTree: DiagnosticGroupInheritanceTree? = nil
) -> WarningGroupControl? {
let warningControlRegions = root.warningGroupControlRegionTreeImpl(
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftWarningControl/WarningControlDeclSyntax.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import SwiftSyntax
extension WithAttributesSyntax {
/// Compute a dictionary of all `@warn` diagnostic group behavior controls
/// specified on this warning control declaration scope.
var allWarningGroupControls: [DiagnosticGroupIdentifier: WarningGroupControl] {
attributes.reduce(into: [DiagnosticGroupIdentifier: WarningGroupControl]()) { result, attr in
var allWarningGroupControls: [(DiagnosticGroupIdentifier, WarningGroupControl)] {
attributes.reduce(into: [(DiagnosticGroupIdentifier, WarningGroupControl)]()) { result, attr in
// `@warn` attributes
guard case .attribute(let attributeSyntax) = attr,
attributeSyntax.attributeName.as(IdentifierTypeSyntax.self)?.name.text == "warn"
Expand Down Expand Up @@ -50,7 +50,7 @@ extension WithAttributesSyntax {
else {
return
}
result[DiagnosticGroupIdentifier(diagnosticGroupID)] = control
result.append((DiagnosticGroupIdentifier(diagnosticGroupID), control))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import SwiftSyntax
extension SyntaxProtocol {
@_spi(ExperimentalLanguageFeatures)
public func warningGroupControlRegionTree(
globalControls: [DiagnosticGroupIdentifier: WarningGroupControl] = [:],
globalControls: [(DiagnosticGroupIdentifier, WarningGroupControl)] = [],
groupInheritanceTree: DiagnosticGroupInheritanceTree? = nil
) -> WarningControlRegionTree {
return warningGroupControlRegionTreeImpl(
Expand All @@ -30,7 +30,7 @@ extension SyntaxProtocol {
/// a specific absolute position - meant to speed up tree generation for individual
/// queries.
func warningGroupControlRegionTreeImpl(
globalControls: [DiagnosticGroupIdentifier: WarningGroupControl],
globalControls: [(DiagnosticGroupIdentifier, WarningGroupControl)],
groupInheritanceTree: DiagnosticGroupInheritanceTree?,
containing position: AbsolutePosition? = nil
) -> WarningControlRegionTree {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftWarningControl/WarningControlRegions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public struct WarningControlRegionTree {
/// Add a warning control region to the tree
mutating func addWarningGroupControls(
range: Range<AbsolutePosition>,
controls: [DiagnosticGroupIdentifier: WarningGroupControl]
controls: [(DiagnosticGroupIdentifier, WarningGroupControl)]
) {
guard !controls.isEmpty else { return }
let newNode = WarningControlRegionNode(range: range)
Expand Down
44 changes: 40 additions & 4 deletions Tests/SwiftWarningControlTest/WarningControlTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public class WarningGroupControlTests: XCTestCase {
1️⃣let x = 1
}
""",
globalControls: ["GroupID": .warning],
globalControls: [("GroupID", .warning)],
diagnosticGroupID: "GroupID",
states: [
"1️⃣": .error
Expand All @@ -289,7 +289,7 @@ public class WarningGroupControlTests: XCTestCase {
}
}
""",
globalControls: ["GroupID": .error],
globalControls: [("GroupID", .error)],
diagnosticGroupID: "GroupID",
states: [
"1️⃣": .error,
Expand All @@ -306,7 +306,7 @@ public class WarningGroupControlTests: XCTestCase {
1️⃣let x = 1
}
""",
globalControls: ["GroupID": .warning],
globalControls: [("GroupID", .warning)],
diagnosticGroupID: "GroupID",
states: [
"1️⃣": .warning
Expand Down Expand Up @@ -351,13 +351,49 @@ public class WarningGroupControlTests: XCTestCase {
)
}
}

func testOrderedGlobalControls() throws {
// Parent group is ignored, followed by sub-group treated as warning
try assertWarningGroupControl(
"""
func foo() {
1️⃣let x = 1
}
""",
globalControls: [("SuperGroupID", .ignored), ("GroupID", .warning)],
groupInheritanceTree: DiagnosticGroupInheritanceTree(subGroups: [
"SuperGroupID": ["GroupID"]
]),
diagnosticGroupID: "GroupID",
states: [
"1️⃣": .warning
]
)

// Parent group is treated as warning, followed by ignored sub-group
try assertWarningGroupControl(
"""
func foo() {
1️⃣let x = 1
}
""",
globalControls: [("SuperGroupID", .warning), ("GroupID", .ignored)],
groupInheritanceTree: DiagnosticGroupInheritanceTree(subGroups: [
"SuperGroupID": ["GroupID"]
]),
diagnosticGroupID: "GroupID",
states: [
"1️⃣": .ignored
]
)
}
}

/// Assert that the various marked positions in the source code have the
/// expected warning behavior controls.
private func assertWarningGroupControl(
_ markedSource: String,
globalControls: [DiagnosticGroupIdentifier: WarningGroupControl] = [:],
globalControls: [(DiagnosticGroupIdentifier, WarningGroupControl)] = [],
groupInheritanceTree: DiagnosticGroupInheritanceTree? = nil,
diagnosticGroupID: DiagnosticGroupIdentifier,
states: [String: WarningGroupControl?],
Expand Down
Loading