Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/file_state.dart

Issue 2826243002: Add FileSystemState.knownFilesSetChanges stream. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/file_state_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async';
5 import 'dart:convert'; 6 import 'dart:convert';
6 import 'dart:typed_data'; 7 import 'dart:typed_data';
7 8
8 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
10 import 'package:analyzer/error/listener.dart'; 11 import 'package:analyzer/error/listener.dart';
11 import 'package:analyzer/file_system/file_system.dart'; 12 import 'package:analyzer/file_system/file_system.dart';
12 import 'package:analyzer/src/dart/analysis/byte_store.dart'; 13 import 'package:analyzer/src/dart/analysis/byte_store.dart';
13 import 'package:analyzer/src/dart/analysis/defined_names.dart'; 14 import 'package:analyzer/src/dart/analysis/defined_names.dart';
14 import 'package:analyzer/src/dart/analysis/driver.dart'; 15 import 'package:analyzer/src/dart/analysis/driver.dart';
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 * Mapping from a URI to the corresponding [FileState]. 610 * Mapping from a URI to the corresponding [FileState].
610 */ 611 */
611 final Map<Uri, FileState> _uriToFile = {}; 612 final Map<Uri, FileState> _uriToFile = {};
612 613
613 /** 614 /**
614 * All known file paths. 615 * All known file paths.
615 */ 616 */
616 final Set<String> knownFilePaths = new Set<String>(); 617 final Set<String> knownFilePaths = new Set<String>();
617 618
618 /** 619 /**
620 * The paths of files that were added to the set of known files since the
621 * last [knownFilesSetChanges] notification.
622 */
623 final Set<String> _addedKnownFiles = new Set<String>();
624
625 /**
626 * If not `null`, this delay will be awaited instead of the default one.
627 */
628 Duration _knownFilesSetChangesDelay;
629
630 /**
631 * The instance of timer that is scheduled to send a new update to the
632 * [knownFilesSetChanges] stream, or `null` if there are no changes to the
633 * set of known files to notify the stream about.
634 */
635 Timer _knownFilesSetChangesTimer;
636
637 /**
638 * The controller for the [knownFilesSetChanges] stream.
639 */
640 final StreamController<KnownFilesSetChange> _knownFilesSetChangesController =
641 new StreamController<KnownFilesSetChange>();
642
643 /**
619 * Mapping from a path to the flag whether there is a URI for the path. 644 * Mapping from a path to the flag whether there is a URI for the path.
620 */ 645 */
621 final Map<String, bool> _hasUriForPath = {}; 646 final Map<String, bool> _hasUriForPath = {};
622 647
623 /** 648 /**
624 * Mapping from a path to the corresponding [FileState]s, canonical or not. 649 * Mapping from a path to the corresponding [FileState]s, canonical or not.
625 */ 650 */
626 final Map<String, List<FileState>> _pathToFiles = {}; 651 final Map<String, List<FileState>> _pathToFiles = {};
627 652
628 /** 653 /**
(...skipping 23 matching lines...) Expand all
652 this._salt) { 677 this._salt) {
653 _testView = new FileSystemStateTestView(this); 678 _testView = new FileSystemStateTestView(this);
654 } 679 }
655 680
656 /** 681 /**
657 * Return the known files. 682 * Return the known files.
658 */ 683 */
659 List<FileState> get knownFiles => 684 List<FileState> get knownFiles =>
660 _pathToFiles.values.map((files) => files.first).toList(); 685 _pathToFiles.values.map((files) => files.first).toList();
661 686
687 /**
688 * Return the [Stream] that is periodically notified about changes to the
689 * known files set.
690 */
691 Stream<KnownFilesSetChange> get knownFilesSetChanges =>
692 _knownFilesSetChangesController.stream;
693
662 @visibleForTesting 694 @visibleForTesting
663 FileSystemStateTestView get test => _testView; 695 FileSystemStateTestView get test => _testView;
664 696
665 /** 697 /**
666 * Return the [FileState] instance that correspond to an unresolved URI. 698 * Return the [FileState] instance that correspond to an unresolved URI.
667 */ 699 */
668 FileState get unresolvedFile { 700 FileState get unresolvedFile {
669 if (_unresolvedFile == null) { 701 if (_unresolvedFile == null) {
670 _unresolvedFile = new FileState._(this, null, null, null); 702 _unresolvedFile = new FileState._(this, null, null, null);
671 _unresolvedFile.refresh(); 703 _unresolvedFile.refresh();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 _pathToCanonicalFile.clear(); 809 _pathToCanonicalFile.clear();
778 _partToLibraries.clear(); 810 _partToLibraries.clear();
779 } 811 }
780 812
781 void _addFileWithPath(String path, FileState file) { 813 void _addFileWithPath(String path, FileState file) {
782 var files = _pathToFiles[path]; 814 var files = _pathToFiles[path];
783 if (files == null) { 815 if (files == null) {
784 knownFilePaths.add(path); 816 knownFilePaths.add(path);
785 files = <FileState>[]; 817 files = <FileState>[];
786 _pathToFiles[path] = files; 818 _pathToFiles[path] = files;
819 // Schedule the stream update.
820 _addedKnownFiles.add(path);
821 _scheduleKnownFilesSetChange();
787 } 822 }
788 files.add(file); 823 files.add(file);
789 } 824 }
825
826 void _scheduleKnownFilesSetChange() {
827 Duration delay = _knownFilesSetChangesDelay ?? new Duration(seconds: 1);
828 _knownFilesSetChangesTimer ??= new Timer(delay, () {
829 Set<String> addedFiles = _addedKnownFiles.toSet();
830 Set<String> removedFiles = new Set<String>();
831 _knownFilesSetChangesController
832 .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
833 _addedKnownFiles.clear();
834 _knownFilesSetChangesTimer = null;
835 });
836 }
790 } 837 }
791 838
792 @visibleForTesting 839 @visibleForTesting
793 class FileSystemStateTestView { 840 class FileSystemStateTestView {
794 final FileSystemState state; 841 final FileSystemState state;
795 842
796 FileSystemStateTestView(this.state); 843 FileSystemStateTestView(this.state);
797 844
798 Set<FileState> get filesWithoutTransitiveFiles { 845 Set<FileState> get filesWithoutTransitiveFiles {
799 return state._uriToFile.values 846 return state._uriToFile.values
800 .where((f) => f._transitiveFiles == null) 847 .where((f) => f._transitiveFiles == null)
801 .toSet(); 848 .toSet();
802 } 849 }
803 850
804 Set<FileState> get filesWithoutTransitiveSignature { 851 Set<FileState> get filesWithoutTransitiveSignature {
805 return state._uriToFile.values 852 return state._uriToFile.values
806 .where((f) => f._transitiveSignature == null) 853 .where((f) => f._transitiveSignature == null)
807 .toSet(); 854 .toSet();
808 } 855 }
856
857 void set knownFilesDelay(Duration value) {
858 state._knownFilesSetChangesDelay = value;
859 }
860 }
861
862 /**
863 * Information about changes to the known file set.
864 */
865 class KnownFilesSetChange {
866 final Set<String> added;
867 final Set<String> removed;
868
869 KnownFilesSetChange(this.added, this.removed);
809 } 870 }
810 871
811 class _FastaElementProxy implements fasta.KernelClassElement { 872 class _FastaElementProxy implements fasta.KernelClassElement {
812 @override 873 @override
813 final fasta.KernelInterfaceType rawType = new _FastaInterfaceTypeProxy(); 874 final fasta.KernelInterfaceType rawType = new _FastaInterfaceTypeProxy();
814 875
815 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 876 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
816 } 877 }
817 878
818 class _FastaElementStoreProxy implements fasta.ElementStore { 879 class _FastaElementStoreProxy implements fasta.ElementStore {
819 final _elements = <fasta.Builder, _FastaElementProxy>{}; 880 final _elements = <fasta.Builder, _FastaElementProxy>{};
820 881
821 @override 882 @override
822 _FastaElementProxy operator [](fasta.Builder builder) => 883 _FastaElementProxy operator [](fasta.Builder builder) =>
823 _elements.putIfAbsent(builder, () => new _FastaElementProxy()); 884 _elements.putIfAbsent(builder, () => new _FastaElementProxy());
824 885
825 @override 886 @override
826 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 887 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
827 } 888 }
828 889
829 class _FastaInterfaceTypeProxy implements fasta.KernelInterfaceType { 890 class _FastaInterfaceTypeProxy implements fasta.KernelInterfaceType {
830 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 891 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
831 } 892 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/file_state_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698