| 1371 | } |
| 1372 | |
| 1373 | class MockFileSystemWatcher implements FileSystemWatcher { |
| 1374 | private onDidCreateEmitter = new Emitter<Uri>(); |
| 1375 | private onDidChangeEmitter = new Emitter<Uri>(); |
| 1376 | private onDidDeleteEmitter = new Emitter<Uri>(); |
| 1377 | |
| 1378 | onDidCreate = this.onDidCreateEmitter.event; |
| 1379 | onDidChange = this.onDidChangeEmitter.event; |
| 1380 | onDidDelete = this.onDidDeleteEmitter.event; |
| 1381 | |
| 1382 | ignoreCreateEvents = false; |
| 1383 | ignoreChangeEvents = false; |
| 1384 | ignoreDeleteEvents = false; |
| 1385 | |
| 1386 | constructor(private pattern: string) { |
| 1387 | // Register this watcher in mockState (will be added to mockState) |
| 1388 | if (mockState.fileWatchers) { |
| 1389 | mockState.fileWatchers.push(this); |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | // Internal methods called by MockFileSystem |
| 1394 | _fireCreate(uri: Uri) { |
| 1395 | if (!this.ignoreCreateEvents && this.matches(uri)) { |
| 1396 | this.onDidCreateEmitter.fire(uri); |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | _fireChange(uri: Uri) { |
| 1401 | if (!this.ignoreChangeEvents && this.matches(uri)) { |
| 1402 | this.onDidChangeEmitter.fire(uri); |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | _fireDelete(uri: Uri) { |
| 1407 | if (!this.ignoreDeleteEvents && this.matches(uri)) { |
| 1408 | this.onDidDeleteEmitter.fire(uri); |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | private matches(uri: Uri): boolean { |
| 1413 | const workspaceFolder = mockState.workspaceFolders[0]; |
| 1414 | if (!workspaceFolder) return false; |
| 1415 | |
| 1416 | const relativePath = path |
| 1417 | .relative(workspaceFolder.uri.fsPath, uri.fsPath) |
| 1418 | .split(path.sep) |
| 1419 | .join('/'); |
| 1420 | // Use micromatch (already imported) for glob matching |
| 1421 | return micromatch.isMatch(relativePath, this.pattern); |
| 1422 | } |
| 1423 | |
| 1424 | dispose() { |
| 1425 | if (mockState.fileWatchers) { |
| 1426 | const index = mockState.fileWatchers.indexOf(this); |
| 1427 | if (index >= 0) { |
| 1428 | mockState.fileWatchers.splice(index, 1); |
| 1429 | } |
| 1430 | } |
nothing calls this directly
no outgoing calls
no test coverage detected