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
12 changes: 11 additions & 1 deletion Sources/SwiftWarningControl/WarningControlRegions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,14 @@ public struct WarningControlRegionTree {
/// Root region representing top-level (file) scope
private var rootRegionNode: WarningControlRegionNode

/// All of the diagnostic group identifiers contained in this tree
/// which have at least one occurence with a non-`ignored` behavior
/// specifier
@_spi(ExperimentalLanguageFeatures)
public private(set) var enabledGroups: Set<DiagnosticGroupIdentifier> = []

/// Inheritance tree among diagnostic group identifiers
let groupInheritanceTree: DiagnosticGroupInheritanceTree
private let groupInheritanceTree: DiagnosticGroupInheritanceTree

init(
range: Range<AbsolutePosition>,
Expand All @@ -130,6 +136,10 @@ public struct WarningControlRegionTree {
let groupIdentifier = groups.removeFirst()
processedGroups.insert(groupIdentifier)
newNode.addWarningGroupControl(for: groupIdentifier, control: control)
if control != .ignored {
enabledGroups.insert(diagnosticGroupIdentifier)
}

let newSubGroups = groupInheritanceTree.subgroups(of: groupIdentifier).filter { !processedGroups.contains($0) }
// Ensure we add a corresponding control to each direct and
// transitive sub-group of the one specified on this control.
Expand Down
34 changes: 34 additions & 0 deletions Tests/SwiftWarningControlTest/WarningControlTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,40 @@ public class WarningGroupControlTests: XCTestCase {
)
}

func testEnabledGroupIdentifiers() throws {
let source =
"""
@warn(Group1, as: warning)
@warn(Group2, as: error)
@warn(Group3, as: ignored)
func foo() {
@warn(Group4, as: warning)
func bar() {
@warn(Group5, as: ignored)
@warn(Group6, as: ignored)
func baz() {}
@warn(Group7, as: error)
func qux() {
@warn(Group8, as: warning)
func corge() {}
}
}
}
"""
var parser = Parser(source)
let parseTree = SourceFileSyntax.parse(from: &parser)
let warningControlTree = parseTree.warningGroupControlRegionTree()
let enabledDiagnosticGroups = warningControlTree.enabledGroups
XCTAssertTrue(enabledDiagnosticGroups.contains("Group1"))
XCTAssertTrue(enabledDiagnosticGroups.contains("Group2"))
XCTAssertFalse(enabledDiagnosticGroups.contains("Group3"))
XCTAssertTrue(enabledDiagnosticGroups.contains("Group4"))
XCTAssertFalse(enabledDiagnosticGroups.contains("Group5"))
XCTAssertFalse(enabledDiagnosticGroups.contains("Group6"))
XCTAssertTrue(enabledDiagnosticGroups.contains("Group7"))
XCTAssertTrue(enabledDiagnosticGroups.contains("Group8"))
}

func testNominalDeclWarningGroupControl() throws {
try assertWarningGroupControl(
"""
Expand Down