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 multiple cases to NonEmptyString support #375

Merged
merged 7 commits into from
Feb 8, 2024

Conversation

lbialy
Copy link
Collaborator

@lbialy lbialy commented Feb 7, 2024

No description provided.

@lbialy lbialy added kind/improvement An improvement with existing workaround area/core The SDK's core code impact/usability Something that impacts users' ability to use the product easily and intuitively impact/first-48 This bug is likely to be hit during a user's first 48 hours of product evaluation size/S Estimated effort to complete (1-2 days). area/api User visible API impact/reliability Something that feels unreliable or flaky labels Feb 7, 2024
@lbialy lbialy requested a review from pawelprazak February 7, 2024 14:54
Copy link
Contributor

@pawelprazak pawelprazak left a comment

Choose a reason for hiding this comment

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

Looks good, thank you.

@lbialy lbialy changed the title [WIP] Add multiple cases to NonEmptyString support Add multiple cases to NonEmptyString support Feb 8, 2024
@lbialy lbialy marked this pull request as ready for review February 8, 2024 10:06
Copy link
Contributor

@pawelprazak pawelprazak left a comment

Choose a reason for hiding this comment

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

I can't find anything wrong with it. Would appreciate comments explaining the more dense parts. Other thank that, looks great, thank you!

@@ -130,6 +130,27 @@ trait BesomSyntax:
res <- ctx.readOrRegisterResource[A, EmptyArgs](companion.typeToken, name, EmptyArgs(), CustomResourceOptions(importId = id))
yield res

extension (s: String)
Copy link
Contributor

Choose a reason for hiding this comment

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

I love those converters, very useful!

import besom.util.interpolator.*
inline def fromStringOutput(inline s: Output[String]): Output[NonEmptyString] = ${ fromStringOutputImpl('s) }

private def fromStringOutputImpl(expr: Expr[Output[String]])(using quotes: Quotes): Expr[Output[NonEmptyString]] =
Copy link
Contributor

Choose a reason for hiding this comment

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

wow, I didn't know you can poke inside interpolators with macros like that, impressive

@@ -39,8 +64,34 @@ object NonEmptyString:
private def fromImpl(expr: Expr[String])(using quotes: Quotes): Expr[NonEmptyString] =
import quotes.reflect.*

// kudos to @Kordyjan for most of this implementation
def downTheRabbitHole(tree: Term): Either[Term, String] =
Copy link
Contributor

@pawelprazak pawelprazak Feb 8, 2024

Choose a reason for hiding this comment

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

this is quite dense, I would appreciate adding some comments to guide the reader through this code, esp. for people not fluent in macros

I understand that we are recursively examining the AST and trying to figure out all cases where it can be proven the result string will be not empty, but I'm sure I'm missing some important details.

In the interest of maintenance, adding comments would be greatly appreciated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, no problem. Give me a minute.

@pawelprazak
Copy link
Contributor

Ah. One more thing, please update the Changelog :)

@lbialy lbialy force-pushed the lbialy/extend-nonemptystring branch from faa74d9 to 8e1686b Compare February 8, 2024 11:21
@lbialy
Copy link
Collaborator Author

lbialy commented Feb 8, 2024

Ah. One more thing, please update the Changelog :)

done!

@lbialy lbialy merged commit d6895d3 into develop Feb 8, 2024
3 checks passed
@lbialy lbialy deleted the lbialy/extend-nonemptystring branch February 8, 2024 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api User visible API area/core The SDK's core code impact/first-48 This bug is likely to be hit during a user's first 48 hours of product evaluation impact/reliability Something that feels unreliable or flaky impact/usability Something that impacts users' ability to use the product easily and intuitively kind/improvement An improvement with existing workaround size/S Estimated effort to complete (1-2 days).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants