Skip to content

Commit 2e05e6c

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Fix for LintDriver and package.
Change-Id: I36347fcac02d214743d2946683036921d17ca10f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154566 Reviewed-by: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 556f0fb commit 2e05e6c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

pkg/analyzer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Removed `defaultSdkDirectory()` and `getSdkProperty()` from internal
33
`FolderBasedDartSdk`. It is up to the clients to decide how to
44
find SDK, for example using `package:cli_util`.
5+
* Fixed `LintDriver` for the new way to access `WorkspacePackage`.
56

67
## 0.39.13
78
* Added 'dart/sdk/build_sdk_summary.dart' with `buildSdkSummary`.

pkg/analyzer/lib/src/lint/analysis.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:async';
66
import 'dart:collection';
77
import 'dart:io' as io;
88

9+
import 'package:analyzer/dart/analysis/context_locator.dart' as api;
910
import 'package:analyzer/dart/analysis/results.dart';
1011
import 'package:analyzer/file_system/file_system.dart'
1112
show File, Folder, ResourceProvider, ResourceUriResolver;
@@ -15,6 +16,8 @@ import 'package:analyzer/src/analysis_options/analysis_options_provider.dart';
1516
import 'package:analyzer/src/context/packages.dart';
1617
import 'package:analyzer/src/dart/analysis/byte_store.dart';
1718
import 'package:analyzer/src/dart/analysis/driver.dart';
19+
import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart'
20+
as api;
1821
import 'package:analyzer/src/dart/analysis/file_state.dart';
1922
import 'package:analyzer/src/dart/analysis/performance_logger.dart';
2023
import 'package:analyzer/src/dart/sdk/sdk.dart';
@@ -169,6 +172,9 @@ class LintDriver {
169172
_buildAnalyzerOptions(options),
170173
packages: Packages.empty,
171174
);
175+
176+
_setAnalysisDriverAnalysisContext(analysisDriver, files);
177+
172178
analysisDriver.results.listen((_) {});
173179
analysisDriver.exceptions.listen((_) {});
174180
scheduler.start();
@@ -242,6 +248,39 @@ class LintDriver {
242248
}
243249
return null;
244250
}
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+
}
245284
}
246285

247286
/// Prints logging information comments to the [outSink] and error messages to

0 commit comments

Comments
 (0)