-
Notifications
You must be signed in to change notification settings - Fork 593
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
Improve Doc-Comment Link Generation Machinery #3434
Conversation
There was a problem hiding this 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.
cpp/src/ice2slice/Gen.cpp
Outdated
// 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 '::'. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 '#' ...
There was a problem hiding this comment.
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.
Yes, I tried to keep up with all the lint-changes that were added, but I didn't read every PR in totality. I expect it to complain about passing my |
cpp/src/slice2py/PythonUtil.cpp
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
cpp/src/Slice/Parser.cpp
Outdated
@@ -692,39 +688,6 @@ namespace | |||
} | |||
} | |||
|
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
cpp/src/Slice/Parser.cpp
Outdated
// 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. |
There was a problem hiding this comment.
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.
cpp/src/Slice/Parser.cpp
Outdated
@@ -819,26 +842,29 @@ Slice::Contained::parseDocComment( | |||
const string returnTag = "@return"; | |||
const string deprecatedTag = "@deprecated"; | |||
|
There was a problem hiding this comment.
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
.
cpp/src/Slice/Parser.cpp
Outdated
string lineText; | ||
string name; | ||
|
||
// Parse the comment's text. | ||
for (const auto& l : lines) | ||
{ | ||
lineText.clear(); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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).
cpp/src/ice2slice/Gen.cpp
Outdated
// 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 '::'. |
There was a problem hiding this comment.
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.
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 ashared_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
toDocComment::parseFrom
.This function was setting private fields on
DocComment
, so it makes sense to have it onDocComment
and avoid afriend Contained
. This was also necessary to avoid some weirdshared_from_this
hackery.