Index: pkg/analysis_server/lib/src/context_manager.dart |
diff --git a/pkg/analysis_server/lib/src/context_manager.dart b/pkg/analysis_server/lib/src/context_manager.dart |
index fd35213fc99a8963a0232387f8e2dd7d3d4b8de6..5c4790947bae3de6f096084c83e2e5dc10b69bd8 100644 |
--- a/pkg/analysis_server/lib/src/context_manager.dart |
+++ b/pkg/analysis_server/lib/src/context_manager.dart |
@@ -23,7 +23,6 @@ import 'package:analyzer/source/pub_package_map_provider.dart'; |
import 'package:analyzer/source/sdk_ext.dart'; |
import 'package:analyzer/src/context/builder.dart'; |
import 'package:analyzer/src/context/context.dart' as context; |
-import 'package:analyzer/src/context/source.dart'; |
import 'package:analyzer/src/dart/sdk/sdk.dart'; |
import 'package:analyzer/src/generated/engine.dart'; |
import 'package:analyzer/src/generated/java_engine.dart'; |
@@ -343,6 +342,12 @@ abstract class ContextManagerCallbacks { |
void computingPackageMap(bool computing); |
/** |
+ * Create and return a context builder that can be used to create a context |
+ * for the files in the given [folder] when analyzed using the given [options]. |
+ */ |
+ ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options); |
+ |
+ /** |
* Called when the context manager changes the folder with which a context is |
* associated. Currently this is mostly FYI, and used only in tests. |
*/ |
@@ -899,55 +904,14 @@ class ContextManagerImpl implements ContextManager { |
// Check to see if this is the .packages file for this context and if so, |
// update the context's source factory. |
if (absolutePathContext.basename(path) == PACKAGE_SPEC_NAME) { |
- File packagespec = resourceProvider.getFile(path); |
- if (packagespec.exists) { |
- // Locate embedder yamls for this .packages file. |
- // If any embedder libs are contributed and this context does not |
- // have an embedded URI resolver, we need to create a new context. |
- |
- List<int> bytes = packagespec.readAsStringSync().codeUnits; |
- Map<String, Uri> packages = |
- pkgfile.parse(bytes, new Uri.file(packagespec.path)); |
- |
- Map<String, List<Folder>> packageMap = |
- new PackagesFileDisposition(new MapPackages(packages)) |
- .buildPackageMap(resourceProvider); |
- Map<Folder, YamlMap> embedderYamls = |
- new EmbedderYamlLocator(packageMap).embedderYamls; |
- |
- SourceFactory sourceFactory = info.context.sourceFactory; |
- |
- // Check for library embedders. |
- if (embedderYamls.values.any(definesEmbeddedLibs)) { |
- // If there is no embedded URI resolver, a new source factory needs to |
- // be recreated. |
- if (sourceFactory is SourceFactoryImpl) { |
- // Get all but the dart: Uri resolver. |
- List<UriResolver> resolvers = sourceFactory.resolvers |
- .where((r) => r is! DartUriResolver) |
- .toList(); |
- // Add an embedded URI resolver in its place. |
- resolvers.add(new DartUriResolver( |
- new EmbedderSdk(resourceProvider, embedderYamls))); |
- |
- // Set a new source factory. |
- SourceFactoryImpl newFactory = sourceFactory.clone(); |
- newFactory.resolvers.clear(); |
- newFactory.resolvers.addAll(resolvers); |
- info.context.sourceFactory = newFactory; |
- return; |
- } |
- } |
- |
- // Next check for package URI updates. |
- if (info.isPathToPackageDescription(path)) { |
- Packages packages = _readPackagespec(packagespec); |
- if (packages != null) { |
- _updateContextPackageUriResolver( |
- folder, new PackagesFileDisposition(packages)); |
- } |
- } |
- } |
+ String contextRoot = info.folder.path; |
+ ContextBuilder builder = |
+ callbacks.createContextBuilder(info.folder, defaultContextOptions); |
+ AnalysisOptions options = |
+ builder.getAnalysisOptions(info.context, contextRoot); |
+ SourceFactory factory = builder.createSourceFactory(contextRoot, options); |
+ info.context.analysisOptions = options; |
+ info.context.sourceFactory = factory; |
} |
} |