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:analyzer/src/context/context.dart' as context; | |
13 import 'package:analysis_server/plugin/analysis/resolver_provider.dart'; | 12 import 'package:analysis_server/plugin/analysis/resolver_provider.dart'; |
14 import 'package:analysis_server/src/analysis_server.dart'; | 13 import 'package:analysis_server/src/analysis_server.dart'; |
15 import 'package:analysis_server/src/server_options.dart'; | |
16 import 'package:analyzer/file_system/file_system.dart'; | 14 import 'package:analyzer/file_system/file_system.dart'; |
17 import 'package:analyzer/instrumentation/instrumentation.dart'; | 15 import 'package:analyzer/instrumentation/instrumentation.dart'; |
18 import 'package:analyzer/plugin/options.dart'; | 16 import 'package:analyzer/plugin/options.dart'; |
19 import 'package:analyzer/source/analysis_options_provider.dart'; | 17 import 'package:analyzer/source/analysis_options_provider.dart'; |
20 import 'package:analyzer/source/package_map_provider.dart'; | 18 import 'package:analyzer/source/package_map_provider.dart'; |
21 import 'package:analyzer/source/package_map_resolver.dart'; | 19 import 'package:analyzer/source/package_map_resolver.dart'; |
22 import 'package:analyzer/source/path_filter.dart'; | 20 import 'package:analyzer/source/path_filter.dart'; |
23 import 'package:analyzer/source/pub_package_map_provider.dart'; | 21 import 'package:analyzer/source/pub_package_map_provider.dart'; |
24 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; |
25 import 'package:analyzer/src/generated/engine.dart'; | 24 import 'package:analyzer/src/generated/engine.dart'; |
26 import 'package:analyzer/src/generated/java_engine.dart'; | 25 import 'package:analyzer/src/generated/java_engine.dart'; |
27 import 'package:analyzer/src/generated/java_io.dart'; | 26 import 'package:analyzer/src/generated/java_io.dart'; |
28 import 'package:analyzer/src/generated/source.dart'; | 27 import 'package:analyzer/src/generated/source.dart'; |
29 import 'package:analyzer/src/generated/source_io.dart'; | 28 import 'package:analyzer/src/generated/source_io.dart'; |
30 import 'package:package_config/packages.dart'; | 29 import 'package:package_config/packages.dart'; |
31 import 'package:package_config/packages_file.dart' as pkgfile show parse; | 30 import 'package:package_config/packages_file.dart' as pkgfile show parse; |
32 import 'package:package_config/src/packages_impl.dart' show MapPackages; | 31 import 'package:package_config/src/packages_impl.dart' show MapPackages; |
33 import 'package:path/path.dart' as pathos; | 32 import 'package:path/path.dart' as pathos; |
34 import 'package:watcher/watcher.dart'; | 33 import 'package:watcher/watcher.dart'; |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 void updateContextPackageUriResolver( | 304 void updateContextPackageUriResolver( |
306 Folder contextFolder, FolderDisposition disposition); | 305 Folder contextFolder, FolderDisposition disposition); |
307 } | 306 } |
308 | 307 |
309 /** | 308 /** |
310 * Class that maintains a mapping from included/excluded paths to a set of | 309 * Class that maintains a mapping from included/excluded paths to a set of |
311 * folders that should correspond to analysis contexts. | 310 * folders that should correspond to analysis contexts. |
312 */ | 311 */ |
313 class ContextManagerImpl implements ContextManager { | 312 class ContextManagerImpl implements ContextManager { |
314 /** | 313 /** |
315 * File name of analysis options files. | |
316 */ | |
317 static const String ANALYSIS_OPTIONS_FILE = '.analysis_options'; | |
318 | |
319 /** | |
320 * The name of the `lib` directory. | 314 * The name of the `lib` directory. |
321 */ | 315 */ |
322 static const String LIB_DIR_NAME = 'lib'; | 316 static const String LIB_DIR_NAME = 'lib'; |
323 | 317 |
324 /** | 318 /** |
325 * The name of `packages` folders. | 319 * The name of `packages` folders. |
326 */ | 320 */ |
327 static const String PACKAGES_NAME = 'packages'; | 321 static const String PACKAGES_NAME = 'packages'; |
328 | 322 |
329 /** | 323 /** |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 } else if (child is Folder) { | 721 } else if (child is Folder) { |
728 String shortName = child.shortName; | 722 String shortName = child.shortName; |
729 if (shortName == PACKAGES_NAME) { | 723 if (shortName == PACKAGES_NAME) { |
730 continue; | 724 continue; |
731 } | 725 } |
732 _addSourceFiles(changeSet, child, info); | 726 _addSourceFiles(changeSet, child, info); |
733 } | 727 } |
734 } | 728 } |
735 } | 729 } |
736 | 730 |
| 731 void _checkForAnalysisOptionsUpdate( |
| 732 String path, ContextInfo info, ChangeType changeType) { |
| 733 if (AnalysisEngine.isAnalysisOptionsFileName(path, pathContext)) { |
| 734 var analysisContext = info.context; |
| 735 if (analysisContext is context.AnalysisContextImpl) { |
| 736 processOptionsForContext(info, info.folder, |
| 737 optionsRemoved: changeType == ChangeType.REMOVE); |
| 738 analysisContext.invalidateCachedResults(); |
| 739 callbacks.applyChangesToContext(info.folder, new ChangeSet()); |
| 740 } |
| 741 } |
| 742 } |
| 743 |
737 void _checkForPackagespecUpdate( | 744 void _checkForPackagespecUpdate( |
738 String path, ContextInfo info, Folder folder) { | 745 String path, ContextInfo info, Folder folder) { |
739 // Check to see if this is the .packages file for this context and if so, | 746 // Check to see if this is the .packages file for this context and if so, |
740 // update the context's source factory. | 747 // update the context's source factory. |
741 if (pathContext.basename(path) == PACKAGE_SPEC_NAME && | 748 if (pathContext.basename(path) == PACKAGE_SPEC_NAME && |
742 info.isPathToPackageDescription(path)) { | 749 info.isPathToPackageDescription(path)) { |
743 File packagespec = resourceProvider.getFile(path); | 750 File packagespec = resourceProvider.getFile(path); |
744 if (packagespec.exists) { | 751 if (packagespec.exists) { |
745 Packages packages = _readPackagespec(packagespec); | 752 Packages packages = _readPackagespec(packagespec); |
746 if (packages != null) { | 753 if (packages != null) { |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 changeSet.changedSource(source); | 1157 changeSet.changedSource(source); |
1151 }); | 1158 }); |
1152 callbacks.applyChangesToContext(info.folder, changeSet); | 1159 callbacks.applyChangesToContext(info.folder, changeSet); |
1153 } | 1160 } |
1154 break; | 1161 break; |
1155 } | 1162 } |
1156 _checkForPackagespecUpdate(path, info, info.folder); | 1163 _checkForPackagespecUpdate(path, info, info.folder); |
1157 _checkForAnalysisOptionsUpdate(path, info, event.type); | 1164 _checkForAnalysisOptionsUpdate(path, info, event.type); |
1158 } | 1165 } |
1159 | 1166 |
1160 void _checkForAnalysisOptionsUpdate( | |
1161 String path, ContextInfo info, ChangeType changeType) { | |
1162 if (pathContext.basename(path) == ANALYSIS_OPTIONS_FILE) { | |
1163 var analysisContext = info.context; | |
1164 if (analysisContext is context.AnalysisContextImpl) { | |
1165 processOptionsForContext(info, info.folder, | |
1166 optionsRemoved: changeType == ChangeType.REMOVE); | |
1167 analysisContext.invalidateCachedResults(); | |
1168 callbacks.applyChangesToContext(info.folder, new ChangeSet()); | |
1169 } | |
1170 } | |
1171 } | |
1172 | |
1173 /** | 1167 /** |
1174 * Determine whether the given [path], when interpreted relative to the | 1168 * Determine whether the given [path], when interpreted relative to the |
1175 * context root [root], contains a folder whose name starts with '.'. | 1169 * context root [root], contains a folder whose name starts with '.'. |
1176 */ | 1170 */ |
1177 bool _isContainedInDotFolder(String root, String path) { | 1171 bool _isContainedInDotFolder(String root, String path) { |
1178 String relativePath = | 1172 String relativePath = |
1179 pathContext.relative(pathContext.dirname(path), from: root); | 1173 pathContext.relative(pathContext.dirname(path), from: root); |
1180 for (String pathComponent in pathContext.split(relativePath)) { | 1174 for (String pathComponent in pathContext.split(relativePath)) { |
1181 if (pathComponent.startsWith('.') && | 1175 if (pathComponent.startsWith('.') && |
1182 pathComponent != '.' && | 1176 pathComponent != '.' && |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 var path = resourceProvider.pathContext.fromUri(uri); | 1440 var path = resourceProvider.pathContext.fromUri(uri); |
1447 packageMap[name] = <Folder>[resourceProvider.getFolder(path)]; | 1441 packageMap[name] = <Folder>[resourceProvider.getFolder(path)]; |
1448 } | 1442 } |
1449 }); | 1443 }); |
1450 return <UriResolver>[new SdkExtUriResolver(packageMap)]; | 1444 return <UriResolver>[new SdkExtUriResolver(packageMap)]; |
1451 } else { | 1445 } else { |
1452 return const <UriResolver>[]; | 1446 return const <UriResolver>[]; |
1453 } | 1447 } |
1454 } | 1448 } |
1455 } | 1449 } |
OLD | NEW |