Skip to content
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

Add debug info and typed context to CodeWriter #1095

Merged
merged 3 commits into from
Feb 21, 2022

Conversation

mtdowling
Copy link
Member

This commit introduces typed properties for CodeWriter, allowing context
properties to be retrieved and assert they are a specific type.

While implementing this, I realized that if there is a type mismatch, it
could be hard to track down where in the process of writing code the error
occurred. So this commit also introduces some open debugging facilities
to CodeWriter that includes information about the state of the
CodeWriter (a '/' delimited path to the current state in the stack of
pushed states), the last N lines of code written (defaults to 2), and
any additional metadata subclasses want to introduce. This information
is then presented when CodeWriterDebugInfo is cast to a string.

Most exceptions thrown by CodeWriter will now include this debug output.

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

This commit introduces typed properties for CodeWriter, allowing context
properties to be retrieved and assert they are a specific type.

While implementing this, I realized that if there is a type mismatch, it
could be hard to track down where in the process of writing code the error
occurred. So this commit also introduces some open debugging facilities
to CodeWriter that includes information about the state of the
CodeWriter (a '/' delimited path to the current state in the stack of
pushed states), the last N lines of code written (defaults to 2), and
any additional metadata subclasses want to introduce. This information
is then presented when CodeWriterDebugInfo is cast to a string.

Most exceptions thrown by CodeWriter will now include this debug output.
@mtdowling mtdowling requested a review from a team as a code owner February 17, 2022 00:40
CodegenWriter is supposed to be an opinionated implementation of
CodeWriter that automatically brings Symbols and imports together with a
CodeWriter. This commit adds a built-in "T" formatter for handling
Symbol and SymbolReference objects. This should work for most Smithy
codegen implementations, but the ones that it doesn't can either
override the "T" formatter or not use CodegenWriter.
@mtdowling mtdowling merged commit cb12934 into main Feb 21, 2022
@mtdowling mtdowling deleted the improve-codewriter-debugging branch April 8, 2022 05:31
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.

2 participants