From 0f9e6da04454017f61e96532772ecee4df4238f7 Mon Sep 17 00:00:00 2001 From: Kallen Tu Date: Thu, 11 Jun 2026 11:15:16 -0700 Subject: [PATCH] API - Deprecate the `excludedPaths` parameter in `AnalysisContextCollection`. Path exclusions should ideally be defined inside a project's `analysis_options.yaml` file, rather than being added programatically. Plus, there's a bug with the constructor that causes this parameter to be completely ignored anyways, so it's been obsolete and non-functional for a while now. `getExcludedGlobs` in the `_ContextLocator` handles parsing and adding excluded paths from the analysis server already, so we should look into deprecating and removing this parameter. Change-Id: I6c023041c7bb5fa4cb9dedc629afa4ea6ecb63d7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/511160 Commit-Queue: Kallen Tu Reviewed-by: Brian Wilkerson Reviewed-by: Konstantin Shcheglov --- pkg/analysis_server/lib/src/context_manager.dart | 1 - pkg/analysis_server/test/verify_sorted_test.dart | 1 - pkg/analysis_server/tool/code_completion/code_metrics.dart | 1 - .../tool/code_completion/completion_metrics_base.dart | 7 +++---- .../tool/code_completion/flutter_metrics.dart | 1 - .../tool/code_completion/implicit_type_declarations.dart | 1 - .../tool/code_completion/relevance_metrics.dart | 1 - .../tool/code_completion/relevance_table_generator.dart | 1 - pkg/analysis_server_plugin/lib/src/plugin_server.dart | 1 - pkg/analyzer/CHANGELOG.md | 1 + pkg/analyzer/api.txt | 2 +- .../lib/dart/analysis/analysis_context_collection.dart | 2 +- .../lib/src/dart/analysis/analysis_context_collection.dart | 1 + pkg/analyzer_utilities/lib/verify_tests.dart | 1 - 14 files changed, 7 insertions(+), 15 deletions(-) diff --git a/pkg/analysis_server/lib/src/context_manager.dart b/pkg/analysis_server/lib/src/context_manager.dart index 4661892d217..b3cb08e3ab5 100644 --- a/pkg/analysis_server/lib/src/context_manager.dart +++ b/pkg/analysis_server/lib/src/context_manager.dart @@ -598,7 +598,6 @@ class ContextManagerImpl implements ContextManager { var watchers = []; var collection = _collection = AnalysisContextCollectionImpl( includedPaths: includedPaths, - excludedPaths: excludedPaths, byteStore: _byteStore, drainStreams: false, enableIndex: true, diff --git a/pkg/analysis_server/test/verify_sorted_test.dart b/pkg/analysis_server/test/verify_sorted_test.dart index ff34d65e203..fdb52f5cf36 100644 --- a/pkg/analysis_server/test/verify_sorted_test.dart +++ b/pkg/analysis_server/test/verify_sorted_test.dart @@ -62,7 +62,6 @@ void buildTests({ var collection = AnalysisContextCollection( includedPaths: [packagePath], - excludedPaths: excludedPaths, resourceProvider: provider, ); for (var context in collection.contexts) { diff --git a/pkg/analysis_server/tool/code_completion/code_metrics.dart b/pkg/analysis_server/tool/code_completion/code_metrics.dart index 1e1a161bcb9..a9c81231b8c 100644 --- a/pkg/analysis_server/tool/code_completion/code_metrics.dart +++ b/pkg/analysis_server/tool/code_completion/code_metrics.dart @@ -1304,7 +1304,6 @@ class CodeShapeMetricsComputer { // Create a new collection to avoid consuming large quantities of memory. var collection = AnalysisContextCollection( includedPaths: root.includedPaths.toList(), - excludedPaths: root.excludedPaths.toList(), resourceProvider: PhysicalResourceProvider.INSTANCE, ); var context = collection.contexts[0]; diff --git a/pkg/analysis_server/tool/code_completion/completion_metrics_base.dart b/pkg/analysis_server/tool/code_completion/completion_metrics_base.dart index 2b7c2530ec6..78c77127a01 100644 --- a/pkg/analysis_server/tool/code_completion/completion_metrics_base.dart +++ b/pkg/analysis_server/tool/code_completion/completion_metrics_base.dart @@ -52,7 +52,6 @@ abstract class CompletionMetricsComputer { // Create a new collection to avoid consuming large quantities of memory. var collection = AnalysisContextCollectionImpl( includedPaths: root.includedPaths.toList(), - excludedPaths: root.excludedPaths.toList(), resourceProvider: provider, withFineDependencies: true, ); @@ -129,9 +128,9 @@ abstract class CompletionMetricsComputer { } if (file_paths.isDart(pathContext, filePath)) { try { - var result = - await context.currentSession.getResolvedUnit(filePath) - as ResolvedUnitResult; + var result = await context.currentSession.getResolvedUnit( + filePath, + ) as ResolvedUnitResult; var analysisError = result.diagnostics.errors.firstOrNull; if (analysisError != null) { diff --git a/pkg/analysis_server/tool/code_completion/flutter_metrics.dart b/pkg/analysis_server/tool/code_completion/flutter_metrics.dart index e46d3512fef..cff2f87c189 100644 --- a/pkg/analysis_server/tool/code_completion/flutter_metrics.dart +++ b/pkg/analysis_server/tool/code_completion/flutter_metrics.dart @@ -189,7 +189,6 @@ class FlutterMetricsComputer { // Create a new collection to avoid consuming large quantities of memory. var collection = AnalysisContextCollection( includedPaths: root.includedPaths.toList(), - excludedPaths: root.excludedPaths.toList(), resourceProvider: PhysicalResourceProvider.INSTANCE, ); var context = collection.contexts[0]; diff --git a/pkg/analysis_server/tool/code_completion/implicit_type_declarations.dart b/pkg/analysis_server/tool/code_completion/implicit_type_declarations.dart index 73a32ca7fc2..37fa23f5f53 100644 --- a/pkg/analysis_server/tool/code_completion/implicit_type_declarations.dart +++ b/pkg/analysis_server/tool/code_completion/implicit_type_declarations.dart @@ -173,7 +173,6 @@ class ImpliedTypeComputer { // Create a new collection to avoid consuming large quantities of memory. var collection = AnalysisContextCollection( includedPaths: root.includedPaths.toList(), - excludedPaths: root.excludedPaths.toList(), resourceProvider: PhysicalResourceProvider.INSTANCE, ); var context = collection.contexts[0]; diff --git a/pkg/analysis_server/tool/code_completion/relevance_metrics.dart b/pkg/analysis_server/tool/code_completion/relevance_metrics.dart index acd2d0009a0..1077a7b7108 100644 --- a/pkg/analysis_server/tool/code_completion/relevance_metrics.dart +++ b/pkg/analysis_server/tool/code_completion/relevance_metrics.dart @@ -2196,7 +2196,6 @@ class RelevanceMetricsComputer { // Create a new collection to avoid consuming large quantities of memory. var collection = AnalysisContextCollection( includedPaths: root.includedPaths.toList(), - excludedPaths: root.excludedPaths.toList(), resourceProvider: PhysicalResourceProvider.INSTANCE, ); var context = collection.contexts[0]; diff --git a/pkg/analysis_server/tool/code_completion/relevance_table_generator.dart b/pkg/analysis_server/tool/code_completion/relevance_table_generator.dart index ede85185cb8..55718359cfa 100644 --- a/pkg/analysis_server/tool/code_completion/relevance_table_generator.dart +++ b/pkg/analysis_server/tool/code_completion/relevance_table_generator.dart @@ -2429,7 +2429,6 @@ class RelevanceMetricsComputer { // Create a new collection to avoid consuming large quantities of memory. var collection = AnalysisContextCollection( includedPaths: root.includedPaths.toList(), - excludedPaths: root.excludedPaths.toList(), resourceProvider: PhysicalResourceProvider.INSTANCE, ); var context = collection.contexts[0]; diff --git a/pkg/analysis_server_plugin/lib/src/plugin_server.dart b/pkg/analysis_server_plugin/lib/src/plugin_server.dart index cf9daeaee42..0372fc9c995 100644 --- a/pkg/analysis_server_plugin/lib/src/plugin_server.dart +++ b/pkg/analysis_server_plugin/lib/src/plugin_server.dart @@ -723,7 +723,6 @@ class PluginServer { var contextCollection = AnalysisContextCollectionImpl( resourceProvider: _resourceProvider, includedPaths: parameters.included, - excludedPaths: parameters.excluded, byteStore: _byteStore, sdkPath: _sdkPath, fileContentCache: FileContentCache(_resourceProvider), diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md index ca4fd6acad3..68ee247d9ec 100644 --- a/pkg/analyzer/CHANGELOG.md +++ b/pkg/analyzer/CHANGELOG.md @@ -9,6 +9,7 @@ * Deprecate `FormalParameterElement.formalParameters` and `typeParameters`. Use `FormalParameterElement.type` instead. * Added `isComplete` to `ConstructorDeclaration`, `FunctionDeclaration`, and `MethodDeclaration`. * Deprecated `MethodDeclaration.isAbstract`. Use `!isComplete` instead. +* Deprecate the `excludedPaths` parameter in `AnalysisContextCollection`. Use `analysis_options.yaml` to configure excluded paths instead. ## 13.1.0 diff --git a/pkg/analyzer/api.txt b/pkg/analyzer/api.txt index 2966ff80fd2..22ff50b6cf3 100644 --- a/pkg/analyzer/api.txt +++ b/pkg/analyzer/api.txt @@ -318,7 +318,7 @@ package:analyzer/dart/analysis/analysis_context.dart: getAnalysisOptionsForFile (method: AnalysisOptions Function(File)) package:analyzer/dart/analysis/analysis_context_collection.dart: AnalysisContextCollection (class extends Object, abstract): - new (constructor: AnalysisContextCollection Function({List? excludedPaths, required List includedPaths, ResourceProvider? resourceProvider, String? sdkPath})) + new (constructor: AnalysisContextCollection Function({deprecated List? excludedPaths, required List includedPaths, ResourceProvider? resourceProvider, String? sdkPath})) contexts (getter: List) contextFor (method: AnalysisContext Function(String)) dispose (method: Future Function()) diff --git a/pkg/analyzer/lib/dart/analysis/analysis_context_collection.dart b/pkg/analyzer/lib/dart/analysis/analysis_context_collection.dart index 0bd19f8fdbe..6104a4b35c9 100644 --- a/pkg/analyzer/lib/dart/analysis/analysis_context_collection.dart +++ b/pkg/analyzer/lib/dart/analysis/analysis_context_collection.dart @@ -24,13 +24,13 @@ abstract class AnalysisContextCollection { /// [dispose] must be invoked after collection is finished being used. factory AnalysisContextCollection({ required List includedPaths, + @Deprecated('Use analysis_options.yaml to exclude paths.') List? excludedPaths, ResourceProvider? resourceProvider, String? sdkPath, }) { return AnalysisContextCollectionImpl( includedPaths: includedPaths, - excludedPaths: excludedPaths, resourceProvider: resourceProvider, sdkPath: sdkPath, ); diff --git a/pkg/analyzer/lib/src/dart/analysis/analysis_context_collection.dart b/pkg/analyzer/lib/src/dart/analysis/analysis_context_collection.dart index 57b58632628..12e758473df 100644 --- a/pkg/analyzer/lib/src/dart/analysis/analysis_context_collection.dart +++ b/pkg/analyzer/lib/src/dart/analysis/analysis_context_collection.dart @@ -42,6 +42,7 @@ class AnalysisContextCollectionImpl implements AnalysisContextCollection { bool drainStreams = true, bool enableIndex = false, required List includedPaths, + @Deprecated('Use analysis_options.yaml to exclude paths.') List? excludedPaths, List? librarySummaryPaths, String? optionsFile, diff --git a/pkg/analyzer_utilities/lib/verify_tests.dart b/pkg/analyzer_utilities/lib/verify_tests.dart index f77bf4fc2b2..7f2b4449c38 100644 --- a/pkg/analyzer_utilities/lib/verify_tests.dart +++ b/pkg/analyzer_utilities/lib/verify_tests.dart @@ -30,7 +30,6 @@ class VerifyTests { var collection = AnalysisContextCollection( resourceProvider: provider, includedPaths: [testDirPath], - excludedPaths: excludedPaths, ); var singleAnalysisContext = collection.contexts .where(analysisContextPredicate ?? (_) => true)