mirror of
https://github.com/dart-lang/sdk
synced 2024-07-25 04:15:45 +00:00
update ContextManager to support analysis option include directive
R=brianwilkerson@google.com Review URL: https://codereview.chromium.org/2514533002 .
This commit is contained in:
parent
138cebfa2d
commit
9ec7547323
|
@ -477,10 +477,6 @@ class ContextManagerImpl implements ContextManager {
|
|||
*/
|
||||
final PubPackageMapProvider _packageMapProvider;
|
||||
|
||||
/// Provider of analysis options.
|
||||
AnalysisOptionsProvider analysisOptionsProvider =
|
||||
new AnalysisOptionsProvider();
|
||||
|
||||
/**
|
||||
* A list of the globs used to determine which files should be analyzed.
|
||||
*/
|
||||
|
@ -685,9 +681,19 @@ class ContextManagerImpl implements ContextManager {
|
|||
* if exists, or in one of the parent folders, or `null` if no analysis
|
||||
* options file is found or if the contents of the file are not valid YAML.
|
||||
*/
|
||||
Map<String, Object> readOptions(Folder folder) {
|
||||
Map<String, Object> readOptions(Folder folder, Packages packages) {
|
||||
try {
|
||||
return analysisOptionsProvider.getOptions(folder, crawlUp: true);
|
||||
Map<String, List<Folder>> packageMap =
|
||||
new ContextBuilder(resourceProvider, null, null)
|
||||
.convertPackagesToMap(packages);
|
||||
List<UriResolver> resolvers = <UriResolver>[
|
||||
new ResourceUriResolver(resourceProvider),
|
||||
new PackageMapUriResolver(resourceProvider, packageMap),
|
||||
];
|
||||
SourceFactory sourceFactory =
|
||||
new SourceFactory(resolvers, packages, resourceProvider);
|
||||
return new AnalysisOptionsProvider(sourceFactory)
|
||||
.getOptions(folder, crawlUp: true);
|
||||
} catch (_) {
|
||||
// Parse errors are reported by GenerateOptionsErrorsTask.
|
||||
}
|
||||
|
@ -916,7 +922,8 @@ class ContextManagerImpl implements ContextManager {
|
|||
if (AnalysisEngine.isAnalysisOptionsFileName(path, pathContext)) {
|
||||
var analysisContext = info.context;
|
||||
if (analysisContext is context.AnalysisContextImpl) {
|
||||
Map<String, Object> options = readOptions(info.folder);
|
||||
Map<String, Object> options =
|
||||
readOptions(info.folder, info.disposition.packages);
|
||||
processOptionsForContext(info, options,
|
||||
optionsRemoved: changeType == ChangeType.REMOVE);
|
||||
analysisContext.sourceFactory = _createSourceFactory(
|
||||
|
@ -1069,7 +1076,8 @@ class ContextManagerImpl implements ContextManager {
|
|||
ContextInfo info = new ContextInfo(this, parent, folder, packagespecFile,
|
||||
normalizedPackageRoots[folder.path], disposition);
|
||||
|
||||
Map<String, Object> optionMap = readOptions(info.folder);
|
||||
Map<String, Object> optionMap =
|
||||
readOptions(info.folder, disposition.packages);
|
||||
AnalysisOptions options =
|
||||
new AnalysisOptionsImpl.from(defaultContextOptions);
|
||||
applyToAnalysisOptions(options, optionMap);
|
||||
|
|
|
@ -11,6 +11,7 @@ import 'package:analyzer/error/error.dart';
|
|||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/file_system/memory_file_system.dart';
|
||||
import 'package:analyzer/instrumentation/instrumentation.dart';
|
||||
import 'package:analyzer/source/analysis_options_provider.dart';
|
||||
import 'package:analyzer/source/error_processor.dart';
|
||||
import 'package:analyzer/src/context/builder.dart';
|
||||
import 'package:analyzer/src/dart/analysis/driver.dart';
|
||||
|
@ -1935,6 +1936,43 @@ linter:
|
|||
expect(getProcessor(missing_return).severity, isNull);
|
||||
}
|
||||
|
||||
test_analysis_options_include() async {
|
||||
// Create files.
|
||||
String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
|
||||
newFile([libPath, 'main.dart']);
|
||||
String sdkExtPath = newFolder([projPath, 'sdk_ext']);
|
||||
newFile([sdkExtPath, 'entry.dart']);
|
||||
String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']);
|
||||
newFile([sdkExtSrcPath, 'part.dart']);
|
||||
// Setup analysis options file which includes another options file.
|
||||
newFile(
|
||||
[projPath, optionsFileName],
|
||||
r'''
|
||||
include: other_options.yaml
|
||||
''');
|
||||
newFile(
|
||||
[projPath, 'other_options.yaml'],
|
||||
r'''
|
||||
analyzer:
|
||||
language:
|
||||
enableGenericMethods: true
|
||||
errors:
|
||||
unused_local_variable: false
|
||||
linter:
|
||||
rules:
|
||||
- camel_case_types
|
||||
''');
|
||||
// Setup context.
|
||||
manager.setRoots(<String>[projPath], <String>[], <String, String>{});
|
||||
await pumpEventQueue();
|
||||
|
||||
// Verify options were set.
|
||||
expect(options.enableGenericMethods, isTrue);
|
||||
expect(errorProcessors, hasLength(1));
|
||||
expect(lints, hasLength(1));
|
||||
expect(lints[0].name, 'camel_case_types');
|
||||
}
|
||||
|
||||
test_analysis_options_parse_failure() async {
|
||||
// Create files.
|
||||
String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
|
||||
|
|
Loading…
Reference in a new issue