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

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

Issue 2946313003: Restore partial analysis of analysis options files (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
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:analysis_server/src/plugin/notification_manager.dart';
10 import 'package:analyzer/context/context_root.dart'; 11 import 'package:analyzer/context/context_root.dart';
12 import 'package:analyzer/error/error.dart';
11 import 'package:analyzer/file_system/file_system.dart'; 13 import 'package:analyzer/file_system/file_system.dart';
12 import 'package:analyzer/instrumentation/instrumentation.dart'; 14 import 'package:analyzer/instrumentation/instrumentation.dart';
13 import 'package:analyzer/plugin/resolver_provider.dart'; 15 import 'package:analyzer/plugin/resolver_provider.dart';
14 import 'package:analyzer/source/analysis_options_provider.dart'; 16 import 'package:analyzer/source/analysis_options_provider.dart';
15 import 'package:analyzer/source/package_map_provider.dart'; 17 import 'package:analyzer/source/package_map_provider.dart';
16 import 'package:analyzer/source/package_map_resolver.dart'; 18 import 'package:analyzer/source/package_map_resolver.dart';
17 import 'package:analyzer/source/path_filter.dart'; 19 import 'package:analyzer/source/path_filter.dart';
18 import 'package:analyzer/source/pub_package_map_provider.dart'; 20 import 'package:analyzer/source/pub_package_map_provider.dart';
19 import 'package:analyzer/source/sdk_ext.dart'; 21 import 'package:analyzer/source/sdk_ext.dart';
20 import 'package:analyzer/src/context/builder.dart'; 22 import 'package:analyzer/src/context/builder.dart';
21 import 'package:analyzer/src/dart/analysis/driver.dart'; 23 import 'package:analyzer/src/dart/analysis/driver.dart';
22 import 'package:analyzer/src/dart/sdk/sdk.dart'; 24 import 'package:analyzer/src/dart/sdk/sdk.dart';
23 import 'package:analyzer/src/generated/engine.dart'; 25 import 'package:analyzer/src/generated/engine.dart';
26 import 'package:analyzer/src/generated/java_engine.dart';
24 import 'package:analyzer/src/generated/java_io.dart'; 27 import 'package:analyzer/src/generated/java_io.dart';
25 import 'package:analyzer/src/generated/sdk.dart'; 28 import 'package:analyzer/src/generated/sdk.dart';
26 import 'package:analyzer/src/generated/source.dart'; 29 import 'package:analyzer/src/generated/source.dart';
27 import 'package:analyzer/src/generated/source_io.dart'; 30 import 'package:analyzer/src/generated/source_io.dart';
28 import 'package:analyzer/src/task/options.dart'; 31 import 'package:analyzer/src/task/options.dart';
29 import 'package:analyzer/src/util/absolute_path.dart'; 32 import 'package:analyzer/src/util/absolute_path.dart';
30 import 'package:analyzer/src/util/glob.dart'; 33 import 'package:analyzer/src/util/glob.dart';
31 import 'package:analyzer/src/util/yaml.dart'; 34 import 'package:analyzer/src/util/yaml.dart';
35 import 'package:analyzer_plugin/utilities/analyzer_converter.dart';
32 import 'package:package_config/packages.dart'; 36 import 'package:package_config/packages.dart';
33 import 'package:package_config/packages_file.dart' as pkgfile show parse; 37 import 'package:package_config/packages_file.dart' as pkgfile show parse;
34 import 'package:package_config/src/packages_impl.dart' show MapPackages; 38 import 'package:package_config/src/packages_impl.dart' show MapPackages;
35 import 'package:path/path.dart' as pathos; 39 import 'package:path/path.dart' as pathos;
36 import 'package:watcher/watcher.dart'; 40 import 'package:watcher/watcher.dart';
37 import 'package:yaml/yaml.dart'; 41 import 'package:yaml/yaml.dart';
38 42
39 /** 43 /**
40 * Information tracked by the [ContextManager] for each context. 44 * Information tracked by the [ContextManager] for each context.
41 */ 45 */
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 * created, destroyed or updated, (b) inform the client when "pub list" 354 * created, destroyed or updated, (b) inform the client when "pub list"
351 * operations are in progress, and (c) determine which files should be 355 * operations are in progress, and (c) determine which files should be
352 * analyzed. 356 * analyzed.
353 * 357 *
354 * TODO(paulberry): eliminate this interface, and instead have [ContextManager] 358 * TODO(paulberry): eliminate this interface, and instead have [ContextManager]
355 * operations return data structures describing how context state should be 359 * operations return data structures describing how context state should be
356 * modified. 360 * modified.
357 */ 361 */
358 abstract class ContextManagerCallbacks { 362 abstract class ContextManagerCallbacks {
359 /** 363 /**
364 * Return the notification manager associated with the server.
365 */
366 NotificationManager get notificationManager;
367
368 /**
360 * Create and return a new analysis driver rooted at the given [folder], with 369 * Create and return a new analysis driver rooted at the given [folder], with
361 * the given analysis [options]. 370 * the given analysis [options].
362 */ 371 */
363 AnalysisDriver addAnalysisDriver( 372 AnalysisDriver addAnalysisDriver(
364 Folder folder, ContextRoot contextRoot, AnalysisOptions options); 373 Folder folder, ContextRoot contextRoot, AnalysisOptions options);
365 374
366 /** 375 /**
367 * Create and return a new analysis context rooted at the given [folder], with 376 * Create and return a new analysis context rooted at the given [folder], with
368 * the given analysis [options]. 377 * the given analysis [options].
369 */ 378 */
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 } else if (child is Folder) { 969 } else if (child is Folder) {
961 String shortName = child.shortName; 970 String shortName = child.shortName;
962 if (shortName == PACKAGES_NAME) { 971 if (shortName == PACKAGES_NAME) {
963 continue; 972 continue;
964 } 973 }
965 _addSourceFiles(changeSet, child, info); 974 _addSourceFiles(changeSet, child, info);
966 } 975 }
967 } 976 }
968 } 977 }
969 978
979 /**
980 * Use the given analysis [driver] to analyze the content of the analysis
981 * options file at the given [path].
982 */
983 void _analyzeAnalysisOptionsFile(AnalysisDriver driver, String path) {
984 String content = driver.fsState.getFileForPath(path).content;
985 List<AnalysisError> errors =
986 GenerateOptionsErrorsTask.analyzeAnalysisOptions(
987 resourceProvider.getFile(path).createSource(),
988 content,
989 driver.sourceFactory);
990 AnalyzerConverter converter = new AnalyzerConverter();
991 LineInfo lineInfo = _computeLineInfo(content);
992 callbacks.notificationManager.recordAnalysisErrors(
993 NotificationManager.serverId,
994 path,
995 converter.convertAnalysisErrors(errors,
996 lineInfo: lineInfo, options: driver.analysisOptions));
997 }
998
970 void _checkForAnalysisOptionsUpdate( 999 void _checkForAnalysisOptionsUpdate(
971 String path, ContextInfo info, ChangeType changeType) { 1000 String path, ContextInfo info, ChangeType changeType) {
972 if (AnalysisEngine.isAnalysisOptionsFileName(path, pathContext)) { 1001 if (AnalysisEngine.isAnalysisOptionsFileName(path, pathContext)) {
973 AnalysisDriver driver = info.analysisDriver; 1002 AnalysisDriver driver = info.analysisDriver;
974 String contextRoot = info.folder.path; 1003 String contextRoot = info.folder.path;
975 ContextBuilder builder = 1004 ContextBuilder builder =
976 callbacks.createContextBuilder(info.folder, defaultContextOptions); 1005 callbacks.createContextBuilder(info.folder, defaultContextOptions);
977 AnalysisOptions options = builder.getAnalysisOptions(contextRoot, 1006 AnalysisOptions options = builder.getAnalysisOptions(contextRoot,
978 contextRoot: driver.contextRoot); 1007 contextRoot: driver.contextRoot);
979 SourceFactory factory = builder.createSourceFactory(contextRoot, options); 1008 SourceFactory factory = builder.createSourceFactory(contextRoot, options);
980 driver.configure(analysisOptions: options, sourceFactory: factory); 1009 driver.configure(analysisOptions: options, sourceFactory: factory);
981 // TODO(brianwilkerson) Set exclusion patterns. 1010 // TODO(brianwilkerson) Set exclusion patterns.
1011 _analyzeAnalysisOptionsFile(driver, path);
982 } 1012 }
983 } 1013 }
984 1014
985 void _checkForPackagespecUpdate( 1015 void _checkForPackagespecUpdate(
986 String path, ContextInfo info, Folder folder) { 1016 String path, ContextInfo info, Folder folder) {
987 // Check to see if this is the .packages file for this context and if so, 1017 // Check to see if this is the .packages file for this context and if so,
988 // update the context's source factory. 1018 // update the context's source factory.
989 if (absolutePathContext.basename(path) == PACKAGE_SPEC_NAME) { 1019 if (absolutePathContext.basename(path) == PACKAGE_SPEC_NAME) {
990 String contextRoot = info.folder.path; 1020 String contextRoot = info.folder.path;
991 ContextBuilder builder = 1021 ContextBuilder builder =
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 addDependency(dependencyPath); 1118 addDependency(dependencyPath);
1089 } 1119 }
1090 if (packageMapInfo.packageMap == null) { 1120 if (packageMapInfo.packageMap == null) {
1091 return new NoPackageFolderDisposition(); 1121 return new NoPackageFolderDisposition();
1092 } 1122 }
1093 return new PackageMapDisposition(packageMapInfo.packageMap); 1123 return new PackageMapDisposition(packageMapInfo.packageMap);
1094 } 1124 }
1095 } 1125 }
1096 1126
1097 /** 1127 /**
1128 * Compute line information for the given [content].
1129 */
1130 LineInfo _computeLineInfo(String content) {
1131 List<int> lineStarts = StringUtilities.computeLineStarts(content);
1132 return new LineInfo(lineStarts);
1133 }
1134
1135 /**
1098 * Create an object that can be used to find and read the analysis options 1136 * Create an object that can be used to find and read the analysis options
1099 * file for code being analyzed using the given [packages]. 1137 * file for code being analyzed using the given [packages].
1100 */ 1138 */
1101 AnalysisOptionsProvider _createAnalysisOptionsProvider(Packages packages) { 1139 AnalysisOptionsProvider _createAnalysisOptionsProvider(Packages packages) {
1102 Map<String, List<Folder>> packageMap = 1140 Map<String, List<Folder>> packageMap =
1103 new ContextBuilder(resourceProvider, null, null) 1141 new ContextBuilder(resourceProvider, null, null)
1104 .convertPackagesToMap(packages); 1142 .convertPackagesToMap(packages);
1105 List<UriResolver> resolvers = <UriResolver>[ 1143 List<UriResolver> resolvers = <UriResolver>[
1106 new ResourceUriResolver(resourceProvider), 1144 new ResourceUriResolver(resourceProvider),
1107 new PackageMapUriResolver(resourceProvider, packageMap), 1145 new PackageMapUriResolver(resourceProvider, packageMap),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 pathContext.isWithin(includedPath, excludedPath)) 1184 pathContext.isWithin(includedPath, excludedPath))
1147 .toList(); 1185 .toList();
1148 processOptionsForDriver(info, options, optionMap); 1186 processOptionsForDriver(info, options, optionMap);
1149 ContextRoot contextRoot = 1187 ContextRoot contextRoot =
1150 new ContextRoot(folder.path, containedExcludedPaths); 1188 new ContextRoot(folder.path, containedExcludedPaths);
1151 if (optionsFile != null) { 1189 if (optionsFile != null) {
1152 contextRoot.optionsFilePath = optionsFile.path; 1190 contextRoot.optionsFilePath = optionsFile.path;
1153 } 1191 }
1154 info.analysisDriver = 1192 info.analysisDriver =
1155 callbacks.addAnalysisDriver(folder, contextRoot, options); 1193 callbacks.addAnalysisDriver(folder, contextRoot, options);
1194 if (optionsFile != null) {
1195 _analyzeAnalysisOptionsFile(info.analysisDriver, optionsFile.path);
1196 }
1156 return info; 1197 return info;
1157 } 1198 }
1158 1199
1159 /** 1200 /**
1160 * Potentially create a new context associated with the given [folder]. 1201 * Potentially create a new context associated with the given [folder].
1161 * 1202 *
1162 * If there are subfolders with 'pubspec.yaml' files, separate contexts are 1203 * If there are subfolders with 'pubspec.yaml' files, separate contexts are
1163 * created for them and excluded from the context associated with the 1204 * created for them and excluded from the context associated with the
1164 * [folder]. 1205 * [folder].
1165 * 1206 *
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 } 1924 }
1884 return _embedderLocator; 1925 return _embedderLocator;
1885 } 1926 }
1886 1927
1887 @override 1928 @override
1888 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { 1929 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) {
1889 return _sdkExtensionFinder ??= 1930 return _sdkExtensionFinder ??=
1890 new SdkExtensionFinder(buildPackageMap(resourceProvider)); 1931 new SdkExtensionFinder(buildPackageMap(resourceProvider));
1891 } 1932 }
1892 } 1933 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698