-
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 JavaScript doc comments for generated code #2604
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -22,6 +22,38 @@ using namespace IceInternal; | |||||||
|
||||||||
namespace | ||||||||
{ | ||||||||
CommentPtr parseComment(const ContainedPtr& p) | ||||||||
{ | ||||||||
// JavaScript TypeDoc doc processor doesn't accept # at the beginning of a link | ||||||||
// so we need to remove it. | ||||||||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do these generate valid links still? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, with Slice and Java doc you can use This was causing warnings mentioned above when parasing Lines 134 to 136 in 5d4f24b
|
||||||||
string text = p->comment(); | ||||||||
const string linkBegin = "{@link "; | ||||||||
const string linkEnd = "}"; | ||||||||
|
||||||||
string::size_type pos = text.find(linkBegin); | ||||||||
while (pos != string::npos) | ||||||||
{ | ||||||||
string::size_type endPos = text.find(linkEnd, pos); | ||||||||
if (endPos == string::npos) | ||||||||
{ | ||||||||
// Invalid link, ignore it | ||||||||
break; | ||||||||
} | ||||||||
|
||||||||
string link = text.substr(pos + linkBegin.size(), endPos - pos - linkBegin.size()); | ||||||||
if (link.find("#") == 0) | ||||||||
{ | ||||||||
link = link.substr(1); | ||||||||
} | ||||||||
const string replacement = "{@link " + link + "}"; | ||||||||
|
||||||||
text.replace(pos, endPos - pos + linkEnd.size(), replacement); | ||||||||
pos = text.find(linkBegin, pos + replacement.size()); | ||||||||
} | ||||||||
|
||||||||
return p->parseComment(text, false); | ||||||||
} | ||||||||
|
||||||||
// Convert a path to a module name, e.g., "../foo/bar/baz.ice" -> "__foo_bar_baz" | ||||||||
string pathToModule(const string& path) | ||||||||
{ | ||||||||
|
@@ -206,7 +238,7 @@ namespace | |||||||
return; | ||||||||
} | ||||||||
|
||||||||
CommentPtr doc = p->parseComment(false); | ||||||||
CommentPtr doc = parseComment(p); | ||||||||
|
||||||||
out << nl << "/**"; | ||||||||
|
||||||||
|
@@ -252,7 +284,6 @@ namespace | |||||||
const OperationPtr& op, | ||||||||
const CommentPtr& doc, | ||||||||
OpDocParamType type, | ||||||||
const StringList& preParams = StringList(), | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this param, we were always passing an empty list. |
||||||||
const StringList& postParams = StringList()) | ||||||||
{ | ||||||||
ParamDeclList params; | ||||||||
|
@@ -269,11 +300,6 @@ namespace | |||||||
break; | ||||||||
} | ||||||||
|
||||||||
if (!preParams.empty()) | ||||||||
{ | ||||||||
writeDocLines(out, preParams, true); | ||||||||
} | ||||||||
|
||||||||
map<string, StringList> paramDoc = doc->parameters(); | ||||||||
for (ParamDeclList::iterator p = params.begin(); p != params.end(); ++p) | ||||||||
{ | ||||||||
|
@@ -303,9 +329,10 @@ namespace | |||||||
ExceptionPtr ex = op->container()->lookupException(name, false); | ||||||||
if (ex) | ||||||||
{ | ||||||||
name = ex->scoped().substr(2); | ||||||||
name = ex->scoped(); | ||||||||
} | ||||||||
out << nl << " * @throws " << name << " "; | ||||||||
name = JsGenerator::fixId(name); | ||||||||
out << nl << " * @throws {@link " << name << "} "; | ||||||||
writeDocLines(out, p->second, false); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TypeDoc uses this syntax in throws see: https://typedoc.org/tags/throws/ |
||||||||
} | ||||||||
} | ||||||||
|
@@ -315,8 +342,6 @@ namespace | |||||||
const OperationPtr& op, | ||||||||
const CommentPtr& doc, | ||||||||
OpDocParamType type, | ||||||||
bool showExceptions, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed, we should always write the @throws clauses. We were passing "false" all the time and exceptions were ignored. |
||||||||
const StringList& preParams = StringList(), | ||||||||
const StringList& postParams = StringList(), | ||||||||
const StringList& returns = StringList()) | ||||||||
{ | ||||||||
|
@@ -327,18 +352,15 @@ namespace | |||||||
writeDocLines(out, doc->overview(), true); | ||||||||
} | ||||||||
|
||||||||
writeOpDocParams(out, op, doc, type, preParams, postParams); | ||||||||
writeOpDocParams(out, op, doc, type, postParams); | ||||||||
|
||||||||
if (!returns.empty()) | ||||||||
{ | ||||||||
out << nl << " * @return "; | ||||||||
writeDocLines(out, returns, false); | ||||||||
} | ||||||||
|
||||||||
if (showExceptions) | ||||||||
{ | ||||||||
writeOpDocExceptions(out, op, doc); | ||||||||
} | ||||||||
writeOpDocExceptions(out, op, doc); | ||||||||
|
||||||||
if (!doc->misc().empty()) | ||||||||
{ | ||||||||
|
@@ -2519,7 +2541,7 @@ Slice::Gen::TypeScriptVisitor::visitClassDefStart(const ClassDefPtr& p) | |||||||
_out << nl << " * One-shot constructor to initialize all data members."; | ||||||||
for (const auto& dataMember : allDataMembers) | ||||||||
{ | ||||||||
CommentPtr comment = dataMember->parseComment(false); | ||||||||
CommentPtr comment = parseComment(dataMember); | ||||||||
if (comment) | ||||||||
{ | ||||||||
_out << nl << " * @param " << fixId(dataMember->name()) << " " << getDocSentence(comment->overview()); | ||||||||
|
@@ -2612,7 +2634,7 @@ Slice::Gen::TypeScriptVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) | |||||||
} | ||||||||
|
||||||||
const string contextParam = escapeParam(paramList, "context"); | ||||||||
CommentPtr comment = op->parseComment(false); | ||||||||
CommentPtr comment = parseComment(op); | ||||||||
const string contextDoc = "@param " + contextParam + " The Context map to send with the invocation."; | ||||||||
const string asyncDoc = "The asynchronous result object for the invocation."; | ||||||||
|
||||||||
|
@@ -2622,7 +2644,7 @@ Slice::Gen::TypeScriptVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) | |||||||
StringList postParams, returns; | ||||||||
postParams.push_back(contextDoc); | ||||||||
returns.push_back(asyncDoc); | ||||||||
writeOpDocSummary(_out, op, comment, OpDocInParams, false, StringList(), postParams, returns); | ||||||||
writeOpDocSummary(_out, op, comment, OpDocInParams, postParams, returns); | ||||||||
} | ||||||||
_out << nl << fixId(op->name()) << spar; | ||||||||
for (const auto& param : inParams) | ||||||||
|
@@ -2715,7 +2737,7 @@ Slice::Gen::TypeScriptVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) | |||||||
} | ||||||||
|
||||||||
const string currentParam = escapeParam(inParams, "current"); | ||||||||
CommentPtr comment = p->parseComment(false); | ||||||||
CommentPtr comment = parseComment(op); | ||||||||
const string currentDoc = "@param " + currentParam + " The Current object for the invocation."; | ||||||||
const string resultDoc = "The result or a promise like object that will " | ||||||||
"be resolved with the result of the invocation."; | ||||||||
|
@@ -2724,7 +2746,7 @@ Slice::Gen::TypeScriptVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) | |||||||
StringList postParams, returns; | ||||||||
postParams.push_back(currentDoc); | ||||||||
returns.push_back(resultDoc); | ||||||||
writeOpDocSummary(_out, op, comment, OpDocInParams, false, StringList(), postParams, returns); | ||||||||
writeOpDocSummary(_out, op, comment, OpDocInParams, postParams, returns); | ||||||||
} | ||||||||
_out << nl << "abstract " << fixId(op->name()) << spar; | ||||||||
for (const auto& param : inParams) | ||||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 added this overload to be able to preprocess the coment before parsing. This allow for language specific preprocessing.