Skip to content

Commit

Permalink
fix: filtering of internal entities
Browse files Browse the repository at this point in the history
  • Loading branch information
schoero committed Aug 29, 2024
1 parent 5a284b4 commit 6e1e2bf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/renderer/markup/ast-converter/entities/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { convertSeeTagsForDocumentation } from "unwritten:renderer/markup/ast-co
import { registerAnchor } from "unwritten:renderer/markup/registry/registry";
import { getSectionType } from "unwritten:renderer/markup/types-definitions/sections.js";
import { renderMemberContext, withMemberContext } from "unwritten:renderer/markup/utils/context";
import { filterExportableEntities } from "unwritten:renderer/markup/utils/filter";
import { renderEntityPrefix } from "unwritten:renderer/markup/utils/renderer.js";
import { sortExportableEntities } from "unwritten:renderer/markup/utils/sort";

import type { ModuleEntity } from "unwritten:interpreter:type-definitions/entities";
import type { MarkupRenderContext } from "unwritten:renderer:markup/types-definitions/markup";
Expand Down Expand Up @@ -54,8 +56,11 @@ export function convertModuleEntityForTableOfContents(ctx: MarkupRenderContext,
const name = moduleEntity.name;
const anchor = convertModuleEntityToAnchor(ctx, moduleEntity);

const sortedEntities = sortExportableEntities(ctx, moduleEntity.exports);
const filteredEntities = filterExportableEntities(ctx, sortedEntities);

return withMemberContext(ctx, name, () => {
const moduleExports = createTableOfContents(ctx, moduleEntity.exports);
const moduleExports = createTableOfContents(ctx, filteredEntities);

return [
anchor,
Expand Down Expand Up @@ -91,7 +96,10 @@ export function convertModuleEntityForDocumentation(ctx: MarkupRenderContext, mo
const example = moduleEntity.example && convertExamplesForDocumentation(ctx, moduleEntity.example);
const see = moduleEntity.see && convertSeeTagsForDocumentation(ctx, moduleEntity.see);

const children = moduleEntity.exports.map(
const sortedEntities = sortExportableEntities(ctx, moduleEntity.exports);
const filteredEntities = filterExportableEntities(ctx, sortedEntities);

const children = filteredEntities.map(
exportedEntity => convertEntityForDocumentation(ctx, exportedEntity)
);

Expand Down
14 changes: 12 additions & 2 deletions src/renderer/markup/ast-converter/entities/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { convertSeeTagsForDocumentation } from "unwritten:renderer/markup/ast-co
import { registerAnchor } from "unwritten:renderer/markup/registry/registry";
import { getSectionType } from "unwritten:renderer/markup/types-definitions/sections.js";
import { renderMemberContext, withMemberContext } from "unwritten:renderer/markup/utils/context";
import { filterExportableEntities } from "unwritten:renderer/markup/utils/filter";
import { renderEntityPrefix } from "unwritten:renderer/markup/utils/renderer.js";
import { sortExportableEntities } from "unwritten:renderer/markup/utils/sort";

import type { NamespaceEntity } from "unwritten:interpreter:type-definitions/entities";
import type { MarkupRenderContext } from "unwritten:renderer:markup/types-definitions/markup";
Expand Down Expand Up @@ -56,7 +58,10 @@ export function convertNamespaceEntityForTableOfContents(ctx: MarkupRenderContex

return withMemberContext(ctx, name, () => {

const moduleExports = createTableOfContents(ctx, namespaceEntity.exports);
const sortedEntities = sortExportableEntities(ctx, namespaceEntity.exports);
const filteredEntities = filterExportableEntities(ctx, sortedEntities);

const moduleExports = createTableOfContents(ctx, filteredEntities);

return [
anchor,
Expand Down Expand Up @@ -91,7 +96,12 @@ export function convertNamespaceEntityForDocumentation(ctx: MarkupRenderContext,
const example = namespaceEntity.example && convertExamplesForDocumentation(ctx, namespaceEntity.example);
const see = namespaceEntity.see && convertSeeTagsForDocumentation(ctx, namespaceEntity.see);

const children = namespaceEntity.exports.map(exportedEntity => convertEntityForDocumentation(ctx, exportedEntity));
const sortedEntities = sortExportableEntities(ctx, namespaceEntity.exports);
const filteredEntities = filterExportableEntities(ctx, sortedEntities);

const children = filteredEntities.map(
exportedEntity => convertEntityForDocumentation(ctx, exportedEntity)
);

return createSectionNode(
getSectionType(namespaceEntity.kind),
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/markup/utils/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ export function filterExportableEntities(ctx: MarkupRenderContext, entities: Exp

const renderInternal = ctx.config.renderConfig[ctx.renderer.name].renderInternalEntities;

if(renderInternal){
return entities;
}

return entities.filter(entity => {
const isInternal = "internal" in entity && entity.internal;
return renderInternal || !isInternal;
if(isFunctionLikeEntity(entity)){
return entity.signatures.every(signature => !signature.internal);
}
return !entity.internal;
});

}
Expand Down

0 comments on commit 6e1e2bf

Please sign in to comment.