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

fix: cairo-doc parser extraction of comment from doc line #7026

Merged
merged 3 commits into from
Jan 9, 2025

Conversation

cairoIover
Copy link
Contributor

Closes #7014

cc @mkaput for review

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Member

@mkaput mkaput left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 4 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @cairoIover, @orizi, and @wawel37)


crates/cairo-lang-doc/src/db.rs line 404 at r2 (raw file):

        //   block, instead of assuming just one space.
        // Require a space after the marker (e.g. "/// " or "//! ")
        if let Some(content) = dedent.strip_prefix(&format!("{} ", comment_marker)) {

I just thought about this and I realised my suggestion how to solve this in the issue was actually wrong. This code forbids the following, which although looks bad is not wrong thing to be honest:

///A thing.
///
///Notice no space.
fn foo() {}

I've verified and this is picked up by rustdoc. So the logic must probably be more sophisticated. Maybe strip the marker and strip whitespace as we did, but reject lines that start with /? @wawel37 wdyt?

Copy link
Collaborator

@wawel37 wawel37 left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @mkaput and @orizi)


crates/cairo-lang-doc/src/db.rs line 404 at r2 (raw file):

Previously, mkaput (Marek Kaput) wrote…

I just thought about this and I realised my suggestion how to solve this in the issue was actually wrong. This code forbids the following, which although looks bad is not wrong thing to be honest:

///A thing.
///
///Notice no space.
fn foo() {}

I've verified and this is picked up by rustdoc. So the logic must probably be more sophisticated. Maybe strip the marker and strip whitespace as we did, but reject lines that start with /? @wawel37 wdyt?

That's right, this one should be working as it would be working with a whitespace:

///Example doc comment that works as comment below
/// A comment with assumption that there's always a whitespace between a prefix and the actual comment.

When it comes to the solution that excludes just the lines that start with / after the prefix is not that perfect imho. Correct me if I am wrong, but I've seen also comment line separators like

///==============
/// Actual comment
///==============

///############
/// Another example
///############

and so on.

I've also checked how it's handled by cargo doc, and it works exactly as @mkaput mentioned. Only lines that start with / after the marker are being ignored. Like like:

///==============
///--------------
///##############

are still being extracted.

In conclusion:
Imo @mkaput is right and we should just ignore lines with / right after the marker and let the user write such docs:

///No space comment

Copy link
Collaborator

@wawel37 wawel37 left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @mkaput and @orizi)


crates/cairo-lang-doc/src/db.rs line 404 at r2 (raw file):

Previously, wawel37 (Mateusz Kowalski) wrote…

That's right, this one should be working as it would be working with a whitespace:

///Example doc comment that works as comment below
/// A comment with assumption that there's always a whitespace between a prefix and the actual comment.

When it comes to the solution that excludes just the lines that start with / after the prefix is not that perfect imho. Correct me if I am wrong, but I've seen also comment line separators like

///==============
/// Actual comment
///==============

///############
/// Another example
///############

and so on.

I've also checked how it's handled by cargo doc, and it works exactly as @mkaput mentioned. Only lines that start with / after the marker are being ignored. Like like:

///==============
///--------------
///##############

are still being extracted.

In conclusion:
Imo @mkaput is right and we should just ignore lines with / right after the marker and let the user write such docs:

///No space comment

also FYI:

//!#############################

This kind of comment results in an error when using cargo doc

Copy link
Member

@mkaput mkaput left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi and @wawel37)


crates/cairo-lang-doc/src/db.rs line 404 at r2 (raw file):

Previously, wawel37 (Mateusz Kowalski) wrote…

also FYI:

//!#############################

This kind of comment results in an error when using cargo doc

hmm, important case to also consider. no idea what should happen here (feel free to copy rustdoc):

/// This is a documentation block.
///
/// This is some summary, wait for this:
/////////////////////////////////////////////////
/// BANG!

Copy link
Contributor Author

@cairoIover cairoIover left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 4 files reviewed, 1 unresolved discussion (waiting on @mkaput and @orizi)


crates/cairo-lang-doc/src/db.rs line 404 at r2 (raw file):

Previously, mkaput (Marek Kaput) wrote…

hmm, important case to also consider. no idea what should happen here (feel free to copy rustdoc):

/// This is a documentation block.
///
/// This is some summary, wait for this:
/////////////////////////////////////////////////
/// BANG!

Done.

New logic is: don't count a comment line that starts with a / as a valid comment line.

Copy link
Member

@mkaput mkaput left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @orizi)


crates/cairo-lang-doc/src/db.rs line 404 at r2 (raw file):

Previously, cairoIover wrote…

Done.

New logic is: don't count a comment line that starts with a / as a valid comment line.

Thank you

Copy link
Collaborator

@wawel37 wawel37 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @orizi)

@mkaput mkaput enabled auto-merge January 9, 2025 10:38
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @cairoIover)

@mkaput mkaput added this pull request to the merge queue Jan 9, 2025
Merged via the queue into starkware-libs:main with commit 9ac17df Jan 9, 2025
47 checks passed
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.

bug: cairo-lang-doc picks ///[/]+ etc. commets as documentation blocks
5 participants