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

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

Issue 2842013003: Add support for watch events and error notifications (Closed)
Patch Set: fix comment Created 3 years, 8 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
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 import 'dart:convert'; 9 import 'dart:convert';
10 import 'dart:core'; 10 import 'dart:core';
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 * changes that need to be applied to the context. 379 * changes that need to be applied to the context.
380 */ 380 */
381 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); 381 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet);
382 382
383 /** 383 /**
384 * The given [file] was removed from the folder analyzed in the [driver]. 384 * The given [file] was removed from the folder analyzed in the [driver].
385 */ 385 */
386 void applyFileRemoved(AnalysisDriver driver, String file); 386 void applyFileRemoved(AnalysisDriver driver, String file);
387 387
388 /** 388 /**
389 * Sent the given watch [event] to any interested plugins.
390 */
391 void broadcastWatchEvent(WatchEvent event);
392
393 /**
389 * Signals that the context manager has started to compute a package map (if 394 * Signals that the context manager has started to compute a package map (if
390 * [computing] is `true`) or has finished (if [computing] is `false`). 395 * [computing] is `true`) or has finished (if [computing] is `false`).
391 */ 396 */
392 void computingPackageMap(bool computing); 397 void computingPackageMap(bool computing);
393 398
394 /** 399 /**
395 * Create and return a context builder that can be used to create a context 400 * Create and return a context builder that can be used to create a context
396 * for the files in the given [folder] when analyzed using the given [options] . 401 * for the files in the given [folder] when analyzed using the given [options] .
397 */ 402 */
398 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options); 403 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options);
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 } 1393 }
1389 return rootInfo; 1394 return rootInfo;
1390 } 1395 }
1391 1396
1392 void _handleWatchEvent(WatchEvent event) { 1397 void _handleWatchEvent(WatchEvent event) {
1393 // Figure out which context this event applies to. 1398 // Figure out which context this event applies to.
1394 // TODO(brianwilkerson) If a file is explicitly included in one context 1399 // TODO(brianwilkerson) If a file is explicitly included in one context
1395 // but implicitly referenced in another context, we will only send a 1400 // but implicitly referenced in another context, we will only send a
1396 // changeSet to the context that explicitly includes the file (because 1401 // changeSet to the context that explicitly includes the file (because
1397 // that's the only context that's watching the file). 1402 // that's the only context that's watching the file).
1398 ContextInfo info = _getInnermostContextInfoFor(event.path); 1403 callbacks.broadcastWatchEvent(event);
1404 String path = event.path;
1405 ChangeType type = event.type;
1406 ContextInfo info = _getInnermostContextInfoFor(path);
1399 if (info == null) { 1407 if (info == null) {
1400 // This event doesn't apply to any context. This could happen due to a 1408 // This event doesn't apply to any context. This could happen due to a
1401 // race condition (e.g. a context was removed while one of its events was 1409 // race condition (e.g. a context was removed while one of its events was
1402 // in the event loop). The event is inapplicable now, so just ignore it. 1410 // in the event loop). The event is inapplicable now, so just ignore it.
1403 return; 1411 return;
1404 } 1412 }
1405 _instrumentationService.logWatchEvent( 1413 _instrumentationService.logWatchEvent(
1406 info.folder.path, event.path, event.type.toString()); 1414 info.folder.path, path, type.toString());
1407 String path = event.path;
1408 // First handle changes that affect folderDisposition (since these need to 1415 // First handle changes that affect folderDisposition (since these need to
1409 // be processed regardless of whether they are part of an excluded/ignored 1416 // be processed regardless of whether they are part of an excluded/ignored
1410 // path). 1417 // path).
1411 if (info.hasDependency(path)) { 1418 if (info.hasDependency(path)) {
1412 _recomputeFolderDisposition(info); 1419 _recomputeFolderDisposition(info);
1413 } 1420 }
1414 // maybe excluded globally 1421 // maybe excluded globally
1415 if (_isExcluded(path) || 1422 if (_isExcluded(path) ||
1416 _isContainedInDotFolder(info.folder.path, path) || 1423 _isContainedInDotFolder(info.folder.path, path) ||
1417 _isInPackagesDir(info.folder.path, path) || 1424 _isInPackagesDir(info.folder.path, path) ||
1418 _isInTopLevelDocDir(info.folder.path, path)) { 1425 _isInTopLevelDocDir(info.folder.path, path)) {
1419 return; 1426 return;
1420 } 1427 }
1421 // maybe excluded from the context, so other context will handle it 1428 // maybe excluded from the context, so other context will handle it
1422 if (info.excludes(path)) { 1429 if (info.excludes(path)) {
1423 return; 1430 return;
1424 } 1431 }
1425 if (info.ignored(path)) { 1432 if (info.ignored(path)) {
1426 return; 1433 return;
1427 } 1434 }
1428 // handle the change 1435 // handle the change
1429 switch (event.type) { 1436 switch (type) {
1430 case ChangeType.ADD: 1437 case ChangeType.ADD:
1431 Resource resource = resourceProvider.getResource(path); 1438 Resource resource = resourceProvider.getResource(path);
1432 1439
1433 String directoryPath = absolutePathContext.dirname(path); 1440 String directoryPath = absolutePathContext.dirname(path);
1434 1441
1435 // Check to see if we need to create a new context. 1442 // Check to see if we need to create a new context.
1436 if (info.isTopLevel) { 1443 if (info.isTopLevel) {
1437 // Only create a new context if this is not the same directory 1444 // Only create a new context if this is not the same directory
1438 // described by our info object. 1445 // described by our info object.
1439 if (info.folder.path != directoryPath) { 1446 if (info.folder.path != directoryPath) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 ChangeSet changeSet = new ChangeSet(); 1543 ChangeSet changeSet = new ChangeSet();
1537 sources.forEach((Source source) { 1544 sources.forEach((Source source) {
1538 changeSet.changedSource(source); 1545 changeSet.changedSource(source);
1539 }); 1546 });
1540 callbacks.applyChangesToContext(info.folder, changeSet); 1547 callbacks.applyChangesToContext(info.folder, changeSet);
1541 } 1548 }
1542 } 1549 }
1543 break; 1550 break;
1544 } 1551 }
1545 _checkForPackagespecUpdate(path, info, info.folder); 1552 _checkForPackagespecUpdate(path, info, info.folder);
1546 _checkForAnalysisOptionsUpdate(path, info, event.type); 1553 _checkForAnalysisOptionsUpdate(path, info, type);
1547 } 1554 }
1548 1555
1549 /** 1556 /**
1550 * Determine whether the given [path], when interpreted relative to the 1557 * Determine whether the given [path], when interpreted relative to the
1551 * context root [root], contains a folder whose name starts with '.'. 1558 * context root [root], contains a folder whose name starts with '.'.
1552 */ 1559 */
1553 bool _isContainedInDotFolder(String root, String path) { 1560 bool _isContainedInDotFolder(String root, String path) {
1554 String pathDir = absolutePathContext.dirname(path); 1561 String pathDir = absolutePathContext.dirname(path);
1555 String suffixPath = absolutePathContext.suffix(root, pathDir); 1562 String suffixPath = absolutePathContext.suffix(root, pathDir);
1556 if (suffixPath == null) { 1563 if (suffixPath == null) {
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 } 1974 }
1968 return _embedderLocator; 1975 return _embedderLocator;
1969 } 1976 }
1970 1977
1971 @override 1978 @override
1972 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { 1979 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) {
1973 return _sdkExtensionFinder ??= 1980 return _sdkExtensionFinder ??=
1974 new SdkExtensionFinder(buildPackageMap(resourceProvider)); 1981 new SdkExtensionFinder(buildPackageMap(resourceProvider));
1975 } 1982 }
1976 } 1983 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698