From 502418d96faec27cadbe8c561e7d556968cad74e Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 16 Jul 2024 13:53:13 -0700 Subject: [PATCH 1/3] Stop using deprecated ContextLocator and ContextBuilder. --- pkgs/graphs/example/crawl_async_example.dart | 28 +++++++++----------- pkgs/graphs/pubspec.yaml | 2 +- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/pkgs/graphs/example/crawl_async_example.dart b/pkgs/graphs/example/crawl_async_example.dart index c74eae901..bd35c75ef 100644 --- a/pkgs/graphs/example/crawl_async_example.dart +++ b/pkgs/graphs/example/crawl_async_example.dart @@ -5,9 +5,7 @@ import 'dart:async'; import 'dart:isolate'; -import 'package:analyzer/dart/analysis/analysis_context.dart'; -import 'package:analyzer/dart/analysis/context_builder.dart'; -import 'package:analyzer/dart/analysis/context_locator.dart'; +import 'package:analyzer/dart/analysis/analysis_context_collection.dart'; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/ast/ast.dart'; import 'package:graphs/graphs.dart'; @@ -24,28 +22,25 @@ Future main() async { read, (from, source) => pool.withResource(() => findImports(from, source)), ).toList(); + await _analysisContextCollection?.dispose(); print(allImports.map((s) => s.uri).toList()); } -AnalysisContext? _analysisContext; +AnalysisContextCollection? _analysisContextCollection; -Future get analysisContext async { - var context = _analysisContext; - if (context == null) { +Future get analysisContextCollection async { + var collection = _analysisContextCollection; + if (collection == null) { final libUri = Uri.parse('package:graphs/'); final libPath = await pathForUri(libUri); final packagePath = p.dirname(libPath); - final roots = ContextLocator().locateRoots(includedPaths: [packagePath]); - if (roots.length != 1) { - throw StateError('Expected to find exactly one context root, got $roots'); - } - - context = _analysisContext = - ContextBuilder().createContext(contextRoot: roots[0]); + collection = _analysisContextCollection = AnalysisContextCollection( + includedPaths: [packagePath], + ); } - return context; + return collection; } Future> findImports(Uri from, Source source) async => @@ -57,7 +52,8 @@ Future> findImports(Uri from, Source source) async => Future parseUri(Uri uri) async { final path = await pathForUri(uri); - final analysisSession = (await analysisContext).currentSession; + final analysisContext = (await analysisContextCollection).contexts.single; + final analysisSession = analysisContext.currentSession; final parseResult = analysisSession.getParsedUnit(path); return (parseResult as ParsedUnitResult).unit; } diff --git a/pkgs/graphs/pubspec.yaml b/pkgs/graphs/pubspec.yaml index bd4dd09fa..1ee925158 100644 --- a/pkgs/graphs/pubspec.yaml +++ b/pkgs/graphs/pubspec.yaml @@ -14,6 +14,6 @@ dev_dependencies: test: ^1.21.6 # For examples - analyzer: '>=5.2.0 <7.0.0' + analyzer: '>=6.8.0 <7.0.0' path: ^1.8.0 pool: ^1.5.0 From 4c80a9b6137d20990012c77da0ed902c70fe4cba Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 16 Jul 2024 14:00:11 -0700 Subject: [PATCH 2/3] Try using Dart SDK 3.5 instead of 3.4 --- .github/workflows/graphs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/graphs.yml b/.github/workflows/graphs.yml index d04d65c1c..bc28e5e3c 100644 --- a/.github/workflows/graphs.yml +++ b/.github/workflows/graphs.yml @@ -53,7 +53,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - sdk: [3.4, dev] + sdk: [3.5, dev] steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 From e391f9320214cae9584b7504b6b64ec9e16727e6 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 16 Jul 2024 14:08:35 -0700 Subject: [PATCH 3/3] Revert to analyzer >= 5.2.0, but no dispose(). --- .github/workflows/graphs.yml | 2 +- pkgs/graphs/example/crawl_async_example.dart | 1 - pkgs/graphs/pubspec.yaml | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/graphs.yml b/.github/workflows/graphs.yml index bc28e5e3c..d04d65c1c 100644 --- a/.github/workflows/graphs.yml +++ b/.github/workflows/graphs.yml @@ -53,7 +53,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - sdk: [3.5, dev] + sdk: [3.4, dev] steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 diff --git a/pkgs/graphs/example/crawl_async_example.dart b/pkgs/graphs/example/crawl_async_example.dart index bd35c75ef..bd305c975 100644 --- a/pkgs/graphs/example/crawl_async_example.dart +++ b/pkgs/graphs/example/crawl_async_example.dart @@ -22,7 +22,6 @@ Future main() async { read, (from, source) => pool.withResource(() => findImports(from, source)), ).toList(); - await _analysisContextCollection?.dispose(); print(allImports.map((s) => s.uri).toList()); } diff --git a/pkgs/graphs/pubspec.yaml b/pkgs/graphs/pubspec.yaml index 1ee925158..bd4dd09fa 100644 --- a/pkgs/graphs/pubspec.yaml +++ b/pkgs/graphs/pubspec.yaml @@ -14,6 +14,6 @@ dev_dependencies: test: ^1.21.6 # For examples - analyzer: '>=6.8.0 <7.0.0' + analyzer: '>=5.2.0 <7.0.0' path: ^1.8.0 pool: ^1.5.0