From 86e263f3d2393d946e464fb7d1e7551396141d6b Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Mon, 15 Jul 2024 16:57:45 +0000 Subject: [PATCH] API. Add AnalysisContextCollection.dispose() to API. Bug: https://github.com/dart-lang/sdk/issues/56102 Change-Id: I06a53805514655fa01e962bbc98255b5e70f3ed8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375720 Reviewed-by: Brian Wilkerson Commit-Queue: Konstantin Shcheglov --- pkg/analyzer/CHANGELOG.md | 3 +++ .../lib/dart/analysis/analysis_context_collection.dart | 5 +++++ .../lib/src/dart/analysis/analysis_context_collection.dart | 1 + pkg/analyzer/pubspec.yaml | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md index 33ac801b8f4f..fab54ab4c99d 100644 --- a/pkg/analyzer/CHANGELOG.md +++ b/pkg/analyzer/CHANGELOG.md @@ -1,3 +1,6 @@ +## 6.8.0-dev +* Add `AnalysisContextCollection.dispose()`. It must be invoked at the end. + ## 6.7.0 * Deprecated `File.createSource()`, it violates levels of abstraction. You can get `Source` instances from `AnalysisResult`s. diff --git a/pkg/analyzer/lib/dart/analysis/analysis_context_collection.dart b/pkg/analyzer/lib/dart/analysis/analysis_context_collection.dart index fa03a7c64cf8..60b232db5778 100644 --- a/pkg/analyzer/lib/dart/analysis/analysis_context_collection.dart +++ b/pkg/analyzer/lib/dart/analysis/analysis_context_collection.dart @@ -20,6 +20,8 @@ abstract class AnalysisContextCollection { /// /// If [sdkPath] is given, then Dart SDK at this path will be used, otherwise /// the default Dart SDK will be used. + /// + /// [dispose] must be invoked after collection is finished being used. factory AnalysisContextCollection({ required List includedPaths, List? excludedPaths, @@ -34,4 +36,7 @@ abstract class AnalysisContextCollection { /// given [path], or throw [StateError] if the [path] is not analyzed in any /// of the created analysis contexts. AnalysisContext contextFor(String path); + + /// Stops associated processes, and free resources. + Future dispose(); } 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 e8e2bee0755f..fe2e4610e4df 100644 --- a/pkg/analyzer/lib/src/dart/analysis/analysis_context_collection.dart +++ b/pkg/analyzer/lib/src/dart/analysis/analysis_context_collection.dart @@ -156,6 +156,7 @@ class AnalysisContextCollectionImpl implements AnalysisContextCollection { throw StateError('Unable to find the context to $path'); } + @override Future dispose({ bool forTesting = false, }) async { diff --git a/pkg/analyzer/pubspec.yaml b/pkg/analyzer/pubspec.yaml index b76bdfd06f15..4d2e251f9243 100644 --- a/pkg/analyzer/pubspec.yaml +++ b/pkg/analyzer/pubspec.yaml @@ -1,5 +1,5 @@ name: analyzer -version: 6.7.0 +version: 6.8.0-dev description: >- This package provides a library that performs static analysis of Dart code. repository: https://github.com/dart-lang/sdk/tree/main/pkg/analyzer