@@ -6,6 +6,7 @@ import 'dart:async';
6
6
import 'dart:collection' ;
7
7
import 'dart:io' as io;
8
8
9
+ import 'package:analyzer/dart/analysis/context_locator.dart' as api;
9
10
import 'package:analyzer/dart/analysis/results.dart' ;
10
11
import 'package:analyzer/file_system/file_system.dart'
11
12
show File, Folder, ResourceProvider, ResourceUriResolver;
@@ -15,6 +16,8 @@ import 'package:analyzer/src/analysis_options/analysis_options_provider.dart';
15
16
import 'package:analyzer/src/context/packages.dart' ;
16
17
import 'package:analyzer/src/dart/analysis/byte_store.dart' ;
17
18
import 'package:analyzer/src/dart/analysis/driver.dart' ;
19
+ import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart'
20
+ as api;
18
21
import 'package:analyzer/src/dart/analysis/file_state.dart' ;
19
22
import 'package:analyzer/src/dart/analysis/performance_logger.dart' ;
20
23
import 'package:analyzer/src/dart/sdk/sdk.dart' ;
@@ -169,6 +172,9 @@ class LintDriver {
169
172
_buildAnalyzerOptions (options),
170
173
packages: Packages .empty,
171
174
);
175
+
176
+ _setAnalysisDriverAnalysisContext (analysisDriver, files);
177
+
172
178
analysisDriver.results.listen ((_) {});
173
179
analysisDriver.exceptions.listen ((_) {});
174
180
scheduler.start ();
@@ -242,6 +248,39 @@ class LintDriver {
242
248
}
243
249
return null ;
244
250
}
251
+
252
+ void _setAnalysisDriverAnalysisContext (
253
+ AnalysisDriver analysisDriver,
254
+ Iterable <io.File > files,
255
+ ) {
256
+ if (files.isEmpty) {
257
+ return ;
258
+ }
259
+
260
+ var rootPath = p.normalize (files.first.absolute.path);
261
+ if (rootPath == null ) {
262
+ return ;
263
+ }
264
+
265
+ var apiContextRoots = api.ContextLocator (
266
+ resourceProvider: resourceProvider,
267
+ ).locateRoots (
268
+ includedPaths: [rootPath],
269
+ excludedPaths: [],
270
+ );
271
+
272
+ if (apiContextRoots.isEmpty) {
273
+ return ;
274
+ }
275
+
276
+ analysisDriver.configure (
277
+ analysisContext: api.DriverBasedAnalysisContext (
278
+ resourceProvider,
279
+ apiContextRoots.first,
280
+ analysisDriver,
281
+ ),
282
+ );
283
+ }
245
284
}
246
285
247
286
/// Prints logging information comments to the [outSink] and error messages to
0 commit comments