Skip to content

Commit

Permalink
Apply @group and @category later
Browse files Browse the repository at this point in the history
Resolves #2459
  • Loading branch information
Gerrit0 committed Dec 17, 2023
1 parent 2fd2144 commit 56aef14
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Bug Fixes

- Navigation triangle markers should no longer display on a separate line with some font settings, #2457.
- `@group` and `@category` organization is now applied later to allow inherited comments to create groups/categories, #2459.
- Keyword syntax highlighting introduced in 0.25.4 was not always applied to keywords.

## v0.25.4 (2023-11-26)
Expand Down
21 changes: 7 additions & 14 deletions src/lib/converter/plugins/CategoryPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
Reflection,
ContainerReflection,
DeclarationReflection,
Comment,
Expand Down Expand Up @@ -45,7 +44,6 @@ export class CategoryPlugin extends ConverterComponent {
this.owner,
{
[Converter.EVENT_BEGIN]: this.onBegin,
[Converter.EVENT_RESOLVE]: this.onResolve,
[Converter.EVENT_RESOLVE_END]: this.onEndResolve,
},
undefined,
Expand All @@ -68,18 +66,6 @@ export class CategoryPlugin extends ConverterComponent {
}
}

/**
* Triggered when the converter resolves a reflection.
*
* @param context The context object describing the current state the converter is in.
* @param reflection The reflection that is currently resolved.
*/
private onResolve(_context: Context, reflection: Reflection) {
if (reflection instanceof ContainerReflection) {
this.categorize(reflection);
}
}

/**
* Triggered when the converter has finished resolving a project.
*
Expand All @@ -89,6 +75,13 @@ export class CategoryPlugin extends ConverterComponent {
const project = context.project;
this.categorize(project);

for (const id in project.reflections) {
const reflection = project.reflections[id];
if (reflection instanceof ContainerReflection) {
this.categorize(reflection);
}
}

const unusedBoosts = new Set(Object.keys(this.boosts));
for (const boost of this.usedBoosts) {
unusedBoosts.delete(boost);
Expand Down
40 changes: 20 additions & 20 deletions src/lib/converter/plugins/GroupPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
Reflection,
ReflectionKind,
ContainerReflection,
DeclarationReflection,
Expand Down Expand Up @@ -38,26 +37,20 @@ export class GroupPlugin extends ConverterComponent {
* Create a new GroupPlugin instance.
*/
override initialize() {
this.listenTo(this.owner, {
[Converter.EVENT_RESOLVE_BEGIN]: () => {
this.sortFunction = getSortFunction(this.application.options);
GroupPlugin.WEIGHTS = this.groupOrder;
this.listenTo(
this.owner,
{
[Converter.EVENT_RESOLVE_BEGIN]: () => {
this.sortFunction = getSortFunction(
this.application.options,
);
GroupPlugin.WEIGHTS = this.groupOrder;
},
[Converter.EVENT_RESOLVE_END]: this.onEndResolve,
},
[Converter.EVENT_RESOLVE]: this.onResolve,
[Converter.EVENT_RESOLVE_END]: this.onEndResolve,
});
}

/**
* Triggered when the converter resolves a reflection.
*
* @param context The context object describing the current state the converter is in.
* @param reflection The reflection that is currently resolved.
*/
private onResolve(_context: Context, reflection: Reflection) {
if (reflection instanceof ContainerReflection) {
this.group(reflection);
}
undefined,
-100,
);
}

/**
Expand All @@ -68,6 +61,13 @@ export class GroupPlugin extends ConverterComponent {
private onEndResolve(context: Context) {
this.group(context.project);

for (const id in context.project.reflections) {
const reflection = context.project.reflections[id];
if (reflection instanceof ContainerReflection) {
this.group(reflection);
}
}

const unusedBoosts = new Set(Object.keys(this.boosts));
for (const boost of this.usedBoosts) {
unusedBoosts.delete(boost);
Expand Down
21 changes: 21 additions & 0 deletions src/test/behavior.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,27 @@ describe("Behavior Tests", () => {
);
});

it("Inherits @group tag if comment is not redefined", () => {
const project = convert("groupInheritance");
const cls = query(project, "Cls");
equal(cls.groups?.map((g) => g.title), ["Constructors", "Group"]);
equal(
cls.groups.map((g) => g.children),
[[query(project, "Cls.constructor")], [query(project, "Cls.prop")]],
);
});

it("Inherits @category tag if comment is not redefined", () => {
app.options.setValue("categorizeByGroup", false);
const project = convert("categoryInheritance");
const cls = query(project, "Cls");
equal(cls.categories?.map((g) => g.title), ["Cat", "Other"]);
equal(
cls.categories.map((g) => g.children),
[[query(project, "Cls.prop")], [query(project, "Cls.constructor")]],
);
});

it("Handles hidden accessors", () => {
const project = convert("hiddenAccessor");
const test = query(project, "Test");
Expand Down
8 changes: 8 additions & 0 deletions src/test/converter2/behavior/categoryInheritance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Int {
/** @category Cat */
prop: string;
}

export class Cls implements Int {
prop = "";
}
8 changes: 8 additions & 0 deletions src/test/converter2/behavior/groupInheritance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Int {
/** @group Group */
prop: string;
}

export class Cls implements Int {
prop = "";
}

0 comments on commit 56aef14

Please sign in to comment.