agentHostFileMonitorService.ts ×14

Frontier kind: Code frontier

unlabeled · c_f812fde51432

501 tests · 10994 LOC · 43 files · introduces 0 tests · 77 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
14 ranges77 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1631 ranges10994 lines · 43 files · Browse complete extent
All tests (intent)
501 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 77 introduced LOC across 14 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/agentHostFileMonitorService.ts 77 introduced LOC · 14 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- agentHostFileMonitorService.ts
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 { disposableTimeout } from '../../../base/common/async.js';
7 > import { IExpression, ParsedExpression, parse } from '../../../base/common/glob.js';
8 > import { Disposable, DisposableMap, DisposableStore, IDisposable, MutableDisposable, toDisposable } from '../../../base/common/lifecycle.js';
9 > import { extUriBiasedIgnorePathCase } from '../../../base/common/resources.js';
10 > import { URI } from '../../../base/common/uri.js';
11 > import { FileChangesEvent, IFileService } from '../../files/common/files.js';
12 > import { createDecorator } from '../../instantiation/common/instantiation.js';
13 > import { ILogService } from '../../log/common/log.js';
14 >
15 > export const IAgentHostFileMonitorService = createDecorator<IAgentHostFileMonitorService>('agentHostFileMonitorService');
16 >
17 > export const DEFAULT_AGENT_HOST_WATCH_EXCLUDES: readonly string[] = Object.freeze([
18 > '**/.git',
19 > '**/.git/lfs/**',
20 > '**/.git/logs/**',
21 > '**/.git/objects/**',
22 > '**/.git/subtree-cache/**',
23 > '**/.git/**/*.lock',
24 > '**/.git/**/FETCH_HEAD',
25 > '**/.git/**/fsmonitor--daemon/**',
26 > '**/*.watchman-cookie-*',
27 > ]);
28 >
29 > export interface IAgentHostFileMonitorOptions {
30 > readonly excludes?: readonly string[];
31 > readonly debounceMs?: number;
32 > }
33 >
34 > export interface IAgentHostFileMonitorService extends IDisposable {
35 > readonly _serviceBrand: undefined;
36 > acquire(folder: URI, callback: () => void, options?: IAgentHostFileMonitorOptions): IDisposable | undefined;
37 > }
38 >
39 > interface IMonitorEntry extends IDisposable {
40 > readonly folder: URI;
41 > readonly callbacks: Set<() => void>;
42 > readonly debounce: MutableDisposable<IDisposable>;
43 > readonly debounceMs: number;
44 > readonly excludeMatcher: ParsedExpression;
45 > }
46 >
47 function normalizeExcludes(excludes: readonly string[]): readonly string[] {
48 return [...excludes].sort();
49 }
51 function parseExcludes(excludes: readonly string[]): ParsedExpression {
52 const expression: IExpression = Object.create(null);
56 return parse(expression);
57 }
59 > export class AgentHostFileMonitorService extends Disposable implements IAgentHostFileMonitorService {
60 > declare readonly _serviceBrand: undefined;
61 >
62 > private static readonly _DEFAULT_DEBOUNCE_MS = 750;
63 >
64 > private readonly _entries = this._register(new DisposableMap<string, IMonitorEntry>());
65 >
66 > constructor(
67 @IFileService private readonly _fileService: IFileService,
68 @ILogService private readonly _logService: ILogService,
74 }));
75 }
77 > acquire(folder: URI, callback: () => void, options: IAgentHostFileMonitorOptions = {}): IDisposable | undefined {
78 const canonicalFolder = this._canonicalizeFolder(folder);
79 const excludes = normalizeExcludes(options.excludes ?? DEFAULT_AGENT_HOST_WATCH_EXCLUDES);
104 });
105 }
107 > private _createEntry(_key: string, folder: URI, excludes: readonly string[], debounceMs: number): IMonitorEntry {
108 const disposable = new DisposableStore();
109 try {
118 }
119 }
121 > private _onDidFilesChange(event: FileChangesEvent): void {
122 for (const key of this._entries.keys()) {
123 this._onDidFilesChangeEntry(key, event);
124 }
125 }
127 > private _onDidFilesChangeEntry(key: string, event: FileChangesEvent): void {
128 const entry = this._entries.get(key);
129 if (!entry || entry.callbacks.size === 0) {
144 }, entry.debounceMs);
145 }
147 > private _hasRelevantRawChange(entry: IMonitorEntry, event: FileChangesEvent): boolean {
148 return this._hasRelevantRawResources(entry, event.rawAdded)
149 || this._hasRelevantRawResources(entry, event.rawUpdated)
150 || this._hasRelevantRawResources(entry, event.rawDeleted);
151 }
153 > private _hasRelevantRawResources(entry: IMonitorEntry, resources: readonly URI[]): boolean {
154 for (const resource of resources) {
155 if (!extUriBiasedIgnorePathCase.isEqualOrParent(resource, entry.folder)) {
162 return false;
163 }
165 > private _isExcluded(entry: IMonitorEntry, resource: URI): boolean {
166 const basename = extUriBiasedIgnorePathCase.basename(resource);
167 const relativePath = extUriBiasedIgnorePathCase.relativePath(entry.folder, resource);
171 return this._matchesExclude(entry, resource.path, basename);
172 }
174 > private _matchesExclude(entry: IMonitorEntry, path: string, basename: string): boolean {
175 return typeof entry.excludeMatcher(path, basename) === 'string';
176 }
178 > private _canonicalizeFolder(folder: URI): URI {
179 return extUriBiasedIgnorePathCase.removeTrailingPathSeparator(extUriBiasedIgnorePathCase.normalizePath(folder));
180 }
182 > private _key(folder: URI, excludes: readonly string[], debounceMs: number): string {
183 return `${extUriBiasedIgnorePathCase.getComparisonKey(folder)}\u0000${debounceMs}\u0000${excludes.join('\n')}`;
184 }