Skip to content
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
6 changes: 4 additions & 2 deletions Sources/SwiftDiagnostics/Diagnostic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ public struct Diagnostic: CustomDebugStringConvertible {
/// Each Fix-It offers a different way to resolve the diagnostic. Usually, there's only one.
public let fixIts: [FixIt]

/// If `highlights` is `nil` then `node` will be highlighted. This is a
/// reasonable default for almost all diagnostics.
public init(
node: Syntax,
position: AbsolutePosition? = nil,
message: DiagnosticMessage,
highlights: [Syntax] = [],
highlights: [Syntax]? = nil,
notes: [Note] = [],
fixIts: [FixIt] = []
) {
self.node = node
self.position = position ?? node.positionAfterSkippingLeadingTrivia
self.diagMessage = message
self.highlights = highlights
self.highlights = highlights ?? [node]
self.notes = notes
self.fixIts = fixIts
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
// MARK: - Private helper functions

/// Produce a diagnostic.
/// If `highlights` is `nil` the `node` will be highlighted.
func addDiagnostic<T: SyntaxProtocol>(
_ node: T,
position: AbsolutePosition? = nil,
_ message: DiagnosticMessage,
highlights: [Syntax] = [],
highlights: [Syntax]? = nil,
notes: [Note] = [],
fixIts: [FixIt] = [],
handledNodes: [SyntaxIdentifier] = []
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSyntaxBuilder/ValidatingSyntaxNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension SyntaxProtocol {
}

extension Trivia {
/// If `trivia` has contains no unexpected trivia, return `trivia`, otherwise
/// If `trivia` contains no unexpected trivia, return `trivia`, otherwise
/// throw an error with diagnostics describing the unexpected trivia.
public init(validating trivia: Trivia) throws {
self = trivia
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftParserTest/translated/RecoveryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ final class RecoveryTests: XCTestCase {
protocol Multi 1️⃣ident {}
""",
diagnostics: [
DiagnosticSpec(message: "found an unexpected second identifier in protocol")
DiagnosticSpec(message: "found an unexpected second identifier in protocol", highlight: "ident")
]
)
}
Expand Down