Skip to content

Commit ada1dca

Browse files
lambdalisueclaude
andcommitted
docs: add comprehensive JSDoc to processor modules
- Document collect.ts for asynchronous item collection - Document match.ts for filtering with multiple matchers - Document sort.ts for item ordering strategies - Document render.ts for display transformation - Document preview.ts for preview generation - Include configuration options and method documentation - Add examples demonstrating processor usage 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent d7b2628 commit ada1dca

File tree

5 files changed

+457
-0
lines changed

5 files changed

+457
-0
lines changed

denops/fall/processor/collect.ts

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/**
2+
* @module processor/collect
3+
*
4+
* Collection processor for vim-fall.
5+
*
6+
* This module provides the CollectProcessor class which manages the collection
7+
* of items from a source. It handles:
8+
*
9+
* - Asynchronous item collection with progress updates
10+
* - Chunking for performance optimization
11+
* - Item deduplication and ID assignment
12+
* - Pause/resume functionality
13+
* - Threshold limiting to prevent memory issues
14+
*
15+
* The processor emits events during collection to update the UI and coordinate
16+
* with other components.
17+
*/
18+
119
import type { Denops } from "jsr:@denops/std@^7.3.2";
220
import { take } from "jsr:@core/iterutil@^0.9.0/async/take";
321
import { map } from "jsr:@core/iterutil@^0.9.0/map";
@@ -8,17 +26,60 @@ import { Chunker } from "../lib/chunker.ts";
826
import { UniqueOrderedList } from "../lib/unique_ordered_list.ts";
927
import { dispatch } from "../event.ts";
1028

29+
/** Default maximum number of items to collect */
1130
const THRESHOLD = 100000;
31+
32+
/** Default number of items to process in each chunk */
1233
const CHUNK_SIZE = 1000;
34+
35+
/** Default interval in milliseconds between chunk updates */
1336
const CHUNK_INTERVAL = 100;
1437

38+
/**
39+
* Configuration options for the CollectProcessor.
40+
*
41+
* @template T - The type of detail data associated with each item
42+
*/
1543
export type CollectProcessorOptions<T extends Detail> = {
44+
/** Initial items to populate the processor with (useful for resume) */
1645
initialItems?: readonly IdItem<T>[];
46+
47+
/** Maximum number of items to collect (default: 100000) */
1748
threshold?: number;
49+
50+
/** Number of items to process before emitting an update (default: 1000) */
1851
chunkSize?: number;
52+
53+
/** Maximum time in ms between updates regardless of chunk size (default: 100) */
1954
chunkInterval?: number;
2055
};
2156

