2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import * as cp from 'child_process';
7
>
import { CancellationToken } from '../../../base/common/cancellation.js';
8
>
import { CancellationError } from '../../../base/common/errors.js';
9
>
import { Disposable } from '../../../base/common/lifecycle.js';
10
>
import { Schemas } from '../../../base/common/network.js';
11
>
import { URI } from '../../../base/common/uri.js';
12
>
import { ILogService } from '../../log/common/log.js';
13
>
import { rgDiskPath } from '../../../base/node/ripgrep.js';
14
>
15
>
/** Maximum number of files cached per working directory. */
16
>
const MAX_FILES = 50_000;
17
>
18
>
/** TTL for a cached file list before we re-enumerate. */
19
>
const CACHE_TTL_MS = 30_000;
20
>
21
>
interface ICacheEntry {
22
>
readonly promise: Promise<readonly URI[]>;
23
>
expiresAt: number;
24
>
}
25
>
26
>
/**
27
>
* Enumerates files under a working directory using ripgrep, with results
28
>
* cached per working directory for a short TTL.
29
>
*
30
>
* Mirrors the workbench's file-search invocation pattern (see
31
>
* `ripgrepFileSearch.ts` in `vs/workbench/services/search/node/`) but does
32
>
* not depend on the workbench layer — the agent host runs in a separate
33
>
* node process that may not import from `vs/workbench/`.
34
>
*
35
>
* Files are returned as absolute {@link URI}s relative to the working
36
>
* directory. `.gitignore` and other `.ignore` files are honoured by
37
>
* ripgrep. Symlinks are followed.
38
>
*/
39
>
export class AgentHostWorkspaceFiles extends Disposable {
40
>
41
>
private readonly _cache = new Map<string, ICacheEntry>();
42
>
/** Active ripgrep child processes, killed on dispose. */
43
>
private readonly _activeChildren = new Set<cp.ChildProcessWithoutNullStreams>();
44
>
45
>
constructor(
46
@ILogService private readonly _logService: ILogService,
47
) {
48
super();
49
}
51
>
override dispose(): void {
52
for (const child of this._activeChildren) {
53
try {