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

Improve Doc-Comment Link Generation Machinery #3434

Conversation

InsertCreativityHere
Copy link
Member

@InsertCreativityHere InsertCreativityHere commented Jan 27, 2025

The main change in this PR is that the callback used to map @link tags has been given more context to work with.
It used to take: (string identifier, string member) (parsed from @link identifier#member).
Now it takes: (string rawLink, ContainedPtr source, SyntaxTreeBasePtr target).
Having pointers to the elements lets us do things like check for cpp:identifier.

This PR also removes our use of DocCommentPtr.
There was absolutely no reason to wrap DocComment in a shared_ptr, since it was never shared between anything.
Now we use optional<DocComment> (nullopt indicates there was no doc-comment on something).

And the function for parsing a doc-comment was changed from Contained::parseDocComment to DocComment::parseFrom.
This function was setting private fields on DocComment, so it makes sense to have it on DocComment and avoid a
friend Contained. This was also necessary to avoid some weird shared_from_this hackery.

@InsertCreativityHere InsertCreativityHere marked this pull request as ready for review January 27, 2025 22:32
Copy link
Member

@bernardnormier bernardnormier left a comment

Choose a reason for hiding this comment

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

I anticipate a number of clang-tidy lints.

// Replace links of the form `{@link Type#member}` with `{@link Type::member}`.
string result = "{@link ";
if (memberComponent.empty())
// The only difference with '@link' between Slice1 and Slice2 is that Slice1 uses '#' and Slice2 uses '::'.
Copy link
Member

Choose a reason for hiding this comment

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

I assume you mean the .ice and .slice syntax, not Slice1 and Slice2. Slice1 and Slice2 are two modes of the .slice syntax.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are those the official terms we want to use for them?
The only difference with '@link' between the '.ice' and '.slice' syntaxes is that '.ice' syntax uses '#'?
Feels a little clunky to me.

Copy link
Member

Choose a reason for hiding this comment

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

We can also say Ice Slice files (.ice) and IceRPC Slice files (.slice) but is kind of verbose.

Copy link
Member

Choose a reason for hiding this comment

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

This is a comment in the ice2slice implementation so you could write:

The only difference with '@link' between the ice and slice syntaxes is that the ice syntax uses '#' ...

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with 'Ice syntax' and 'Slice syntax' because I don't care enough to argue.
Of course, I'm still going to make my case though : vP

Because these terms feel pretty weird to me.
There is no such thing as 'Ice syntax' and 'Slice syntax' is ambiguous IMO.
Whereas 'Slice1' and 'Slice2' make it clear that we're only talking about the Slice syntax, but just two different versions of it.

It happens to be true that 'Slice1' and 'Slice2' are compilation modes in IceRPC, but that has no bearing here.
Ice has no compilation modes. And it's worth noting that the entire point of 'Slice1's existence is to interop with the 'Ice syntax'. So calling this 'Slice1' feels very natural to me.

@InsertCreativityHere
Copy link
Member Author

I anticipate a number of clang-tidy lints.

Yes, I tried to keep up with all the lint-changes that were added, but I didn't read every PR in totality.
So, there's probably some that I'm unaware of.

I expect it to complain about passing my std::function by const &.
But given that I'm passing in a function pointer (and not a lambda), I really don't see the point of passing a reference.
So, I'm hoping it won't complain about this.

cpp/src/slice2cpp/Gen.cpp Outdated Show resolved Hide resolved
@@ -1994,7 +2002,7 @@ Slice::Python::CodeVisitor::collectExceptionMembers(const ExceptionPtr& p, Membe
}

void
Slice::Python::CodeVisitor::writeDocstring(const DocCommentPtr& comment, const string& prefix)
Slice::Python::CodeVisitor::writeDocstring(optional<DocComment> comment, const string& prefix)
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 these methods should take a reference, as they are not taking ownership of the comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it to use a const&.
I don't think it really matters though since we were always passing in xvalues to this function.

Co-authored-by: Jose  <pepone@users.noreply.github.com>
@@ -692,39 +688,6 @@ namespace
}
}

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 code for fixing @link tags was moved further down (and largely rewritten).

{
doc.clear();
Copy link
Member Author

Choose a reason for hiding this comment

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

We leave it up to the caller to doc.clear() now.

Comment on lines 787 to 788
// I AM GOING TO MOVE THIS COMMENT PARSING UP THE FILE NEXT TO `DocComment`.
// RIGHT NOW I'VE LEFT IT IN IT'S ORIGINAL PLACE, SO THE DIFF IS REVIEWABLE.
Copy link
Member Author

Choose a reason for hiding this comment

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

Once everyone has reviewed, I'll move all this code up next to DocComment where it belongs.

@@ -819,26 +842,29 @@ Slice::Contained::parseDocComment(
const string returnTag = "@return";
const string deprecatedTag = "@deprecated";

Copy link
Member Author

Choose a reason for hiding this comment

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

Now a plain DocComment instead of an unnecessary DocCommentPtr.

string lineText;
string name;

// Parse the comment's text.
for (const auto& l : lines)
{
lineText.clear();
Copy link
Member Author

Choose a reason for hiding this comment

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

This is where we call clear now instead of inside parseCommentLine and parsseNamedCommentLine.

@@ -503,9 +516,9 @@ namespace Slice
return false;
}

protected:
[[nodiscard]] std::string thisScope() const;
Copy link
Member Author

Choose a reason for hiding this comment

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

thisScope is used by DocComment::parseFrom now (in the process of resolving links).

// Replace links of the form `{@link Type#member}` with `{@link Type::member}`.
string result = "{@link ";
if (memberComponent.empty())
// The only difference with '@link' between Slice1 and Slice2 is that Slice1 uses '#' and Slice2 uses '::'.
Copy link
Member Author

Choose a reason for hiding this comment

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

Are those the official terms we want to use for them?
The only difference with '@link' between the '.ice' and '.slice' syntaxes is that '.ice' syntax uses '#'?
Feels a little clunky to me.

@InsertCreativityHere InsertCreativityHere merged commit f07b487 into zeroc-ice:main Jan 30, 2025
20 of 22 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.

3 participants