Skip to content

Commit

Permalink
fix(pacmak): .NET submodules don't have namespace docs (#2683)
Browse files Browse the repository at this point in the history
Propagate submodule docs to namespace docs.



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
rix0rrr authored Mar 17, 2021
1 parent 3594ad7 commit 097a4ea
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 67 deletions.
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

0 comments on commit 097a4ea

Please sign in to comment.