Skip to content

[ASTGen] Simplify diagnostics framework #77404

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 1 commit into from
Nov 6, 2024

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Nov 5, 2024

This simplifies both the diagnostic declarations and usages.

To create a new diangnostic message, create a static method in ASTGen/Diagnostics.swift:

    static func invalidToken(_ token: TokenSyntax) -> Self {
      Self( node: token, message: "invalid token: '\(token.trimmed)'")
    }

To use it in ASTGenVisitor:

  self.diagnose(.invalidToken(token))

This simplifies both the diagnostic declarations and usages.

To create a new diangnostic message, create a static method:

  extension ASTGenDiagnostic {
    static func invalidToken(_ token: TokenSyntax) -> Self {
      return Self(
        node: token,
        message: "invalid token: '\(token.trimmed)'"
      )
    }
  }

To use it In ASTGenVisitor:

  self.diagnose(.invalidToken(token))
@rintaro rintaro force-pushed the astgen-diagnostics-simple branch from 983872b to 92c4989 Compare November 5, 2024 21:12
@rintaro
Copy link
Member Author

rintaro commented Nov 5, 2024

@swift-ci Please smoke test

@rintaro rintaro enabled auto-merge November 6, 2024 00:47
Comment on lines +91 to +92
missing child token of kind '\(kindOfTokenMissing)' in:
\(parent.debugDescription(indentString: " "))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these messages intended to be multi-line. I don’t think we have multi-line diagnostics anywhere else at the moment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to revisit here before enabling ASTGen by default.

@rintaro
Copy link
Member Author

rintaro commented Nov 6, 2024

@swift-ci Please smoke test Windows

1 similar comment
@rintaro
Copy link
Member Author

rintaro commented Nov 6, 2024

@swift-ci Please smoke test Windows

@rintaro rintaro merged commit bba4f65 into swiftlang:main Nov 6, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants