Chromium Code Reviews| Index: pkg/analyzer/lib/src/dart/analysis/file_state.dart |
| diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart |
| index c742f9f61b25cac1c1ebe1fbb56a978cb0e1975e..1c45917e8ef2430d05e2090cb2d36114bf6bf85b 100644 |
| --- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart |
| +++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart |
| @@ -2,6 +2,7 @@ |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| +import 'dart:async'; |
| import 'dart:convert'; |
| import 'dart:typed_data'; |
| @@ -616,6 +617,30 @@ class FileSystemState { |
| final Set<String> knownFilePaths = new Set<String>(); |
| /** |
| + * The paths of files that were added to the set of known files since the |
| + * last [knownFilesSetChanges] notification. |
| + */ |
| + final Set<String> _addedKnownFiles = new Set<String>(); |
| + |
| + /** |
| + * If not `null`, this delay will be awaited instead of the default one. |
| + */ |
| + Duration _knownFilesSetChangesDelay; |
| + |
| + /** |
| + * The instance of timer that is scheduled to send a new update to the |
| + * [knownFilesSetChanges] stream, or `null` if there are no changes to the |
| + * set of known files to notify the stream about. |
| + */ |
| + Timer _knownFilesSetChangesTimer; |
| + |
| + /** |
| + * The controller for the [knownFilesSetChanges] stream. |
| + */ |
| + final StreamController<KnownFilesSetChange> _knownFilesSetChangesController = |
| + new StreamController<KnownFilesSetChange>(); |
| + |
| + /** |
| * Mapping from a path to the flag whether there is a URI for the path. |
| */ |
| final Map<String, bool> _hasUriForPath = {}; |
| @@ -659,6 +684,13 @@ class FileSystemState { |
| List<FileState> get knownFiles => |
| _pathToFiles.values.map((files) => files.first).toList(); |
| + /** |
| + * Return the [Stream] that is periodically notified about changes to the |
| + * known files set. |
| + */ |
| + Stream<KnownFilesSetChange> get knownFilesSetChanges => |
| + _knownFilesSetChangesController.stream; |
| + |
| @visibleForTesting |
| FileSystemStateTestView get test => _testView; |
| @@ -784,9 +816,24 @@ class FileSystemState { |
| knownFilePaths.add(path); |
| files = <FileState>[]; |
| _pathToFiles[path] = files; |
| + // Schedule the stream update. |
| + _addedKnownFiles.add(path); |
| + _scheduleKnownFilesSetChange(); |
| } |
| files.add(file); |
| } |
| + |
| + void _scheduleKnownFilesSetChange() { |
| + Duration delay = _knownFilesSetChangesDelay ?? new Duration(seconds: 1); |
| + _knownFilesSetChangesTimer ??= new Timer(delay, () { |
| + Set<String> addedFiles = _addedKnownFiles.toSet(); |
| + Set<String> removedFiles = new Set<String>(); |
| + _knownFilesSetChangesController |
| + .add(new KnownFilesSetChange(addedFiles, removedFiles)); |
|
Brian Wilkerson
2017/04/19 20:09:52
Do we want to only add to the stream if at least o
scheglov
2017/04/19 20:21:47
Yes, the intention is that we send only useful not
|
| + _addedKnownFiles.clear(); |
| + _knownFilesSetChangesTimer = null; |
| + }); |
| + } |
| } |
| @visibleForTesting |
| @@ -806,6 +853,20 @@ class FileSystemStateTestView { |
| .where((f) => f._transitiveSignature == null) |
| .toSet(); |
| } |
| + |
| + void set knownFilesDelay(Duration value) { |
| + state._knownFilesSetChangesDelay = value; |
| + } |
| +} |
| + |
| +/** |
| + * Information about changes to the known file set. |
| + */ |
| +class KnownFilesSetChange { |
| + final Set<String> added; |
| + final Set<String> removed; |
| + |
| + KnownFilesSetChange(this.added, this.removed); |
| } |
| class _FastaElementProxy implements fasta.KernelClassElement { |