| 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 'package:analysis_server/src/resource.dart'; | 7 import 'package:analysis_server/src/resource.dart'; |
| 8 import 'package:analyzer/src/generated/engine.dart'; |
| 9 import 'package:analyzer/src/generated/source.dart'; |
| 8 | 10 |
| 9 /** | 11 /** |
| 10 * Class that maintains a mapping from included/excluded paths to a set of | 12 * Class that maintains a mapping from included/excluded paths to a set of |
| 11 * folders that should correspond to analysis contexts. | 13 * folders that should correspond to analysis contexts. |
| 12 */ | 14 */ |
| 13 abstract class ContextDirectoryManager { | 15 abstract class ContextDirectoryManager { |
| 14 /** | 16 /** |
| 15 * The set of included folders in the most recent successful call to | 17 * The set of included folders in the most recent successful call to |
| 16 * [setRoots]. | 18 * [setRoots]. |
| 17 */ | 19 */ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 Set<Folder> excludedFolders = new Set<Folder>(); | 55 Set<Folder> excludedFolders = new Set<Folder>(); |
| 54 // diff | 56 // diff |
| 55 Set<Folder> newFolders = includedFolders.difference(currentFolders); | 57 Set<Folder> newFolders = includedFolders.difference(currentFolders); |
| 56 Set<Folder> oldFolders = currentFolders.difference(includedFolders); | 58 Set<Folder> oldFolders = currentFolders.difference(includedFolders); |
| 57 // remove old contexts | 59 // remove old contexts |
| 58 for (Folder folder in oldFolders) { | 60 for (Folder folder in oldFolders) { |
| 59 // TODO(scheglov) implement | 61 // TODO(scheglov) implement |
| 60 } | 62 } |
| 61 // add new contexts | 63 // add new contexts |
| 62 for (Folder folder in newFolders) { | 64 for (Folder folder in newFolders) { |
| 63 addContext(folder); | 65 File pubspecFile = folder.getChild('pubspec.yaml'); |
| 66 addContext(folder, pubspecFile.exists ? pubspecFile : null); |
| 67 ChangeSet changeSet = new ChangeSet(); |
| 68 _addSourceFiles(changeSet, folder); |
| 69 applyChangesToContext(folder, changeSet); |
| 64 } | 70 } |
| 65 currentFolders = new Set<Folder>.from(includedFolders); | 71 currentFolders = new Set<Folder>.from(includedFolders); |
| 66 } | 72 } |
| 67 | 73 |
| 68 /** | 74 /** |
| 69 * Called when a new context needs to be created. | 75 * Resursively adds all Dart and HTML files to the [changeSet]. |
| 70 */ | 76 */ |
| 71 void addContext(Folder folder); | 77 static void _addSourceFiles(ChangeSet changeSet, Folder folder) { |
| 78 List<Resource> children = folder.getChildren(); |
| 79 for (Resource child in children) { |
| 80 if (child is File) { |
| 81 String fileName = child.shortName; |
| 82 if (AnalysisEngine.isDartFileName(fileName) |
| 83 || AnalysisEngine.isHtmlFileName(fileName)) { |
| 84 Source source = child.createSource(UriKind.FILE_URI); |
| 85 changeSet.addedSource(source); |
| 86 } |
| 87 } else if (child is Folder) { |
| 88 _addSourceFiles(changeSet, child); |
| 89 } |
| 90 } |
| 91 } |
| 92 |
| 93 /** |
| 94 * Called when a new context needs to be created. If the context is |
| 95 * associated with a pubspec file, that file is passed in [pubspecFile]; |
| 96 * otherwise it is null. |
| 97 */ |
| 98 void addContext(Folder folder, File pubspecFile); |
| 99 |
| 100 /** |
| 101 * Called when the set of files associated with a context have changed (or |
| 102 * some of those files have been modified). [changeSet] is the set of |
| 103 * changes that need to be applied to the context. |
| 104 */ |
| 105 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); |
| 72 } | 106 } |
| OLD | NEW |