Skip to content

Conversation

cprecioso
Copy link
Member

@cprecioso cprecioso commented May 22, 2025

Review changes for #2638

Copy link
Member

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

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

Left some comments @cprecioso , I like where we are going, I think we are quite closer to a finished thing!

Except for what I commented on, one main thing that I am suspicious a bit of is the current LanguageInfo situation. That whole part is certainly better now, as you said it is more explicit, there are less hidden assumptions. But on the other hand, this centralization of LanguageInfo seems a bit weird to me, a bit artifical and too emphasized. I tryed playing a bit with replacing that structure with functions like function tsToJsExt (tsExt: "ts" | "tsx"): "js" | "jsx" and function tsExtIsJsx (tsExt: "ts" | "tsx"): boolean but I am not sure that is the right direction either.
Maybe that is ok all together -> I would say, let's take care of everyting that is outstanding, then at the very end we can take one last look at the LanguageInfo situation and see if we want to do something there or not, it will be clearer situation then.

Copy link

cloudflare-workers-and-pages bot commented May 27, 2025

Deploying wasp-docs-on-main with  Cloudflare Pages  Cloudflare Pages

Latest commit: b8d75e7
Status: ✅  Deploy successful!
Preview URL: https://5a5f0985.wasp-docs-on-main.pages.dev
Branch Preview URL: https://cprecioso-push-lxzuqtyxotlm.wasp-docs-on-main.pages.dev

View logs

@cprecioso
Copy link
Member Author

@Martinsos addressed the comments, please review


I tryed playing a bit with replacing that structure with functions like function tsToJsExt (tsExt: "ts" | "tsx"): "js" | "jsx" and function tsExtIsJsx (tsExt: "ts" | "tsx"): boolean but I am not sure that is the right direction either.

I think Haskell-isms are leading you on here, I wouldn't say this kind of solution is idiomatic JS/TS at all.

seems a bit weird to me, a bit artifical and too emphasized

Well, yes 😅 If we want to operate at this level of abstraction, we need a more-or-less central way of defining the transformation. And right now, it does look like overkill for just two possible alternatives. If we want to make it simpler I think I'd end up slipping back to something very similar to what we had.

@Martinsos
Copy link
Member

@Martinsos addressed the comments, please review

I tryed playing a bit with replacing that structure with functions like function tsToJsExt (tsExt: "ts" | "tsx"): "js" | "jsx" and function tsExtIsJsx (tsExt: "ts" | "tsx"): boolean but I am not sure that is the right direction either.

I think Haskell-isms are leading you on here, I wouldn't say this kind of solution is idiomatic JS/TS at all.

seems a bit weird to me, a bit artifical and too emphasized

Well, yes 😅 If we want to operate at this level of abstraction, we need a more-or-less central way of defining the transformation. And right now, it does look like overkill for just two possible alternatives. If we want to make it simpler I think I'd end up slipping back to something very similar to what we had.

Yes it is probably a bit of Haskellisms as you said :D. I do find Haskell often to influence my code in other languages for better though, so I don't disregard them but usually follow them, to see where it brings me.
In this case, I agree that didn't feel like the right direction at the end, as I noted above. And I completely get what you did with the current approach and think it is a nice improvement.
Still, I have something gnawing at me that there is somewhat better solution just in reach, feels like there is too much complexity. But I do have to admit I haven't managed to see it quickly, and it might be a fake hunch, so I am happy with the current solution -> it is explicit and clear and that is most important, and since it is relatively local and scoped, a bit of potentially redundant complexity / non-cohesiveness can't do much damage. And exploring something better (if there is anything at all) would probably take time that is just not worth it.

Ok, good with me, nice stuff!

Copy link
Member

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

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

@cprecioso ok we are very close now! I think there is nothing major left,expect for one thing that I would really want us to fix before we close this, and that is making that function for chekcing the meta flag work correctly and not give false positives.

@cprecioso
Copy link
Member Author

@Martinsos ready

Copy link
Member

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

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

@cprecioso some last improvements for the new code and I think that will be it.

import type { VFile } from "vfile";
import { formatCode, FormatCodeOptions } from "./prettier";

const CODE_BLOCK_META_REGEX = /([^\s=]+)(?:="([^"]*)")?/g;
Copy link
Member

Choose a reason for hiding this comment

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

Since this regex is standalone here, and not inside the function that uses it, I would shortly document what it intends to capture, since regexes are not easy to read not get the intention from.

Copy link
Member Author

Choose a reason for hiding this comment

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

The comment for the parse function can work for both

Copy link
Member

Choose a reason for hiding this comment

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

Nice comment on the CODE_BLOCK_META_REGEX! Doesn't mention anything about what matching groups capture, nor does it have an example, but that ok, reader can figure that on their own also.

I am not sure what do you mean by

The comment for the parse function can work for both

I wouldn't count on parseCodeBlockMetaString being documented by comment that is on CODE_BLOCK_META_REGEX. They are close to each other right now, in the source file, but they are both top level definitions in this file, and that makes them standalone. Meaning that their implementations and contracts/APIs are not tied together and can digress at any moment, even if they stay close to each other (which also might change).

So if we think parseCodeBlockMetaString deserves a comment explaining what it expects from the metaString, and I think it does (I probably suggested it earlier? I can't remember), then there should be an explicit comment. If nothing, let's at least in that comment tell the reader to check out the CODE_BLOCK_META_REGEX, that metaString needs to satisfy it -> that will already work well enough. Because at the moment that is only implementation detail, and is not a part of the contract/API of this function, this way you make it so though.

It would be a different story if you moved that regex inside of the parseCodeBlockMetaString function, then it would be an implementation detail and any comment would be just there to make it easier to understand it, not to define the contract/API of it.

Copy link
Member Author

Choose a reason for hiding this comment

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

It really feels like we'd prefer the regex to be inside of the function so I did that 😜

Copy link
Member

Choose a reason for hiding this comment

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

That also works! I don't mind any of the approaches, as long as stuff has clear APIs/contracts.

RAW

@cprecioso
Copy link
Member Author

@Martinsos ready

Copy link
Member

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

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

LGTM! But there check out the last comments I left, one of them will probably need handling before merging (adding comments to parse function). Then merge.

@cprecioso
Copy link
Member Author

@Martinsos check it out

@Martinsos
Copy link
Member

@Martinsos check it out

All good, and I already approved it last time, feel free to merge!

@cprecioso cprecioso merged commit 8c49210 into main Jun 4, 2025
3 checks passed
@cprecioso cprecioso deleted the cprecioso/push-lxzuqtyxotlm branch June 4, 2025 08:04
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