@@ -8,7 +8,7 @@ import { ReflectionCategory } from "../../models";
88import { Component , ConverterComponent } from "../components" ;
99import { Converter } from "../converter" ;
1010import type { Context } from "../context" ;
11- import { Option , getSortFunction , removeIf } from "../../utils" ;
11+ import { Option , getSortFunction } from "../../utils" ;
1212
1313/**
1414 * A handler that sorts and categorizes the found reflections in the resolving phase.
@@ -157,13 +157,13 @@ export class CategoryPlugin extends ConverterComponent {
157157 * relevance boost to be used when searching
158158 * @returns An array containing all children of the given reflection categorized
159159 */
160- getReflectionCategories (
160+ private getReflectionCategories (
161161 reflections : DeclarationReflection [ ] ,
162162 ) : ReflectionCategory [ ] {
163163 const categories = new Map < string , ReflectionCategory > ( ) ;
164164
165165 for ( const child of reflections ) {
166- const childCategories = this . getCategories ( child ) ;
166+ const childCategories = this . extractCategories ( child ) ;
167167 if ( childCategories . size === 0 ) {
168168 childCategories . add ( CategoryPlugin . defaultCategory ) ;
169169 }
@@ -197,31 +197,18 @@ export class CategoryPlugin extends ConverterComponent {
197197 * @privateRemarks
198198 * If you change this, also update getGroups in GroupPlugin accordingly.
199199 */
200- getCategories ( reflection : DeclarationReflection ) {
201- const categories = new Set < string > ( ) ;
202- function extractCategoryTags ( comment : Comment | undefined ) {
203- if ( ! comment ) return ;
204- removeIf ( comment . blockTags , ( tag ) => {
205- if ( tag . tag === "@category" ) {
206- categories . add (
207- Comment . combineDisplayParts ( tag . content ) . trim ( ) ,
208- ) ;
209-
210- return true ;
211- }
212- return false ;
213- } ) ;
214- }
200+ private extractCategories ( reflection : DeclarationReflection ) {
201+ const categories = CategoryPlugin . getCategories ( reflection ) ;
215202
216- extractCategoryTags ( reflection . comment ) ;
203+ reflection . comment ?. removeTags ( "@category" ) ;
217204 for ( const sig of reflection . getNonIndexSignatures ( ) ) {
218- extractCategoryTags ( sig . comment ) ;
205+ sig . comment ?. removeTags ( "@category" ) ;
219206 }
220207
221208 if ( reflection . type ?. type === "reflection" ) {
222- extractCategoryTags ( reflection . type . declaration . comment ) ;
209+ reflection . type . declaration . comment ?. removeTags ( "@category" ) ;
223210 for ( const sig of reflection . type . declaration . getNonIndexSignatures ( ) ) {
224- extractCategoryTags ( sig . comment ) ;
211+ sig . comment ?. removeTags ( "@category" ) ;
225212 }
226213 }
227214
@@ -245,7 +232,7 @@ export class CategoryPlugin extends ConverterComponent {
245232 * @param b The right reflection to sort.
246233 * @returns The sorting weight.
247234 */
248- static sortCatCallback (
235+ private static sortCatCallback (
249236 a : ReflectionCategory ,
250237 b : ReflectionCategory ,
251238 ) : number {
@@ -268,4 +255,34 @@ export class CategoryPlugin extends ConverterComponent {
268255 }
269256 return aWeight - bWeight ;
270257 }
258+
259+ static getCategories ( reflection : DeclarationReflection ) {
260+ const categories = new Set < string > ( ) ;
261+ function discoverCategories ( comment : Comment | undefined ) {
262+ if ( ! comment ) return ;
263+ for ( const tag of comment . blockTags ) {
264+ if ( tag . tag === "@category" ) {
265+ categories . add (
266+ Comment . combineDisplayParts ( tag . content ) . trim ( ) ,
267+ ) ;
268+ }
269+ }
270+ }
271+
272+ discoverCategories ( reflection . comment ) ;
273+ for ( const sig of reflection . getNonIndexSignatures ( ) ) {
274+ discoverCategories ( sig . comment ) ;
275+ }
276+
277+ if ( reflection . type ?. type === "reflection" ) {
278+ discoverCategories ( reflection . type . declaration . comment ) ;
279+ for ( const sig of reflection . type . declaration . getNonIndexSignatures ( ) ) {
280+ discoverCategories ( sig . comment ) ;
281+ }
282+ }
283+
284+ categories . delete ( "" ) ;
285+
286+ return categories ;
287+ }
271288}
0 commit comments