Skip to content

Lowercase diagnostic and Fix-It messages and remove "after <previous token>" clause from missing node diagnostics #847

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 2 commits into from
Sep 27, 2022
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
9 changes: 1 addition & 8 deletions Sources/SwiftParser/Diagnostics/MissingNodesError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ public struct MissingNodesError: ParserError {
}
}

// The after clause only provides value if the first missing node is not a token.
// TODO: Revisit whether we want to have this clause at all.
if !firstMissingNode.is(TokenSyntax.self) {
if let previousToken = firstMissingNode.previousToken(viewMode: .fixedUp), previousToken.presence == .present {
return "after '\(previousToken.text)'"
}
}
return nil
}

Expand Down Expand Up @@ -176,7 +169,7 @@ public struct MissingNodesError: ParserError {
}

public var message: String {
var message = "Expected \(missingNodesDescription(missingNodes: missingNodes, commonParent: commonParent))"
var message = "expected \(missingNodesDescription(missingNodes: missingNodes, commonParent: commonParent))"
if let afterClause = afterClause {
message += " \(afterClause)"
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/SwiftParser/Diagnostics/ParserDiagnosticMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public extension ParserFixIt {
/// Please order the cases in this enum alphabetically by case name.
public enum StaticParserError: String, DiagnosticMessage {
case cStyleForLoop = "C-style for statement has been removed in Swift 3"
case missingColonInTernaryExprDiagnostic = "Expected ':' after '? ...' in ternary expression"
case missingFunctionParameterClause = "Expected argument list in function declaration"
case missingColonInTernaryExprDiagnostic = "expected ':' after '? ...' in ternary expression"
case missingFunctionParameterClause = "expected argument list in function declaration"
case throwsInReturnPosition = "'throws' may only occur before '->'"

public var message: String { self.rawValue }
Expand All @@ -73,9 +73,9 @@ public struct ExtaneousCodeAtTopLevel: ParserError {

public var message: String {
if let shortContent = extraneousCode.contentForDiagnosticsIfShortSingleLine {
return "Extraneous '\(shortContent)' at top level"
return "extraneous '\(shortContent)' at top level"
} else {
return "Extraneous code at top level"
return "extraneous code at top level"
}
}
}
Expand All @@ -98,15 +98,15 @@ public struct MissingAttributeArgument: ParserError {
public let attributeName: TokenSyntax

public var message: String {
return "Expected argument for '@\(attributeName)' attribute"
return "expected argument for '@\(attributeName)' attribute"
}
}

public struct UnexpectedNodesError: ParserError {
public let unexpectedNodes: UnexpectedNodesSyntax

public var message: String {
var message = "Unexpected text"
var message = "unexpected text"
if let shortContent = unexpectedNodes.contentForDiagnosticsIfShortSingleLine {
message += " '\(shortContent)'"
}
Expand All @@ -124,8 +124,8 @@ public struct UnexpectedNodesError: ParserError {
// MARK: - Fix-Its (please sort alphabetically)

public enum StaticParserFixIt: String, FixItMessage {
case insertAttributeArguments = "Insert attribute argument"
case moveThrowBeforeArrow = "Move 'throws' before '->'"
case insertAttributeArguments = "insert attribute argument"
case moveThrowBeforeArrow = "move 'throws' before '->'"

public var message: String { self.rawValue }

Expand Down
24 changes: 12 additions & 12 deletions Tests/SwiftParserTest/Attributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ final class AttributeTests: XCTestCase {
}
""",
diagnostics: [
DiagnosticSpec(message: "Expected argument for '@_dynamicReplacement' attribute", fixIts: ["Insert attribute argument"]),
DiagnosticSpec(message: "Expected ')' to end attribute", fixIts: ["Insert ')'"]),
DiagnosticSpec(message: "expected argument for '@_dynamicReplacement' attribute", fixIts: ["insert attribute argument"]),
DiagnosticSpec(message: "expected ')' to end attribute", fixIts: ["Insert ')'"]),
],
fixedSource: """
@_dynamicReplacement(for: <#identifier#>)
Expand All @@ -30,9 +30,9 @@ final class AttributeTests: XCTestCase {
}
""",
diagnostics: [
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected ':' and parameters in '@differentiable' argument", fixIts: ["Insert ':' and parameters"]),
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '=' and right-hand type in same type requirement", fixIts: ["Insert '=' and right-hand type"]),
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected ')' to end attribute", fixIts: ["Insert ')'"]),
DiagnosticSpec(locationMarker: "DIAG_1", message: "expected ':' and parameters in '@differentiable' argument", fixIts: ["Insert ':' and parameters"]),
DiagnosticSpec(locationMarker: "DIAG_2", message: "expected '=' and right-hand type in same type requirement", fixIts: ["Insert '=' and right-hand type"]),
DiagnosticSpec(locationMarker: "DIAG_2", message: "expected ')' to end attribute", fixIts: ["Insert ')'"]),
],
fixedSource: """
@differentiable(reverse wrt: <#syntax#>,where T = <#type#>)
Expand All @@ -48,9 +48,9 @@ final class AttributeTests: XCTestCase {
@_specialize(e#^DIAG^#
""",
diagnostics: [
DiagnosticSpec(message: "Expected ':' in attribute argument"),
DiagnosticSpec(message: "Expected ')' to end attribute"),
DiagnosticSpec(message: "Expected declaration after attribute"),
DiagnosticSpec(message: "expected ':' in attribute argument"),
DiagnosticSpec(message: "expected ')' to end attribute"),
DiagnosticSpec(message: "expected declaration after attribute"),
]
)
}
Expand All @@ -61,9 +61,9 @@ final class AttributeTests: XCTestCase {
@_specialize(e#^DIAG_1^#, exported#^DIAG_2^#)#^DIAG_3^#
""",
diagnostics: [
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected ':' in attribute argument"),
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected ': false' in attribute argument"),
DiagnosticSpec(locationMarker: "DIAG_3", message: "Expected declaration after attribute"),
DiagnosticSpec(locationMarker: "DIAG_1", message: "expected ':' in attribute argument"),
DiagnosticSpec(locationMarker: "DIAG_2", message: "expected ': false' in attribute argument"),
DiagnosticSpec(locationMarker: "DIAG_3", message: "expected declaration after attribute"),
]
)
}
Expand Down Expand Up @@ -231,7 +231,7 @@ final class AttributeTests: XCTestCase {
func testMissingDeclarationAfterAttributes() {
AssertParse(
"@resultBuilder#^DIAG^#",
diagnostics: [DiagnosticSpec(message: "Expected declaration after attribute")],
diagnostics: [DiagnosticSpec(message: "expected declaration after attribute")],
fixedSource: """
@resultBuilder
<#declaration#>
Expand Down
Loading