| OLD | NEW |
| 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:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 import 'package:analyzer/src/source/source_resource.dart'; | 24 import 'package:analyzer/src/source/source_resource.dart'; |
| 25 import 'package:analyzer/src/summary/format.dart'; | 25 import 'package:analyzer/src/summary/format.dart'; |
| 26 import 'package:analyzer/src/summary/idl.dart'; | 26 import 'package:analyzer/src/summary/idl.dart'; |
| 27 import 'package:analyzer/src/summary/name_filter.dart'; | 27 import 'package:analyzer/src/summary/name_filter.dart'; |
| 28 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 28 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
| 29 import 'package:analyzer/src/summary/summarize_ast.dart'; | 29 import 'package:analyzer/src/summary/summarize_ast.dart'; |
| 30 import 'package:convert/convert.dart'; | 30 import 'package:convert/convert.dart'; |
| 31 import 'package:crypto/crypto.dart'; | 31 import 'package:crypto/crypto.dart'; |
| 32 import 'package:front_end/src/base/api_signature.dart'; | 32 import 'package:front_end/src/base/api_signature.dart'; |
| 33 import 'package:front_end/src/base/performace_logger.dart'; | 33 import 'package:front_end/src/base/performace_logger.dart'; |
| 34 import 'package:front_end/src/byte_store/byte_store.dart'; |
| 34 import 'package:front_end/src/fasta/builder/builder.dart' as fasta; | 35 import 'package:front_end/src/fasta/builder/builder.dart' as fasta; |
| 35 import 'package:front_end/src/fasta/parser/parser.dart' as fasta; | 36 import 'package:front_end/src/fasta/parser/parser.dart' as fasta; |
| 36 import 'package:front_end/src/fasta/scanner.dart' as fasta; | 37 import 'package:front_end/src/fasta/scanner.dart' as fasta; |
| 37 import 'package:front_end/src/byte_store/byte_store.dart'; | |
| 38 import 'package:meta/meta.dart'; | 38 import 'package:meta/meta.dart'; |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * [FileContentOverlay] is used to temporary override content of files. | 41 * [FileContentOverlay] is used to temporary override content of files. |
| 42 */ | 42 */ |
| 43 class FileContentOverlay { | 43 class FileContentOverlay { |
| 44 final _map = <String, String>{}; | 44 final _map = <String, String>{}; |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * Return the paths currently being overridden. | 47 * Return the paths currently being overridden. |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 Duration _knownFilesSetChangesDelay; | 698 Duration _knownFilesSetChangesDelay; |
| 699 | 699 |
| 700 /** | 700 /** |
| 701 * The instance of timer that is scheduled to send a new update to the | 701 * The instance of timer that is scheduled to send a new update to the |
| 702 * [knownFilesSetChanges] stream, or `null` if there are no changes to the | 702 * [knownFilesSetChanges] stream, or `null` if there are no changes to the |
| 703 * set of known files to notify the stream about. | 703 * set of known files to notify the stream about. |
| 704 */ | 704 */ |
| 705 Timer _knownFilesSetChangesTimer; | 705 Timer _knownFilesSetChangesTimer; |
| 706 | 706 |
| 707 /** | 707 /** |
| 708 * Whether the [knownFilesSetChanges] stream is requested. |
| 709 */ |
| 710 bool _knownFilesSetChangesRequested = false; |
| 711 |
| 712 /** |
| 708 * The controller for the [knownFilesSetChanges] stream. | 713 * The controller for the [knownFilesSetChanges] stream. |
| 709 */ | 714 */ |
| 710 final StreamController<KnownFilesSetChange> _knownFilesSetChangesController = | 715 final StreamController<KnownFilesSetChange> _knownFilesSetChangesController = |
| 711 new StreamController<KnownFilesSetChange>(); | 716 new StreamController<KnownFilesSetChange>(); |
| 712 | 717 |
| 713 /** | 718 /** |
| 714 * Mapping from a path to the flag whether there is a URI for the path. | 719 * Mapping from a path to the flag whether there is a URI for the path. |
| 715 */ | 720 */ |
| 716 final Map<String, bool> _hasUriForPath = {}; | 721 final Map<String, bool> _hasUriForPath = {}; |
| 717 | 722 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 /** | 757 /** |
| 753 * Return the known files. | 758 * Return the known files. |
| 754 */ | 759 */ |
| 755 List<FileState> get knownFiles => | 760 List<FileState> get knownFiles => |
| 756 _pathToFiles.values.map((files) => files.first).toList(); | 761 _pathToFiles.values.map((files) => files.first).toList(); |
| 757 | 762 |
| 758 /** | 763 /** |
| 759 * Return the [Stream] that is periodically notified about changes to the | 764 * Return the [Stream] that is periodically notified about changes to the |
| 760 * known files set. | 765 * known files set. |
| 761 */ | 766 */ |
| 762 Stream<KnownFilesSetChange> get knownFilesSetChanges => | 767 Stream<KnownFilesSetChange> get knownFilesSetChanges { |
| 763 _knownFilesSetChangesController.stream; | 768 // If this is the first (and actually the only) time when the stream is |
| 769 // requested, schedule the timer to send updates. |
| 770 if (!_knownFilesSetChangesRequested) { |
| 771 _knownFilesSetChangesRequested = true; |
| 772 _scheduleKnownFilesSetChange(); |
| 773 } |
| 774 return _knownFilesSetChangesController.stream; |
| 775 } |
| 764 | 776 |
| 765 @visibleForTesting | 777 @visibleForTesting |
| 766 FileSystemStateTestView get test => _testView; | 778 FileSystemStateTestView get test => _testView; |
| 767 | 779 |
| 768 /** | 780 /** |
| 769 * Return the [FileState] instance that correspond to an unresolved URI. | 781 * Return the [FileState] instance that correspond to an unresolved URI. |
| 770 */ | 782 */ |
| 771 FileState get unresolvedFile { | 783 FileState get unresolvedFile { |
| 772 if (_unresolvedFile == null) { | 784 if (_unresolvedFile == null) { |
| 773 _unresolvedFile = new FileState._(this, null, null, null); | 785 _unresolvedFile = new FileState._(this, null, null, null); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 files = <FileState>[]; | 911 files = <FileState>[]; |
| 900 _pathToFiles[path] = files; | 912 _pathToFiles[path] = files; |
| 901 // Schedule the stream update. | 913 // Schedule the stream update. |
| 902 _addedKnownFiles.add(path); | 914 _addedKnownFiles.add(path); |
| 903 _scheduleKnownFilesSetChange(); | 915 _scheduleKnownFilesSetChange(); |
| 904 } | 916 } |
| 905 files.add(file); | 917 files.add(file); |
| 906 } | 918 } |
| 907 | 919 |
| 908 void _scheduleKnownFilesSetChange() { | 920 void _scheduleKnownFilesSetChange() { |
| 921 // Schedule the timer only if there is a client who listens the stream. |
| 922 if (!_knownFilesSetChangesRequested) { |
| 923 return; |
| 924 } |
| 925 |
| 909 Duration delay = _knownFilesSetChangesDelay ?? new Duration(seconds: 1); | 926 Duration delay = _knownFilesSetChangesDelay ?? new Duration(seconds: 1); |
| 910 _knownFilesSetChangesTimer ??= new Timer(delay, () { | 927 _knownFilesSetChangesTimer ??= new Timer(delay, () { |
| 911 Set<String> addedFiles = _addedKnownFiles.toSet(); | 928 Set<String> addedFiles = _addedKnownFiles.toSet(); |
| 912 Set<String> removedFiles = new Set<String>(); | 929 Set<String> removedFiles = new Set<String>(); |
| 913 _knownFilesSetChangesController | 930 _knownFilesSetChangesController |
| 914 .add(new KnownFilesSetChange(addedFiles, removedFiles)); | 931 .add(new KnownFilesSetChange(addedFiles, removedFiles)); |
| 915 _addedKnownFiles.clear(); | 932 _addedKnownFiles.clear(); |
| 916 _knownFilesSetChangesTimer = null; | 933 _knownFilesSetChangesTimer = null; |
| 917 }); | 934 }); |
| 918 } | 935 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 943 | 960 |
| 944 /** | 961 /** |
| 945 * Information about changes to the known file set. | 962 * Information about changes to the known file set. |
| 946 */ | 963 */ |
| 947 class KnownFilesSetChange { | 964 class KnownFilesSetChange { |
| 948 final Set<String> added; | 965 final Set<String> added; |
| 949 final Set<String> removed; | 966 final Set<String> removed; |
| 950 | 967 |
| 951 KnownFilesSetChange(this.added, this.removed); | 968 KnownFilesSetChange(this.added, this.removed); |
| 952 } | 969 } |
| OLD | NEW |