| 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 | 9 |
| 10 import 'package:analysis_server/src/package_map_provider.dart'; | 10 import 'package:analysis_server/src/package_map_provider.dart'; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } | 137 } |
| 138 | 138 |
| 139 void _handleWatchEvent(Folder folder, _ContextDirectoryInfo info, WatchEvent e
vent) { | 139 void _handleWatchEvent(Folder folder, _ContextDirectoryInfo info, WatchEvent e
vent) { |
| 140 switch (event.type) { | 140 switch (event.type) { |
| 141 case ChangeType.ADD: | 141 case ChangeType.ADD: |
| 142 if (_isInPackagesDir(event.path, folder)) { | 142 if (_isInPackagesDir(event.path, folder)) { |
| 143 // TODO(paulberry): perhaps we should only skip packages dirs if | 143 // TODO(paulberry): perhaps we should only skip packages dirs if |
| 144 // there is a pubspec.yaml? | 144 // there is a pubspec.yaml? |
| 145 break; | 145 break; |
| 146 } | 146 } |
| 147 if (_shouldFileBeAnalyzed(event.path)) { | 147 Resource resource = resourceProvider.getResource(event.path); |
| 148 ChangeSet changeSet = new ChangeSet(); | 148 // If the file went away and was replaced by a folder before we |
| 149 Resource resource = resourceProvider.getResource(event.path); | 149 // had a chance to process the event, resource might be a Folder. In |
| 150 // If the file went away and was replaced by a folder before we | 150 // that case don't add it. |
| 151 // had a chance to process the event, resource might be a Folder. In | 151 if (resource is File) { |
| 152 // that case don't add it. | 152 File file = resource; |
| 153 if (resource is File) { | 153 if (_shouldFileBeAnalyzed(file)) { |
| 154 File file = resource; | 154 ChangeSet changeSet = new ChangeSet(); |
| 155 Source source = file.createSource(UriKind.FILE_URI); | 155 Source source = file.createSource(UriKind.FILE_URI); |
| 156 changeSet.addedSource(source); | 156 changeSet.addedSource(source); |
| 157 applyChangesToContext(folder, changeSet); | 157 applyChangesToContext(folder, changeSet); |
| 158 info.sources[event.path]= source; | 158 info.sources[event.path]= source; |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 break; | 161 break; |
| 162 case ChangeType.REMOVE: | 162 case ChangeType.REMOVE: |
| 163 Source source = info.sources[event.path]; | 163 Source source = info.sources[event.path]; |
| 164 if (source != null) { | 164 if (source != null) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 return false; | 204 return false; |
| 205 } | 205 } |
| 206 | 206 |
| 207 /** | 207 /** |
| 208 * Resursively adds all Dart and HTML files to the [changeSet]. | 208 * Resursively adds all Dart and HTML files to the [changeSet]. |
| 209 */ | 209 */ |
| 210 static void _addSourceFiles(ChangeSet changeSet, Folder folder, _ContextDirect
oryInfo info) { | 210 static void _addSourceFiles(ChangeSet changeSet, Folder folder, _ContextDirect
oryInfo info) { |
| 211 List<Resource> children = folder.getChildren(); | 211 List<Resource> children = folder.getChildren(); |
| 212 for (Resource child in children) { | 212 for (Resource child in children) { |
| 213 if (child is File) { | 213 if (child is File) { |
| 214 if (_shouldFileBeAnalyzed(child.path)) { | 214 if (_shouldFileBeAnalyzed(child)) { |
| 215 Source source = child.createSource(UriKind.FILE_URI); | 215 Source source = child.createSource(UriKind.FILE_URI); |
| 216 changeSet.addedSource(source); | 216 changeSet.addedSource(source); |
| 217 info.sources[child.path] = source; | 217 info.sources[child.path] = source; |
| 218 } | 218 } |
| 219 } else if (child is Folder) { | 219 } else if (child is Folder) { |
| 220 if (child.shortName == 'packages') { | 220 if (child.shortName == 'packages') { |
| 221 // TODO(paulberry): perhaps we should only skip packages dirs if | 221 // TODO(paulberry): perhaps we should only skip packages dirs if |
| 222 // there is a pubspec.yaml? | 222 // there is a pubspec.yaml? |
| 223 continue; | 223 continue; |
| 224 } | 224 } |
| 225 _addSourceFiles(changeSet, child, info); | 225 _addSourceFiles(changeSet, child, info); |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 static bool _shouldFileBeAnalyzed(String path) { | 230 static bool _shouldFileBeAnalyzed(File file) { |
| 231 return AnalysisEngine.isDartFileName(path) | 231 if (!(AnalysisEngine.isDartFileName(file.path) |
| 232 || AnalysisEngine.isHtmlFileName(path); | 232 || AnalysisEngine.isHtmlFileName(file.path))) { |
| 233 return false; |
| 234 } |
| 235 // Emacs creates dummy links to track the fact that a file is open for |
| 236 // editing and has unsaved changes (e.g. having unsaved changes to |
| 237 // 'foo.dart' causes a link '.#foo.dart' to be created, which points to the |
| 238 // non-existent file 'username@hostname.pid'. To avoid these dummy links |
| 239 // causing the analyzer to thrash, just ignore links to non-existent files. |
| 240 return file.exists; |
| 233 } | 241 } |
| 234 | 242 |
| 235 /** | 243 /** |
| 236 * Called when a new context needs to be created. | 244 * Called when a new context needs to be created. |
| 237 */ | 245 */ |
| 238 void addContext(Folder folder, HashMap<String, List<Folder>> packageMap); | 246 void addContext(Folder folder, HashMap<String, List<Folder>> packageMap); |
| 239 | 247 |
| 240 /** | 248 /** |
| 241 * Called when the set of files associated with a context have changed (or | 249 * Called when the set of files associated with a context have changed (or |
| 242 * some of those files have been modified). [changeSet] is the set of | 250 * some of those files have been modified). [changeSet] is the set of |
| 243 * changes that need to be applied to the context. | 251 * changes that need to be applied to the context. |
| 244 */ | 252 */ |
| 245 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); | 253 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); |
| 246 | 254 |
| 247 /** | 255 /** |
| 248 * Remove the context associated with the given [folder]. | 256 * Remove the context associated with the given [folder]. |
| 249 */ | 257 */ |
| 250 void removeContext(Folder folder); | 258 void removeContext(Folder folder); |
| 251 | 259 |
| 252 /** | 260 /** |
| 253 * Called when the package map for a context has changed. | 261 * Called when the package map for a context has changed. |
| 254 */ | 262 */ |
| 255 void updateContextPackageMap(Folder contextFolder, | 263 void updateContextPackageMap(Folder contextFolder, |
| 256 Map<String, List<Folder>> packageMap); | 264 Map<String, List<Folder>> packageMap); |
| 257 } | 265 } |
| OLD | NEW |