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

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

Issue 2214613003: Convert server and cli and deprecate the old implementation (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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 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/src/analysis_server.dart'; 12 import 'package:analysis_server/src/analysis_server.dart';
13 import 'package:analyzer/file_system/file_system.dart'; 13 import 'package:analyzer/file_system/file_system.dart';
14 import 'package:analyzer/instrumentation/instrumentation.dart'; 14 import 'package:analyzer/instrumentation/instrumentation.dart';
15 import 'package:analyzer/plugin/options.dart'; 15 import 'package:analyzer/plugin/options.dart';
16 import 'package:analyzer/plugin/resolver_provider.dart'; 16 import 'package:analyzer/plugin/resolver_provider.dart';
17 import 'package:analyzer/source/analysis_options_provider.dart'; 17 import 'package:analyzer/source/analysis_options_provider.dart';
18 import 'package:analyzer/source/config.dart'; 18 import 'package:analyzer/source/config.dart';
19 import 'package:analyzer/source/embedder.dart';
20 import 'package:analyzer/source/package_map_provider.dart'; 19 import 'package:analyzer/source/package_map_provider.dart';
21 import 'package:analyzer/source/package_map_resolver.dart'; 20 import 'package:analyzer/source/package_map_resolver.dart';
22 import 'package:analyzer/source/path_filter.dart'; 21 import 'package:analyzer/source/path_filter.dart';
23 import 'package:analyzer/source/pub_package_map_provider.dart'; 22 import 'package:analyzer/source/pub_package_map_provider.dart';
24 import 'package:analyzer/source/sdk_ext.dart'; 23 import 'package:analyzer/source/sdk_ext.dart';
24 import 'package:analyzer/src/context/builder.dart';
25 import 'package:analyzer/src/context/context.dart' as context; 25 import 'package:analyzer/src/context/context.dart' as context;
26 import 'package:analyzer/src/context/source.dart'; 26 import 'package:analyzer/src/context/source.dart';
27 import 'package:analyzer/src/dart/sdk/sdk.dart';
27 import 'package:analyzer/src/generated/engine.dart'; 28 import 'package:analyzer/src/generated/engine.dart';
28 import 'package:analyzer/src/generated/java_engine.dart'; 29 import 'package:analyzer/src/generated/java_engine.dart';
29 import 'package:analyzer/src/generated/java_io.dart'; 30 import 'package:analyzer/src/generated/java_io.dart';
30 import 'package:analyzer/src/generated/sdk.dart'; 31 import 'package:analyzer/src/generated/sdk.dart';
31 import 'package:analyzer/src/generated/source.dart'; 32 import 'package:analyzer/src/generated/source.dart';
32 import 'package:analyzer/src/generated/source_io.dart'; 33 import 'package:analyzer/src/generated/source_io.dart';
33 import 'package:analyzer/src/task/options.dart'; 34 import 'package:analyzer/src/task/options.dart';
34 import 'package:analyzer/src/util/absolute_path.dart'; 35 import 'package:analyzer/src/util/absolute_path.dart';
35 import 'package:analyzer/src/util/glob.dart'; 36 import 'package:analyzer/src/util/glob.dart';
36 import 'package:analyzer/src/util/yaml.dart'; 37 import 'package:analyzer/src/util/yaml.dart';
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 * File name of pubspec files. 385 * File name of pubspec files.
385 */ 386 */
386 static const String PUBSPEC_NAME = 'pubspec.yaml'; 387 static const String PUBSPEC_NAME = 'pubspec.yaml';
387 388
388 /** 389 /**
389 * File name of package spec files. 390 * File name of package spec files.
390 */ 391 */
391 static const String PACKAGE_SPEC_NAME = '.packages'; 392 static const String PACKAGE_SPEC_NAME = '.packages';
392 393
393 /** 394 /**
395 * The name of the key in an embedder file whose value is the list of
396 * libraries in the SDK.
397 * TODO(brianwilkerson) This is also defined in sdk.dart.
398 */
399 static const String _EMBEDDED_LIB_MAP_KEY = 'embedded_libs';
400
401 /**
394 * The [ResourceProvider] using which paths are converted into [Resource]s. 402 * The [ResourceProvider] using which paths are converted into [Resource]s.
395 */ 403 */
396 final ResourceProvider resourceProvider; 404 final ResourceProvider resourceProvider;
397 405
398 /** 406 /**
399 * The manager used to access the SDK that should be associated with a 407 * The manager used to access the SDK that should be associated with a
400 * particular context. 408 * particular context.
401 */ 409 */
402 final DartSdkManager sdkManager; 410 final DartSdkManager sdkManager;
403 411
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 516
509 @override 517 @override
510 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) { 518 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) {
511 List<AnalysisContext> contexts = <AnalysisContext>[]; 519 List<AnalysisContext> contexts = <AnalysisContext>[];
512 ContextInfo innermostContainingInfo = 520 ContextInfo innermostContainingInfo =
513 _getInnermostContextInfoFor(analysisRoot.path); 521 _getInnermostContextInfoFor(analysisRoot.path);
514 void addContextAndDescendants(ContextInfo info) { 522 void addContextAndDescendants(ContextInfo info) {
515 contexts.add(info.context); 523 contexts.add(info.context);
516 info.children.forEach(addContextAndDescendants); 524 info.children.forEach(addContextAndDescendants);
517 } 525 }
526
518 if (innermostContainingInfo != null) { 527 if (innermostContainingInfo != null) {
519 if (analysisRoot == innermostContainingInfo.folder) { 528 if (analysisRoot == innermostContainingInfo.folder) {
520 addContextAndDescendants(innermostContainingInfo); 529 addContextAndDescendants(innermostContainingInfo);
521 } else { 530 } else {
522 for (ContextInfo info in innermostContainingInfo.children) { 531 for (ContextInfo info in innermostContainingInfo.children) {
523 if (analysisRoot.isOrContains(info.folder.path)) { 532 if (analysisRoot.isOrContains(info.folder.path)) {
524 addContextAndDescendants(info); 533 addContextAndDescendants(info);
525 } 534 }
526 } 535 }
527 } 536 }
528 } 537 }
529 return contexts; 538 return contexts;
530 } 539 }
531 540
541 /**
542 * Check if this map defines embedded libraries.
543 */
544 bool definesEmbeddedLibs(Map map) => map[_EMBEDDED_LIB_MAP_KEY] != null;
545
532 @override 546 @override
533 AnalysisContext getContextFor(String path) { 547 AnalysisContext getContextFor(String path) {
534 return _getInnermostContextInfoFor(path)?.context; 548 return _getInnermostContextInfoFor(path)?.context;
535 } 549 }
536 550
537 /** 551 /**
538 * For testing: get the [ContextInfo] object for the given [folder], if any. 552 * For testing: get the [ContextInfo] object for the given [folder], if any.
539 */ 553 */
540 ContextInfo getContextInfoFor(Folder folder) { 554 ContextInfo getContextInfoFor(Folder folder) {
541 ContextInfo info = _getInnermostContextInfoFor(folder.path); 555 ContextInfo info = _getInnermostContextInfoFor(folder.path);
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 // Check for library embedders. 920 // Check for library embedders.
907 if (embedderYamls.values.any(definesEmbeddedLibs)) { 921 if (embedderYamls.values.any(definesEmbeddedLibs)) {
908 // If there is no embedded URI resolver, a new source factory needs to 922 // If there is no embedded URI resolver, a new source factory needs to
909 // be recreated. 923 // be recreated.
910 if (sourceFactory is SourceFactoryImpl) { 924 if (sourceFactory is SourceFactoryImpl) {
911 // Get all but the dart: Uri resolver. 925 // Get all but the dart: Uri resolver.
912 List<UriResolver> resolvers = sourceFactory.resolvers 926 List<UriResolver> resolvers = sourceFactory.resolvers
913 .where((r) => r is! DartUriResolver) 927 .where((r) => r is! DartUriResolver)
914 .toList(); 928 .toList();
915 // Add an embedded URI resolver in its place. 929 // Add an embedded URI resolver in its place.
916 resolvers.add(new DartUriResolver(new EmbedderSdk(embedderYamls))); 930 resolvers.add(new DartUriResolver(
931 new EmbedderSdk(resourceProvider, embedderYamls)));
917 932
918 // Set a new source factory. 933 // Set a new source factory.
919 SourceFactoryImpl newFactory = sourceFactory.clone(); 934 SourceFactoryImpl newFactory = sourceFactory.clone();
920 newFactory.resolvers.clear(); 935 newFactory.resolvers.clear();
921 newFactory.resolvers.addAll(resolvers); 936 newFactory.resolvers.addAll(resolvers);
922 info.context.sourceFactory = newFactory; 937 info.context.sourceFactory = newFactory;
923 return; 938 return;
924 } 939 }
925 } 940 }
926 941
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 */ 1166 */
1152 SourceFactory _createSourceFactory(InternalAnalysisContext context, 1167 SourceFactory _createSourceFactory(InternalAnalysisContext context,
1153 AnalysisOptions options, FolderDisposition disposition, Folder folder) { 1168 AnalysisOptions options, FolderDisposition disposition, Folder folder) {
1154 List<UriResolver> resolvers = []; 1169 List<UriResolver> resolvers = [];
1155 List<UriResolver> packageUriResolvers = 1170 List<UriResolver> packageUriResolvers =
1156 disposition.createPackageUriResolvers(resourceProvider); 1171 disposition.createPackageUriResolvers(resourceProvider);
1157 1172
1158 EmbedderYamlLocator locator = 1173 EmbedderYamlLocator locator =
1159 disposition.getEmbedderLocator(resourceProvider); 1174 disposition.getEmbedderLocator(resourceProvider);
1160 Map<Folder, YamlMap> embedderYamls = locator.embedderYamls; 1175 Map<Folder, YamlMap> embedderYamls = locator.embedderYamls;
1161 EmbedderSdk embedderSdk = new EmbedderSdk(embedderYamls); 1176 EmbedderSdk embedderSdk = new EmbedderSdk(resourceProvider, embedderYamls);
1162 if (embedderSdk.libraryMap.size() == 0) { 1177 if (embedderSdk.libraryMap.size() == 0) {
1163 // There was no embedder file, or the file was empty, so used the default 1178 // There was no embedder file, or the file was empty, so used the default
1164 // SDK. 1179 // SDK.
1165 resolvers.add(new DartUriResolver(sdkManager.getSdkForOptions(options))); 1180 resolvers.add(new DartUriResolver(sdkManager.getSdkForOptions(options)));
1166 } else { 1181 } else {
1167 // The embedder file defines an alternate SDK, so use it. 1182 // The embedder file defines an alternate SDK, so use it.
1168 List<String> paths = <String>[]; 1183 List<String> paths = <String>[];
1169 for (Folder folder in embedderYamls.keys) { 1184 for (Folder folder in embedderYamls.keys) {
1170 paths.add(folder 1185 paths.add(folder
1171 .getChildAssumingFile(EmbedderYamlLocator.EMBEDDER_FILE_NAME) 1186 .getChildAssumingFile(EmbedderYamlLocator.EMBEDDER_FILE_NAME)
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 1862
1848 @override 1863 @override
1849 EmbedderYamlLocator getEmbedderLocator(ResourceProvider resourceProvider) { 1864 EmbedderYamlLocator getEmbedderLocator(ResourceProvider resourceProvider) {
1850 if (_embedderLocator == null) { 1865 if (_embedderLocator == null) {
1851 _embedderLocator = 1866 _embedderLocator =
1852 new EmbedderYamlLocator(buildPackageMap(resourceProvider)); 1867 new EmbedderYamlLocator(buildPackageMap(resourceProvider));
1853 } 1868 }
1854 return _embedderLocator; 1869 return _embedderLocator;
1855 } 1870 }
1856 } 1871 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | pkg/analysis_server/lib/src/status/get_handler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698