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

feat: generate martian struct field descriptions and filenames #480

Merged
merged 9 commits into from
Mar 8, 2024

Conversation

pjedge
Copy link
Collaborator

@pjedge pjedge commented Mar 5, 2024

  • When deriving MartianStruct for a Rust struct convert doc comments into Martian struct field descriptions (optional 3rd column of martian struct field)
  • Allow direct file naming (optional 4th column in Martian struct def) with a new #[mro_filename = "my_filename"] attribute.

@pjedge
Copy link
Collaborator Author

pjedge commented Mar 5, 2024

@adam-azarchs curious if you can recommend a different name for force_filename mro_filename, I wasn't really sure what that feature of Martian is actually called (the 4th column in a struct field).

@pjedge pjedge force-pushed the pe/implement-struct-descriptions-and-renames branch from 775e452 to 33117be Compare March 5, 2024 18:44
Comment on lines 459 to 465
fn name_width(&self) -> usize {
if self.mro_filename.is_none() && self.desc.is_none() {
self.name.len() + 1 // string length + 1 space
} else {
self.name.len() // string_length
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Not sure it makes sense to be reimplementing this logic rather than just relying on passing the output through mro format. For one thing, this won't actually match the logic used by mro format, which is a bit more complex:
https://github.com/martian-lang/martian/blob/6171ed9de74fad39566b2f08685dcb86d5949eff/martian/syntax/format_callable.go#L116-L121

That is, it does not consider the lengths of names > 35 characters in length, or help texts > 25 characters in length.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suppose we could generate unformatted code and then pass things through MRO format. I know in the past I've had failing GHA tests because the generated MRO code in the repo gets formatted by MRO format and then doesn't match the directly generated code, but I suppose we could just update any such tests to test that it matches generated then MRO formatted code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree I had to bend over backwards to get this formatting right and it's much simpler if I don't need to

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough! Should we simply auto-generate an mro that has the correct syntax and let the user pipe it through mro format downstream?

Copy link
Collaborator Author

@pjedge pjedge Mar 6, 2024

Choose a reason for hiding this comment

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

Sounds like both of you agree with that strategy so I will revert it to the unformatted version.
We will need to update rust-martian github action tests to perform mro format before comparison when we bump martian-rust in that repo

Copy link
Member

Choose a reason for hiding this comment

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

I think it's a good idea to have it at least produce semi-formatted output, if for no other reason than to makes it easier to debug if mro format chokes on it due to a syntax error. But I don't think you should go to extreme lengths to replicate the formatting exactly, especially since I reserve the right to change things about the formatting in the future.

Copy link
Collaborator Author

@pjedge pjedge Mar 6, 2024

Choose a reason for hiding this comment

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

I think I'll just leave it as-is. It's nice that the output matches MRF closely. and if we have small differences in certain MROs since they aren't exactly the same we will be sure to run MRF afterward

.github/workflows/rust.yml Outdated Show resolved Hide resolved
Copy link
Member

@sreenathkrishnan sreenathkrishnan 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! Funnily the formatting is more complex than the derive logic itself

martian-derive/src/lib.rs Outdated Show resolved Hide resolved
martian/src/mro.rs Outdated Show resolved Hide resolved
martian/src/mro.rs Outdated Show resolved Hide resolved
@pjedge pjedge enabled auto-merge (squash) March 8, 2024 03:36
@pjedge pjedge merged commit 5111114 into master Mar 8, 2024
2 checks passed
@pjedge pjedge deleted the pe/implement-struct-descriptions-and-renames branch March 8, 2024 03:40
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