Skip to content

Conversation

@tclem
Copy link
Member

@tclem tclem commented Sep 15, 2025

Makes better use of parse_quote! and specific syn AST types so that development of twirp-build is a bit easier. This gives much more specific error messages with line numbers that are helpful for debugging the code gen code. There is no change to generated code.

🎩 to @jorendorff for showing me how this works!

@jorendorff there was one place I didn't know how to handle: method chaining with syn::ExprMethodCall.

@tclem tclem requested a review from a team as a code owner September 15, 2025 18:33
Copilot AI review requested due to automatic review settings September 15, 2025 18:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the code generation in twirp-build to use parse_quote! instead of quote! for better development experience. It adds type annotations to AST structures and leverages specific syn AST types, which provides more detailed error messages with line numbers for debugging code generation.

  • Replaces quote! with parse_quote! for AST node generation
  • Adds specific syn type annotations to AST collections
  • Improves error reporting during code generation development

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +208 to +209
};
let handler_direct_impl: syn::ItemImpl = parse_quote! {
Copy link

Copilot AI Sep 15, 2025

Choose a reason for hiding this comment

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

The handler_impl variable is missing a closing implementation block. The parse_quote! block at line 200 should include the entire implementation, but it's cut off and continued in handler_direct_impl. Consider combining these into a single implementation block or properly separating them.

Copilot uses AI. Check for mistakes.
@tclem
Copy link
Member Author

tclem commented Sep 15, 2025

@jorendorff there was one place I didn't know how to handle: method chaining with syn::ExprMethodCall.

I sort of figured this out... Let me know what you think.

@tclem tclem added this pull request to the merge queue Sep 16, 2025
Merged via the queue into main with commit 0d46292 Sep 16, 2025
5 checks passed
@tclem tclem deleted the tclem/use-parse-quote branch September 16, 2025 20:36
@github-actions github-actions bot mentioned this pull request Oct 13, 2025
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.

3 participants