Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: pkg/analysis_server/lib/src/context_manager.dart

Issue 2947743002: Add support to pass the location of the analysis options file to plugins (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/plugin/plugin_manager.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'dart:convert'; 7 import 'dart:convert';
8 import 'dart:core'; 8 import 'dart:core';
9 9
10 import 'package:analyzer/context/context_root.dart'; 10 import 'package:analyzer/context/context_root.dart';
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 if (analyzer is Map) { 743 if (analyzer is Map) {
744 // Set ignore patterns. 744 // Set ignore patterns.
745 YamlList exclude = analyzer[AnalyzerOptions.exclude]; 745 YamlList exclude = analyzer[AnalyzerOptions.exclude];
746 List<String> excludeList = toStringList(exclude); 746 List<String> excludeList = toStringList(exclude);
747 if (excludeList != null) { 747 if (excludeList != null) {
748 setIgnorePatternsForContext(info, excludeList); 748 setIgnorePatternsForContext(info, excludeList);
749 } 749 }
750 } 750 }
751 } 751 }
752 752
753 /**
754 * Return the options from the analysis options file in the given [folder]
755 * if exists, or in one of the parent folders, or `null` if no analysis
756 * options file is found or if the contents of the file are not valid YAML.
757 */
758 Map<String, Object> readOptions(Folder folder, Packages packages) {
759 try {
760 Map<String, List<Folder>> packageMap =
761 new ContextBuilder(resourceProvider, null, null)
762 .convertPackagesToMap(packages);
763 List<UriResolver> resolvers = <UriResolver>[
764 new ResourceUriResolver(resourceProvider),
765 new PackageMapUriResolver(resourceProvider, packageMap),
766 ];
767 SourceFactory sourceFactory =
768 new SourceFactory(resolvers, packages, resourceProvider);
769 return new AnalysisOptionsProvider(sourceFactory)
770 .getOptions(folder, crawlUp: true);
771 } catch (_) {
772 // Parse errors are reported by GenerateOptionsErrorsTask.
773 }
774 return null;
775 }
776
777 @override 753 @override
778 void refresh(List<Resource> roots) { 754 void refresh(List<Resource> roots) {
779 // Destroy old contexts 755 // Destroy old contexts
780 List<ContextInfo> contextInfos = rootInfo.descendants.toList(); 756 List<ContextInfo> contextInfos = rootInfo.descendants.toList();
781 if (roots == null) { 757 if (roots == null) {
782 contextInfos.forEach(_destroyContext); 758 contextInfos.forEach(_destroyContext);
783 } else { 759 } else {
784 roots.forEach((Resource resource) { 760 roots.forEach((Resource resource) {
785 contextInfos.forEach((ContextInfo contextInfo) { 761 contextInfos.forEach((ContextInfo contextInfo) {
786 if (resource is Folder && 762 if (resource is Folder &&
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 addDependency(dependencyPath); 1088 addDependency(dependencyPath);
1113 } 1089 }
1114 if (packageMapInfo.packageMap == null) { 1090 if (packageMapInfo.packageMap == null) {
1115 return new NoPackageFolderDisposition(); 1091 return new NoPackageFolderDisposition();
1116 } 1092 }
1117 return new PackageMapDisposition(packageMapInfo.packageMap); 1093 return new PackageMapDisposition(packageMapInfo.packageMap);
1118 } 1094 }
1119 } 1095 }
1120 1096
1121 /** 1097 /**
1098 * Create an object that can be used to find and read the analysis options
1099 * file for code being analyzed using the given [packages].
1100 */
1101 AnalysisOptionsProvider _createAnalysisOptionsProvider(Packages packages) {
1102 Map<String, List<Folder>> packageMap =
1103 new ContextBuilder(resourceProvider, null, null)
1104 .convertPackagesToMap(packages);
1105 List<UriResolver> resolvers = <UriResolver>[
1106 new ResourceUriResolver(resourceProvider),
1107 new PackageMapUriResolver(resourceProvider, packageMap),
1108 ];
1109 SourceFactory sourceFactory =
1110 new SourceFactory(resolvers, packages, resourceProvider);
1111 return new AnalysisOptionsProvider(sourceFactory);
1112 }
1113
1114 /**
1122 * Create a new empty context associated with [folder], having parent 1115 * Create a new empty context associated with [folder], having parent
1123 * [parent] and using [packagesFile] to resolve package URI's. 1116 * [parent] and using [packagesFile] to resolve package URI's.
1124 */ 1117 */
1125 ContextInfo _createContext(ContextInfo parent, Folder folder, 1118 ContextInfo _createContext(ContextInfo parent, Folder folder,
1126 List<String> excludedPaths, File packagesFile) { 1119 List<String> excludedPaths, File packagesFile) {
1127 List<String> dependencies = <String>[]; 1120 List<String> dependencies = <String>[];
1128 FolderDisposition disposition = 1121 FolderDisposition disposition =
1129 _computeFolderDisposition(folder, dependencies.add, packagesFile); 1122 _computeFolderDisposition(folder, dependencies.add, packagesFile);
1130 ContextInfo info = new ContextInfo(this, parent, folder, packagesFile, 1123 ContextInfo info = new ContextInfo(this, parent, folder, packagesFile,
1131 normalizedPackageRoots[folder.path], disposition); 1124 normalizedPackageRoots[folder.path], disposition);
1132 1125
1133 Map<String, Object> optionMap = 1126 File optionsFile = null;
1134 readOptions(info.folder, disposition.packages); 1127 Map<String, Object> optionMap = null;
1128 try {
1129 AnalysisOptionsProvider provider =
1130 _createAnalysisOptionsProvider(disposition.packages);
1131 optionsFile = provider.getOptionsFile(info.folder, crawlUp: true);
1132 if (optionsFile != null) {
1133 optionMap = provider.getOptionsFromFile(optionsFile);
1134 }
1135 } catch (_) {
1136 // Parse errors are reported elsewhere.
1137 }
1135 AnalysisOptions options = 1138 AnalysisOptions options =
1136 new AnalysisOptionsImpl.from(defaultContextOptions); 1139 new AnalysisOptionsImpl.from(defaultContextOptions);
1137 applyToAnalysisOptions(options, optionMap); 1140 applyToAnalysisOptions(options, optionMap);
1138 1141
1139 info.setDependencies(dependencies); 1142 info.setDependencies(dependencies);
1140 String includedPath = folder.path; 1143 String includedPath = folder.path;
1141 List<String> containedExcludedPaths = excludedPaths 1144 List<String> containedExcludedPaths = excludedPaths
1142 .where((String excludedPath) => 1145 .where((String excludedPath) =>
1143 pathContext.isWithin(includedPath, excludedPath)) 1146 pathContext.isWithin(includedPath, excludedPath))
1144 .toList(); 1147 .toList();
1145 processOptionsForDriver(info, options, optionMap); 1148 processOptionsForDriver(info, options, optionMap);
1146 info.analysisDriver = callbacks.addAnalysisDriver( 1149 ContextRoot contextRoot =
1147 folder, new ContextRoot(folder.path, containedExcludedPaths), options); 1150 new ContextRoot(folder.path, containedExcludedPaths);
1151 if (optionsFile != null) {
1152 contextRoot.optionsFilePath = optionsFile.path;
1153 }
1154 info.analysisDriver =
1155 callbacks.addAnalysisDriver(folder, contextRoot, options);
1148 return info; 1156 return info;
1149 } 1157 }
1150 1158
1151 /** 1159 /**
1152 * Potentially create a new context associated with the given [folder]. 1160 * Potentially create a new context associated with the given [folder].
1153 * 1161 *
1154 * If there are subfolders with 'pubspec.yaml' files, separate contexts are 1162 * If there are subfolders with 'pubspec.yaml' files, separate contexts are
1155 * created for them and excluded from the context associated with the 1163 * created for them and excluded from the context associated with the
1156 * [folder]. 1164 * [folder].
1157 * 1165 *
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 } 1883 }
1876 return _embedderLocator; 1884 return _embedderLocator;
1877 } 1885 }
1878 1886
1879 @override 1887 @override
1880 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { 1888 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) {
1881 return _sdkExtensionFinder ??= 1889 return _sdkExtensionFinder ??=
1882 new SdkExtensionFinder(buildPackageMap(resourceProvider)); 1890 new SdkExtensionFinder(buildPackageMap(resourceProvider));
1883 } 1891 }
1884 } 1892 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/plugin/plugin_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698