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(pacmak): .NET submodules don't have namespace docs #2683

Merged
merged 11 commits into from
Mar 17, 2021
4 changes: 2 additions & 2 deletions packages/jsii-pacmak/lib/targets/dotnet/dotnetdocgenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class DotNetDocGenerator {
const remarks = this.renderRemarks(docs);
if (remarks.length > 0) {
this.code.line('/// <remarks>');
remarks.forEach((r) => this.code.line(`/// ${r}`));
remarks.forEach((r) => this.code.line(`/// ${r}`.trimRight()));
this.code.line('/// </remarks>');
}

Expand All @@ -101,7 +101,7 @@ export class DotNetDocGenerator {

this.code.line('/// <remarks>');
for (const line of lines) {
this.code.line(`/// ${line}`);
this.code.line(`/// ${line}`.trimRight());
}
this.code.line('/// </remarks>');
}
Expand Down
32 changes: 23 additions & 9 deletions packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class DotNetGenerator extends Generator {
this.assembly,
);

this.emitNamespaceDocs();
this.emitAssemblyDocs();

// We need to resolve the dependency tree
this.typeresolver.resolveNamespacesDependencies();
Expand Down Expand Up @@ -149,9 +149,19 @@ export class DotNetGenerator extends Generator {

/**
* Namespaces are handled implicitly by openFileIfNeeded().
*
* Do generate docs if this is for a submodule though.
*/
protected onBeginNamespace(_ns: string) {
/* noop */
protected onBeginNamespace(jsiiNs: string) {
const submodule = this.assembly.submodules?.[jsiiNs];
if (submodule) {
const dotnetNs = this.typeresolver.resolveNamespace(
this.assembly,
this.assembly.name,
jsiiNs,
);
this.emitNamespaceDocs(dotnetNs, submodule);
}
}

protected onEndNamespace(_ns: string) {
Expand Down Expand Up @@ -1074,6 +1084,13 @@ export class DotNetGenerator extends Generator {
}
}

private emitAssemblyDocs() {
this.emitNamespaceDocs(
this.assembly.targets!.dotnet!.namespace,
this.assembly,
);
}

/**
* Emit an unused, empty class called `NamespaceDoc` to attach the module README to
*
Expand All @@ -1086,18 +1103,15 @@ export class DotNetGenerator extends Generator {
* In any case, we need a place to attach the docs where they can be transported around,
* might as well be this method.
*/
private emitNamespaceDocs() {
if (!this.assembly.readme) {
private emitNamespaceDocs(namespace: string, docSource: spec.Targetable) {
if (!docSource.readme) {
return;
}

const namespace = this.assembly.targets!.dotnet!.namespace;
const className = 'NamespaceDoc';
this.openFileIfNeeded(className, namespace, false, false);

this.dotnetDocGenerator.emitMarkdownAsRemarks(
this.assembly.readme.markdown,
);
this.dotnetDocGenerator.emitMarkdownAsRemarks(docSource.readme.markdown);
this.emitHideAttribute();
// Traditionally this class is made 'internal', but that interacts poorly with DocFX's default filters
// which aren't overridable. So we make it public, but use attributes to hide it from users' IntelliSense,
Expand Down
Loading