57+
/**
58+
* Processor responsible for collecting items from a source.
59+
*
60+
* The CollectProcessor manages the asynchronous collection of items from a source,
61+
* handling chunking, deduplication, and progress updates. It can be paused and
62+
* resumed, making it suitable for long-running collection operations.
63+
*
64+
* @template T - The type of detail data associated with each item
65+
*
66+
* @example
67+
* ```typescript
68+
* const processor = new CollectProcessor(fileSource, {
69+
* threshold: 50000,
70+
* chunkSize: 500,
71+
* });
72+
*
73+
* // Start collecting
74+
* processor.start(denops, { args: ["--hidden"] });
75+
*
76+
* // Access collected items
77+
* console.log(processor.items.length);
78+
*
79+
* // Pause if needed
80+
* processor.pause();
81+
* ```
82+
*/
2283
export class CollectProcessor<T extends Detail> implements Disposable {
2384
readonly #controller: AbortController = new AbortController();
2485
readonly #items: UniqueOrderedList<IdItem<T>>;
@@ -28,6 +89,12 @@ export class CollectProcessor<T extends Detail> implements Disposable {
2889
#processing?: Promise<void>;
2990
#paused?: PromiseWithResolvers<void>;
3091

92+
/**
93+
* Creates a new CollectProcessor.
94+
*
95+
* @param source - The source to collect items from
96+
* @param options - Configuration options
97+
*/
3198
constructor(
3299
readonly source: Source<T>,
33100
options: CollectProcessorOptions<T> = {},
@@ -45,10 +112,20 @@ export class CollectProcessor<T extends Detail> implements Disposable {
45112
);
46113
}
47114

115+
/**
116+
* Gets the currently collected items.
117+
*
118+
* @returns An array of collected items with assigned IDs
119+
*/
48120
get items(): readonly IdItem<T>[] {
49121
return this.#items.items;
50122
}
51123

124+
/**
125+
* Validates that the processor is not disposed.
126+
*
127+
* @throws Error if the processor is disposed
128+
*/
52129
#validateAvailability(): void {
53130
try {
54131
this.#controller.signal.throwIfAborted();
@@ -60,6 +137,26 @@ export class CollectProcessor<T extends Detail> implements Disposable {
60137
}
61138
}
62139

140+
/**
141+
* Starts or resumes the collection process.
142+
*
143+
* If collection is already in progress and paused, this will resume it.
144+
* Otherwise, it starts a new collection process.
145+
*
146+
* The method emits the following events:
147+
* - `collect-processor-started`: When collection begins
148+
* - `collect-processor-updated`: When new items are collected
149+
* - `collect-processor-succeeded`: When collection completes successfully
150+
* - `collect-processor-failed`: If an error occurs
151+
*
152+
* @param denops - The Denops instance
153+
* @param params - Parameters to pass to the source's collect method
154+
*
155+
* @example
156+
* ```typescript
157+
* processor.start(denops, { args: ["--hidden", "--no-ignore"] });
158+
* ```
159+
*/
63160
start(
64161
denops: Denops,
65162
params: CollectParams,
@@ -107,6 +204,20 @@ export class CollectProcessor<T extends Detail> implements Disposable {
107204
});
108205
}
109206

207+
/**
208+
* Pauses the collection process.
209+
*
210+
* The collection can be resumed by calling `start()` again.
211+
* This is useful for temporarily stopping collection to free up
212+
* resources or when the user navigates away.
213+
*
214+
* @example
215+
* ```typescript
216+
* processor.pause();
217+
* // Later...
218+
* processor.start(denops, params); // Resumes from where it left off
219+
* ```
220+
*/
110221
pause(): void {
111222
this.#validateAvailability();
112223
if (!this.#processing) {
@@ -118,6 +229,9 @@ export class CollectProcessor<T extends Detail> implements Disposable {
118229
});
119230
}
120231

232+
/**
233+
* Resumes a paused collection process.
234+
*/
121235
#resume(): void {
122236
if (!this.#paused) {
123237
return;
@@ -126,6 +240,12 @@ export class CollectProcessor<T extends Detail> implements Disposable {
126240
this.#paused = undefined;
127241
}
128242

243+
/**
244+
* Disposes of the processor and cancels any ongoing collection.
245+
*
246+
* This method is called automatically when the processor is no longer needed.
247+
* It aborts the collection process and cleans up resources.
248+
*/
129249
[Symbol.dispose](): void {
130250
try {
131251
this.#controller.abort(null);

denops/fall/processor/match.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/**
2+
* @module processor/match
3+
*
4+
* Matching processor for vim-fall.
5+
*
6+
* This module provides the MatchProcessor class which filters items based on
7+
* user queries using configurable matchers. It supports:
8+
*
9+
* - Multiple matcher implementations (fuzzy, substring, regex, etc.)
10+
* - Incremental matching for performance optimization
11+
* - Asynchronous processing with chunking
12+
* - Query caching to avoid redundant processing
13+
* - Matcher switching during runtime
14+
*
15+
* The processor transforms collected items into filtered items that match
16+
* the current query, emitting events to coordinate with other components.
17+
*/
18+
119
import type { Denops } from "jsr:@denops/std@^7.3.2";
220
import { delay } from "jsr:@std/async@^1.0.0/delay";
321
import { take } from "jsr:@core/iterutil@^0.9.0/async/take";
@@ -8,22 +26,75 @@ import { Chunker } from "../lib/chunker.ts";
826
import { ItemBelt } from "../lib/item_belt.ts";
927
import { dispatch } from "../event.ts";
1028

29+
/** Default delay interval between processing cycles */
1130
const INTERVAL = 0;
31+
32+
/** Default maximum number of items to process */
1233
const THRESHOLD = 100000;
34+
35+
/** Default number of items to process in each chunk */
1336
const CHUNK_SIZE = 1000;
37+
38+
/** Default interval in milliseconds between chunk updates */
1439
const CHUNK_INTERVAL = 100;
1540

41+
/**
42+
* Configuration options for the MatchProcessor.
43+
*
44+
* @template T - The type of detail data associated with each item
45+
*/
1646
export type MatchProcessorOptions<T extends Detail> = {
47+
/** Initial filtered items (useful for resume) */
1748
initialItems?: readonly IdItem<T>[];
49+
50+
/** Initial query string */
1851
initialQuery?: string;
52+
53+
/** Initial matcher index */
1954
initialIndex?: number;
55+
56+
/** Delay between processing cycles in ms (default: 0) */
2057
interval?: number;
58+
59+
/** Maximum items to process (default: 100000) */
2160
threshold?: number;
61+
62+
/** Items per chunk (default: 1000) */
2263
chunkSize?: number;
64+
65+
/** Max time between chunk updates in ms (default: 100) */
2366
chunkInterval?: number;
67+
68+
/** Enable incremental matching mode for better performance */
2469
incremental?: boolean;
2570
};
2671

72+
/**
73+
* Processor responsible for filtering items based on user queries.
74+
*
75+
* The MatchProcessor applies matchers to filter collected items according to
76+
* the current query. It supports multiple matchers that can be switched
77+
* dynamically, and provides both standard and incremental matching modes.
78+
*
79+
* @template T - The type of detail data associated with each item
80+
*
81+
* @example
82+
* ```typescript
83+
* const processor = new MatchProcessor([fzf(), substring()], {
84+
* incremental: true,
85+
* chunkSize: 500,
86+
* });
87+
*
88+
* // Start matching
89+
* processor.start(denops, {
90+
* items: collectedItems,
91+
* query: "search term",
92+
* });
93+
*
94+
* // Switch matcher
95+
* processor.matcherIndex = 1;
96+
* ```
97+
*/
2798
export class MatchProcessor<T extends Detail> implements Disposable {
2899
readonly matchers: ItemBelt<Matcher<T>>;
29100
readonly #interval: number;
@@ -57,18 +128,34 @@ export class MatchProcessor<T extends Detail> implements Disposable {
57128
return this.matchers.current!;
58129
}
59130

131+
/**
132+
* Gets the currently filtered items.
133+
*
134+
* @returns Array of items that match the current query
135+
*/
60136
get items(): IdItem<T>[] {
61137
return this.#items;
62138
}
63139

140+
/**
141+
* Gets the total number of available matchers.
142+
*/
64143
get matcherCount(): number {
65144
return this.matchers.count;
66145
}
67146

147+
/**
148+
* Gets the current matcher index.
149+
*/
68150
get matcherIndex(): number {
69151
return this.matchers.index;
70152
}
71153

154+
/**
155+
* Sets the current matcher index.
156+
*
157+
* @param index - The matcher index or "$" for the last matcher
158+
*/
72159
set matcherIndex(index: number | "$") {
73160
if (index === "$") {
74161
index = this.matchers.count;
@@ -87,6 +174,34 @@ export class MatchProcessor<T extends Detail> implements Disposable {
87174
}
88175
}
89176

177+
/**
178+
* Starts the matching process.
179+
*
180+
* This method filters the provided items based on the query using the
181+
* current matcher. It handles:
182+
* - Query caching to avoid redundant processing
183+
* - Incremental matching when enabled
184+
* - Asynchronous processing with progress updates
185+
*
186+
* The method emits:
187+
* - `match-processor-started`: When matching begins
188+
* - `match-processor-updated`: When new matches are found
189+
* - `match-processor-succeeded`: When matching completes
190+
* - `match-processor-failed`: If an error occurs
191+
*
192+
* @param denops - The Denops instance
193+
* @param params - Items to filter and the query string
194+
* @param options - Optional configuration
195+
* @param options.restart - Force restart even if processing
196+
*
197+
* @example
198+
* ```typescript
199+
* processor.start(denops, {
200+
* items: collectedItems,
201+
* query: "search term",
202+
* });
203+
* ```
204+
*/
90205
start(
91206
denops: Denops,
92207
{ items, query }: MatchParams<T>,
@@ -158,6 +273,12 @@ export class MatchProcessor<T extends Detail> implements Disposable {
158273
});
159274
}
160275

276+
/**
277+
* Disposes of the processor and cancels any ongoing matching.
278+
*
279+
* This method is called automatically when the processor is no longer needed.
280+
* It aborts the matching process and cleans up resources.
281+
*/
161282
[Symbol.dispose](): void {
162283
try {
163284
this.#controller.abort(null);

0 commit comments

Comments
 (0)