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

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

Issue 455863003: Fixes for adding/removing pubspecs to/from roots. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analysis_server/test/context_manager_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9
10 import 'package:analysis_server/src/package_map_provider.dart'; 10 import 'package:analysis_server/src/package_map_provider.dart';
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 256 }
257 // handle the change 257 // handle the change
258 switch (event.type) { 258 switch (event.type) {
259 case ChangeType.ADD: 259 case ChangeType.ADD:
260 if (_isInPackagesDir(path, folder)) { 260 if (_isInPackagesDir(path, folder)) {
261 // TODO(paulberry): perhaps we should only skip packages dirs if 261 // TODO(paulberry): perhaps we should only skip packages dirs if
262 // there is a pubspec.yaml? 262 // there is a pubspec.yaml?
263 break; 263 break;
264 } 264 }
265 Resource resource = resourceProvider.getResource(path); 265 Resource resource = resourceProvider.getResource(path);
266 // pubspec was added, extract a new context 266 // pubspec was added in a sub-folder, extract a new context
267 if (_isPubspec(path)) { 267 if (_isPubspec(path) && info.isRoot && !info.isPubspec(path)) {
268 _extractContext(info, resource); 268 _extractContext(info, resource);
269 return; 269 return;
270 } 270 }
271 // If the file went away and was replaced by a folder before we 271 // If the file went away and was replaced by a folder before we
272 // had a chance to process the event, resource might be a Folder. In 272 // had a chance to process the event, resource might be a Folder. In
273 // that case don't add it. 273 // that case don't add it.
274 if (resource is File) { 274 if (resource is File) {
275 File file = resource; 275 File file = resource;
276 if (_shouldFileBeAnalyzed(file)) { 276 if (_shouldFileBeAnalyzed(file)) {
277 ChangeSet changeSet = new ChangeSet(); 277 ChangeSet changeSet = new ChangeSet();
278 Source source = file.createSource(); 278 Source source = file.createSource();
279 changeSet.addedSource(source); 279 changeSet.addedSource(source);
280 applyChangesToContext(folder, changeSet); 280 applyChangesToContext(folder, changeSet);
281 info.sources[path] = source; 281 info.sources[path] = source;
282 } 282 }
283 } 283 }
284 break; 284 break;
285 case ChangeType.REMOVE: 285 case ChangeType.REMOVE:
286 // pubspec was removed, merge the context into its parent 286 // pubspec was removed, merge the context into its parent
287 if (info.isPubspec(path)) { 287 if (info.isPubspec(path) && !info.isRoot) {
288 _mergeContext(info); 288 _mergeContext(info);
289 return; 289 return;
290 } 290 }
291 Source source = info.sources[path]; 291 Source source = info.sources[path];
292 if (source != null) { 292 if (source != null) {
293 ChangeSet changeSet = new ChangeSet(); 293 ChangeSet changeSet = new ChangeSet();
294 changeSet.removedSource(source); 294 changeSet.removedSource(source);
295 applyChangesToContext(folder, changeSet); 295 applyChangesToContext(folder, changeSet);
296 info.sources.remove(path); 296 info.sources.remove(path);
297 } 297 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 Set<String> packageMapDependencies; 443 Set<String> packageMapDependencies;
444 444
445 _ContextInfo(this.folder, this.children) { 445 _ContextInfo(this.folder, this.children) {
446 pubspecPath = folder.getChild(PUBSPEC_NAME).path; 446 pubspecPath = folder.getChild(PUBSPEC_NAME).path;
447 for (_ContextInfo child in children) { 447 for (_ContextInfo child in children) {
448 child.parent = this; 448 child.parent = this;
449 } 449 }
450 } 450 }
451 451
452 /** 452 /**
453 * Returns `true` if this context is root folder based.
454 */
455 bool get isRoot => parent == null;
456
457 /**
453 * Returns `true` if [path] is excluded, as it is in one of the children. 458 * Returns `true` if [path] is excluded, as it is in one of the children.
454 */ 459 */
455 bool excludes(String path) { 460 bool excludes(String path) {
456 return children.any((child) { 461 return children.any((child) {
457 return child.folder.contains(path); 462 return child.folder.contains(path);
458 }); 463 });
459 } 464 }
460 465
461 /** 466 /**
462 * Returns `true` if [resource] is excldued, as it is in one of the children. 467 * Returns `true` if [resource] is excldued, as it is in one of the children.
463 */ 468 */
464 bool excludesResource(Resource resource) { 469 bool excludesResource(Resource resource) {
465 return excludes(resource.path); 470 return excludes(resource.path);
466 } 471 }
467 472
468 /** 473 /**
469 * Returns `true` if [path] is the pubspec file of this context. 474 * Returns `true` if [path] is the pubspec file of this context.
470 */ 475 */
471 bool isPubspec(String path) { 476 bool isPubspec(String path) {
472 return path == pubspecPath; 477 return path == pubspecPath;
473 } 478 }
474 } 479 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/context_manager_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698