@@ -57,14 +57,21 @@ export function getExcludePattern() {
57
57
const getExcludePatternOnce = once ( getExcludePattern )
58
58
59
59
/**
60
- * WatchedFiles lets us index files in the current registry . It is used
60
+ * WatchedFiles lets us watch files on the filesystem . It is used
61
61
* for CFN templates among other things. WatchedFiles holds a list of pairs of
62
62
* the absolute path to the file or "untitled:" URI along with a transform of it that is useful for
63
63
* where it is used. For example, for templates, it parses the template and stores it.
64
64
*
65
- * Initialize the registry by adding watch patterns and excluded patterns via
66
- * `addWatchPatterns`, `watchUntitledFiles`, and `addExcludedPattern` and then
67
- * calling the `rebuild` function to begin registering files.
65
+ * Initialize the registry by adding patterns, followed by a required call to `rebuild`.
66
+
67
+ * Example:
68
+ * ```
69
+ * registry.addExcludedPattern(/.*[/\\]\.aws-sam([/\\].*|$)/)
70
+ * registry.addExcludedPattern('**\/*.{yaml,yml}')
71
+ * registry.addWatchPatterns([/.*devfile\.(yaml|yml)/i])
72
+ * registry.watchUntitledFiles()
73
+ * await registry.rebuild(cancellationTimeout)
74
+ * ```
68
75
*/
69
76
export abstract class WatchedFiles < T > implements vscode . Disposable {
70
77
private isWatching : boolean = false
@@ -284,34 +291,40 @@ export abstract class WatchedFiles<T> implements vscode.Disposable {
284
291
/**
285
292
* Builds/rebuilds registry using current glob and exclusion patterns. ***Necessary to init registry***.
286
293
*
287
- * @param cancellationTimeout Optional timeout that can trigger canceling additional loading on completion (manual or timed)
294
+ * @param cancel Optional timeout that can trigger canceling additional loading on completion (manual or timed)
288
295
*/
289
- public async rebuild ( cancellationTimeout ?: Timeout ) : Promise < void > {
296
+ public async rebuild ( cancel ?: Timeout ) : Promise < void > {
290
297
let skips = 0
298
+ let todo = 0
291
299
this . isWatching = true
292
300
this . reset ( )
293
301
294
302
const exclude = getExcludePatternOnce ( )
295
- getLogger ( ) . info ( `${ this . name } : Building registry with the following criteria : ${ this . outputPatterns ( ) } ` )
296
- for ( let i = 0 ; i < this . globs . length && ! cancellationTimeout ?. completed ; i ++ ) {
303
+ getLogger ( ) . info ( `${ this . name } : building with: ${ this . outputPatterns ( ) } ` )
304
+ for ( let i = 0 ; i < this . globs . length && ! cancel ?. completed ; i ++ ) {
297
305
const glob = this . globs [ i ]
298
306
try {
299
307
const found = await vscode . workspace . findFiles ( glob , exclude )
300
- for ( let j = 0 ; j < found . length && ! cancellationTimeout ?. completed ; j ++ ) {
301
- await this . addItem ( found [ j ] , true )
308
+ todo = found . length
309
+ for ( let j = 0 ; j < found . length && ! cancel ?. completed ; j ++ , todo -- ) {
310
+ const r = await this . addItem ( found [ j ] , true )
311
+ if ( ! r ) {
312
+ skips ++
313
+ }
302
314
}
303
315
} catch ( e ) {
304
- // file not processable
305
- skips ++
306
316
const err = e as Error
307
- getLogger ( ) . error ( `${ this . name } : watchedFiles: findFiles("%s", "%s"): %s` , glob , exclude , err . message )
317
+ if ( err . name !== 'Canceled' ) {
318
+ // vscode may throw nonsense "Canceled" errors when stopping the debugger.
319
+ getLogger ( ) . error ( `%s: findFiles("%s", "%s"): %s` , this . name , glob , exclude , err . message )
320
+ }
308
321
}
309
322
}
310
323
getLogger ( ) . info (
311
- `${ this . name } : Registered %s items%s%s` ,
324
+ `${ this . name } : processed %s items%s%s` ,
312
325
this . registryData . size ,
313
- cancellationTimeout ?. completed ? ' (cancelled)' : '' ,
314
- skips > 0 ? `, skipped ${ skips } entries ` : ''
326
+ cancel ?. completed ? ` (cancelled, ${ todo } left)` : '' ,
327
+ skips > 0 ? `, skipped ${ skips } ` : ''
315
328
)
316
329
}
317
330
0 commit comments