| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library context.directory.manager; | 5 library context.directory.manager; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:core' hide Resource; | 10 import 'dart:core' hide Resource; |
| 11 | 11 |
| 12 import 'package:analysis_server/plugin/analysis/resolver_provider.dart'; | 12 import 'package:analysis_server/plugin/analysis/resolver_provider.dart'; |
| 13 import 'package:analysis_server/src/analysis_server.dart'; | 13 import 'package:analysis_server/src/analysis_server.dart'; |
| 14 import 'package:analyzer/file_system/file_system.dart'; | 14 import 'package:analyzer/file_system/file_system.dart'; |
| 15 import 'package:analyzer/instrumentation/instrumentation.dart'; | 15 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 16 import 'package:analyzer/plugin/options.dart'; | 16 import 'package:analyzer/plugin/options.dart'; |
| 17 import 'package:analyzer/source/analysis_options_provider.dart'; | 17 import 'package:analyzer/source/analysis_options_provider.dart'; |
| 18 import 'package:analyzer/source/package_map_provider.dart'; | 18 import 'package:analyzer/source/package_map_provider.dart'; |
| 19 import 'package:analyzer/source/package_map_resolver.dart'; | 19 import 'package:analyzer/source/package_map_resolver.dart'; |
| 20 import 'package:analyzer/source/path_filter.dart'; | 20 import 'package:analyzer/source/path_filter.dart'; |
| 21 import 'package:analyzer/source/pub_package_map_provider.dart'; | 21 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 22 import 'package:analyzer/source/sdk_ext.dart'; | 22 import 'package:analyzer/source/sdk_ext.dart'; |
| 23 import 'package:analyzer/src/context/context.dart' as context; | 23 import 'package:analyzer/src/context/context.dart' as context; |
| 24 import 'package:analyzer/src/generated/engine.dart'; | 24 import 'package:analyzer/src/generated/engine.dart'; |
| 25 import 'package:analyzer/src/generated/error.dart'; |
| 25 import 'package:analyzer/src/generated/java_engine.dart'; | 26 import 'package:analyzer/src/generated/java_engine.dart'; |
| 26 import 'package:analyzer/src/generated/java_io.dart'; | 27 import 'package:analyzer/src/generated/java_io.dart'; |
| 27 import 'package:analyzer/src/generated/source.dart'; | 28 import 'package:analyzer/src/generated/source.dart'; |
| 28 import 'package:analyzer/src/generated/source_io.dart'; | 29 import 'package:analyzer/src/generated/source_io.dart'; |
| 29 import 'package:package_config/packages.dart'; | 30 import 'package:package_config/packages.dart'; |
| 30 import 'package:package_config/packages_file.dart' as pkgfile show parse; | 31 import 'package:package_config/packages_file.dart' as pkgfile show parse; |
| 31 import 'package:package_config/src/packages_impl.dart' show MapPackages; | 32 import 'package:package_config/src/packages_impl.dart' show MapPackages; |
| 32 import 'package:path/path.dart' as pathos; | 33 import 'package:path/path.dart' as pathos; |
| 33 import 'package:watcher/watcher.dart'; | 34 import 'package:watcher/watcher.dart'; |
| 34 import 'package:yaml/yaml.dart'; | 35 import 'package:yaml/yaml.dart'; |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 new AnalysisOptionsImpl.from(context.analysisOptions); | 514 new AnalysisOptionsImpl.from(context.analysisOptions); |
| 514 options.strongMode = strongMode; | 515 options.strongMode = strongMode; |
| 515 context.analysisOptions = options; | 516 context.analysisOptions = options; |
| 516 } | 517 } |
| 517 | 518 |
| 518 // Set ignore patterns. | 519 // Set ignore patterns. |
| 519 YamlList exclude = analyzer['exclude']; | 520 YamlList exclude = analyzer['exclude']; |
| 520 if (exclude != null) { | 521 if (exclude != null) { |
| 521 setIgnorePatternsForContext(info, exclude); | 522 setIgnorePatternsForContext(info, exclude); |
| 522 } | 523 } |
| 524 |
| 525 // Set filters. |
| 526 YamlNode filters = analyzer['errors']; |
| 527 setFiltersForContext(info, filters); |
| 523 } | 528 } |
| 524 | 529 |
| 525 @override | 530 @override |
| 526 void refresh(List<Resource> roots) { | 531 void refresh(List<Resource> roots) { |
| 527 // Destroy old contexts | 532 // Destroy old contexts |
| 528 List<ContextInfo> contextInfos = _rootInfo.descendants.toList(); | 533 List<ContextInfo> contextInfos = _rootInfo.descendants.toList(); |
| 529 if (roots == null) { | 534 if (roots == null) { |
| 530 contextInfos.forEach(_destroyContext); | 535 contextInfos.forEach(_destroyContext); |
| 531 } else { | 536 } else { |
| 532 roots.forEach((Resource resource) { | 537 roots.forEach((Resource resource) { |
| 533 contextInfos.forEach((ContextInfo contextInfo) { | 538 contextInfos.forEach((ContextInfo contextInfo) { |
| 534 if (resource is Folder && | 539 if (resource is Folder && |
| 535 resource.isOrContains(contextInfo.folder.path)) { | 540 resource.isOrContains(contextInfo.folder.path)) { |
| 536 _destroyContext(contextInfo); | 541 _destroyContext(contextInfo); |
| 537 } | 542 } |
| 538 }); | 543 }); |
| 539 }); | 544 }); |
| 540 } | 545 } |
| 541 | 546 |
| 542 // Rebuild contexts based on the data last sent to setRoots(). | 547 // Rebuild contexts based on the data last sent to setRoots(). |
| 543 setRoots(includedPaths, excludedPaths, packageRoots); | 548 setRoots(includedPaths, excludedPaths, packageRoots); |
| 544 } | 549 } |
| 545 | 550 |
| 551 void setFiltersForContext(ContextInfo info, YamlNode codes) { |
| 552 List<ErrorFilter> filters = <ErrorFilter>[]; |
| 553 // If codes are enumerated, collect them as filters; else leave filters |
| 554 // empty to overwrite previous value. |
| 555 if (codes is YamlMap) { |
| 556 String code, value; |
| 557 codes.nodes.forEach((k, v) { |
| 558 if (k is YamlScalar && v is YamlScalar) { |
| 559 value = v.value?.toString()?.toLowerCase(); |
| 560 if (value == 'false' || value == 'ignore') { |
| 561 // Case-insensitive. |
| 562 code = k.value?.toString()?.toUpperCase(); |
| 563 filters.add((AnalysisError error) => error.errorCode.name == code); |
| 564 } |
| 565 } |
| 566 }); |
| 567 } |
| 568 info.context.setConfigurationData(CONFIGURED_ERROR_FILTERS, filters); |
| 569 } |
| 570 |
| 546 /** | 571 /** |
| 547 * Sets the [ignorePatterns] for the context having info [info]. | 572 * Sets the [ignorePatterns] for the context having info [info]. |
| 548 */ | 573 */ |
| 549 void setIgnorePatternsForContext( | 574 void setIgnorePatternsForContext( |
| 550 ContextInfo info, List<String> ignorePatterns) { | 575 ContextInfo info, List<String> ignorePatterns) { |
| 551 info.pathFilter.setIgnorePatterns(ignorePatterns); | 576 info.pathFilter.setIgnorePatterns(ignorePatterns); |
| 552 } | 577 } |
| 553 | 578 |
| 554 @override | 579 @override |
| 555 void setRoots(List<String> includedPaths, List<String> excludedPaths, | 580 void setRoots(List<String> includedPaths, List<String> excludedPaths, |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 var path = resourceProvider.pathContext.fromUri(uri); | 1470 var path = resourceProvider.pathContext.fromUri(uri); |
| 1446 packageMap[name] = <Folder>[resourceProvider.getFolder(path)]; | 1471 packageMap[name] = <Folder>[resourceProvider.getFolder(path)]; |
| 1447 } | 1472 } |
| 1448 }); | 1473 }); |
| 1449 return <UriResolver>[new SdkExtUriResolver(packageMap)]; | 1474 return <UriResolver>[new SdkExtUriResolver(packageMap)]; |
| 1450 } else { | 1475 } else { |
| 1451 return const <UriResolver>[]; | 1476 return const <UriResolver>[]; |
| 1452 } | 1477 } |
| 1453 } | 1478 } |
| 1454 } | 1479 } |
| OLD | NEW |