Use AnalysisDriver.addedFiles for search, remove DriverAnalyzedFiles.

The client that uses Search - DAS, adds analyzed files.
Visiting the file system again to gather analyzed files is wasteful.
DAS now uses AnalysisContextCollection, so the same set of files.

Change-Id: I2b6ba4181e7ed8cda02db152086d13758ea6f4dd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/189381
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov
2021-03-06 05:15:24 +00:00
committed by commit-bot@chromium.org
parent b683098fde
commit f81be2cd8b
4 changed files with 26 additions and 29 deletions
@@ -18,6 +18,7 @@ import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine;
import 'package:analyzer/src/test_utilities/mock_sdk.dart';
import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
import 'package:linter/src/rules.dart';
import 'package:meta/meta.dart';
@@ -174,6 +175,7 @@ class AbstractContextTest with ResourceProviderMixin {
throw StateError('Only dart files can be changed after analysis.');
}
_addAnalyzedFileToDrivers(path);
return super.newFile(path, content: content);
}
@@ -259,6 +261,28 @@ class AbstractContextTest with ResourceProviderMixin {
writePackageConfig(path, config);
}
void _addAnalyzedFilesToDrivers() {
for (var analysisContext in _analysisContextCollection.contexts) {
var driver = (analysisContext as DriverBasedAnalysisContext).driver;
for (var path in analysisContext.contextRoot.analyzedFiles()) {
if (file_paths.isDart(resourceProvider.pathContext, path)) {
driver.addFile(path);
}
}
}
}
void _addAnalyzedFileToDrivers(String path) {
if (_analysisContextCollection != null) {
for (var analysisContext in _analysisContextCollection.contexts) {
if (analysisContext.contextRoot.isAnalyzed(path)) {
var driver = (analysisContext as DriverBasedAnalysisContext).driver;
driver.addFile(path);
}
}
}
}
/// Create all analysis contexts in [collectionIncludedPaths].
void _createAnalysisContexts() {
if (_analysisContextCollection != null) {
@@ -274,6 +298,7 @@ class AbstractContextTest with ResourceProviderMixin {
sdkPath: convertPath(sdkRoot),
);
_addAnalyzedFilesToDrivers();
verifyCreatedCollection();
}
}
@@ -57,7 +57,6 @@ class C {
''', target: '/home/test/lib/a.dart');
}
@FailingTest(reason: 'The lint does not fire for parts.')
Future<void> test_changeInPart() async {
addSource('/home/test/lib/a.dart', '''
part 'test.dart';
@@ -248,8 +248,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
/// Whether resolved units should be indexed.
final bool enableIndex;
late final DriverAnalyzedFiles analyzedFiles = DriverAnalyzedFiles(this);
/// The current analysis session.
late AnalysisSessionImpl _currentSession;
@@ -448,7 +446,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
if (!_fsState.hasUri(path)) {
return;
}
analyzedFiles.reset();
if (file_paths.isDart(resourceProvider.pathContext, path)) {
_fileTracker.addFile(path);
// If the file is known, it has already been read, even if it did not
@@ -1203,7 +1200,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
/// but does not guarantee this.
void removeFile(String path) {
_throwIfNotAbsolutePath(path);
analyzedFiles.reset();
_fileTracker.removeFile(path);
clearLibraryContext();
_priorityResults.clear();
@@ -2086,29 +2082,6 @@ class AnalysisResult extends ResolvedUnitResultImpl {
errors);
}
/// The cache of files analyzed in the driver.
class DriverAnalyzedFiles {
final AnalysisDriver _driver;
List<String>? _files;
DriverAnalyzedFiles(this._driver);
List<String> get files {
var files = _files;
if (files == null) {
var contextRoot = _driver.analysisContext!.contextRoot;
_files = files = contextRoot.analyzedFiles().toList();
}
return files;
}
void reset() {
_files = null;
}
}
/// An object that watches for the creation and removal of analysis drivers.
///
/// Clients may not extend, implement or mix-in this class.
@@ -503,7 +503,7 @@ class SearchedFiles {
}
void ownAnalyzed(Search search) {
for (var path in search._driver.analyzedFiles.files) {
for (var path in search._driver.addedFiles) {
if (path.endsWith('.dart')) {
add(path, search);
}