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

Unified Diff: pkg/analysis_server/lib/src/context_directory_manager.dart

Issue 340773005: Add support for adding/removing pubspec.yaml files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/resource.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/context_directory_manager.dart
diff --git a/pkg/analysis_server/lib/src/context_directory_manager.dart b/pkg/analysis_server/lib/src/context_directory_manager.dart
index 960cd9aece23bdf24676151a7eed8e18bcdf8296..dca28bfcc909c3d80b4bde8b9de91302a74c2210 100644
--- a/pkg/analysis_server/lib/src/context_directory_manager.dart
+++ b/pkg/analysis_server/lib/src/context_directory_manager.dart
@@ -27,6 +27,17 @@ class _ContextDirectoryInfo {
* added to the context.
*/
Map<String, Source> sources = new HashMap<String, Source>();
+
+ /**
+ * Pubspec file for this context, if there is one. Otherwise null.
+ */
+ File pubspecFile = null;
scheglov 2014/06/18 18:32:04 Do we need "= null"?
Paul Berry 2014/06/19 14:55:15 Technically, it's redundant, since uninitialized v
+
+ /**
+ * Path to that the pubspec file for this context would have, if it has one.
+ * Otherwise path that the pubspec file would have.
+ */
+ String pubspecPath;
}
/**
@@ -35,6 +46,11 @@ class _ContextDirectoryInfo {
*/
abstract class ContextDirectoryManager {
/**
+ * File name of pubspec files.
+ */
+ static String PUBSPEC_NAME = 'pubspec.yaml';
scheglov 2014/06/18 18:32:04 static const?
Paul Berry 2014/06/19 14:55:15 Done.
+
+ /**
* [_ContextDirectoryInfo] object for each included directory in the most
* recent successful call to [setRoots].
*/
@@ -81,22 +97,41 @@ abstract class ContextDirectoryManager {
Set<Folder> oldFolders = currentFolders.difference(includedFolders);
// remove old contexts
scheglov 2014/06/18 18:32:04 "destroy old contexts" ?
Paul Berry 2014/06/19 14:55:15 Done.
for (Folder folder in oldFolders) {
- _currentDirectoryInfo.remove(folder);
- removeContext(folder);
+ _destroyContext(folder);
}
// add new contexts
scheglov 2014/06/18 18:32:04 "create new contexts"?
Paul Berry 2014/06/19 14:55:15 Done.
for (Folder folder in newFolders) {
- _ContextDirectoryInfo info = new _ContextDirectoryInfo();
- _currentDirectoryInfo[folder] = info;
- info.changeSubscription = folder.changes.listen((WatchEvent event) {
- _handleWatchEvent(folder, info, event);
- });
- File pubspecFile = folder.getChild('pubspec.yaml');
- addContext(folder, pubspecFile.exists ? pubspecFile : null);
- ChangeSet changeSet = new ChangeSet();
- _addSourceFiles(changeSet, folder, info);
- applyChangesToContext(folder, changeSet);
+ _createContext(folder);
+ }
+ }
+
+ /**
+ * Create a new context associated with the given folder.
+ */
+ void _createContext(Folder folder) {
+ _ContextDirectoryInfo info = new _ContextDirectoryInfo();
+ _currentDirectoryInfo[folder] = info;
+ info.changeSubscription = folder.changes.listen((WatchEvent event) {
+ _handleWatchEvent(folder, info, event);
+ });
+ File pubspecFile = folder.getChild(PUBSPEC_NAME);
+ info.pubspecPath = pubspecFile.path;
+ if (pubspecFile.exists) {
+ info.pubspecFile = pubspecFile;
}
+ addContext(folder, info.pubspecFile);
+ ChangeSet changeSet = new ChangeSet();
+ _addSourceFiles(changeSet, folder, info);
+ applyChangesToContext(folder, changeSet);
+ }
+
+ /**
+ * Clean up and destroy the context associated with the given folder.
+ */
+ void _destroyContext(Folder folder) {
+ _currentDirectoryInfo[folder].changeSubscription.cancel();
+ _currentDirectoryInfo.remove(folder);
+ removeContext(folder);
}
void _handleWatchEvent(Folder folder, _ContextDirectoryInfo info, WatchEvent event) {
@@ -107,7 +142,14 @@ abstract class ContextDirectoryManager {
// there is a pubspec.yaml?
break;
}
- // TODO(paulberry): handle adding pubspec.yaml
+ if (info.pubspecFile == null && event.path == info.pubspecPath) {
+ // Pubspec file added. This is likely to be such a rare event that
+ // there's no need to try to be clever. Just destroy the old context
+ // and create a new one.
+ _destroyContext(folder);
+ _createContext(folder);
+ return;
+ }
if (_shouldFileBeAnalyzed(event.path)) {
ChangeSet changeSet = new ChangeSet();
Resource resource = resourceProvider.getResource(event.path);
@@ -124,6 +166,14 @@ abstract class ContextDirectoryManager {
}
break;
case ChangeType.REMOVE:
+ if (info.pubspecFile != null && event.path == info.pubspecPath) {
+ // Pubspec file removed. This is likely to be such a rare event that
+ // there's no need to try to be clever. Just destroy the old context
+ // and create a new one.
+ _destroyContext(folder);
+ _createContext(folder);
+ return;
+ }
// TODO(paulberry): handle removing pubspec.yaml
Source source = info.sources[event.path];
if (source != null) {
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/resource.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698