Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/physical_file_system.dart'; | 8 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 9 import 'package:analyzer/src/dart/analysis/driver.dart' | 9 import 'package:analyzer/src/dart/analysis/driver.dart' |
| 10 show AnalysisDriverGeneric, AnalysisDriverScheduler; | 10 show AnalysisDriverGeneric, AnalysisDriverScheduler; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 Future<AnalysisSetContextRootsResult> handleAnalysisSetContextRoots( | 262 Future<AnalysisSetContextRootsResult> handleAnalysisSetContextRoots( |
| 263 AnalysisSetContextRootsParams parameters) async { | 263 AnalysisSetContextRootsParams parameters) async { |
| 264 List<ContextRoot> contextRoots = parameters.roots; | 264 List<ContextRoot> contextRoots = parameters.roots; |
| 265 List<ContextRoot> oldRoots = driverMap.keys.toList(); | 265 List<ContextRoot> oldRoots = driverMap.keys.toList(); |
| 266 for (ContextRoot contextRoot in contextRoots) { | 266 for (ContextRoot contextRoot in contextRoots) { |
| 267 if (!oldRoots.remove(contextRoot)) { | 267 if (!oldRoots.remove(contextRoot)) { |
| 268 // The context is new, so we create a driver for it. Creating the driver | 268 // The context is new, so we create a driver for it. Creating the driver |
| 269 // has the side-effect of adding it to the analysis driver scheduler. | 269 // has the side-effect of adding it to the analysis driver scheduler. |
| 270 AnalysisDriverGeneric driver = createAnalysisDriver(contextRoot); | 270 AnalysisDriverGeneric driver = createAnalysisDriver(contextRoot); |
| 271 driverMap[contextRoot] = driver; | 271 driverMap[contextRoot] = driver; |
| 272 _addFilesToDriver( | |
| 273 driver, | |
| 274 resourceProvider.getResource(contextRoot.root), | |
| 275 contextRoot.exclude); | |
| 272 } | 276 } |
| 273 } | 277 } |
| 274 for (ContextRoot contextRoot in oldRoots) { | 278 for (ContextRoot contextRoot in oldRoots) { |
| 275 // The context has been removed, so we remove its driver. | 279 // The context has been removed, so we remove its driver. |
| 276 AnalysisDriverGeneric driver = driverMap.remove(contextRoot); | 280 AnalysisDriverGeneric driver = driverMap.remove(contextRoot); |
| 277 // The `dispose` method has the side-effect of removing the driver from | 281 // The `dispose` method has the side-effect of removing the driver from |
| 278 // the analysis driver scheduler. | 282 // the analysis driver scheduler. |
| 279 driver.dispose(); | 283 driver.dispose(); |
| 280 } | 284 } |
| 281 return new AnalysisSetContextRootsResult(); | 285 return new AnalysisSetContextRootsResult(); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 | 456 |
| 453 /** | 457 /** |
| 454 * Start this plugin by listening to the given communication [channel]. | 458 * Start this plugin by listening to the given communication [channel]. |
| 455 */ | 459 */ |
| 456 void start(PluginCommunicationChannel channel) { | 460 void start(PluginCommunicationChannel channel) { |
| 457 _channel = channel; | 461 _channel = channel; |
| 458 _channel.listen(_onRequest, onError: onError, onDone: onDone); | 462 _channel.listen(_onRequest, onError: onError, onDone: onDone); |
| 459 } | 463 } |
| 460 | 464 |
| 461 /** | 465 /** |
| 466 * Add all of the files contained in the given [resource] that are not in the | |
| 467 * list of [excluded] resources to the given [driver]. | |
| 468 */ | |
| 469 void _addFilesToDriver( | |
| 470 AnalysisDriverGeneric driver, Resource resource, List<String> excluded) { | |
| 471 String path = resource.path; | |
| 472 if (excluded.contains(path) || !resource.exists) { | |
|
scheglov
2017/05/18 01:20:40
It does not guarantee anything that the resource e
Brian Wilkerson
2017/05/18 14:43:36
I removed the existence check.
| |
| 473 return; | |
| 474 } | |
| 475 if (resource is File) { | |
| 476 driver.addFile(path); | |
| 477 } else if (resource is Folder) { | |
| 478 for (Resource child in resource.getChildren()) { | |
|
scheglov
2017/05/18 01:20:40
getChildren() should be wrapped with try/catch in
Brian Wilkerson
2017/05/18 14:43:36
Done
| |
| 479 _addFilesToDriver(driver, child, excluded); | |
| 480 } | |
| 481 } | |
| 482 } | |
| 483 | |
| 484 /** | |
| 462 * Compute the response that should be returned for the given [request], or | 485 * Compute the response that should be returned for the given [request], or |
| 463 * `null` if the response has already been sent. | 486 * `null` if the response has already been sent. |
| 464 */ | 487 */ |
| 465 Future<Response> _getResponse(Request request) async { | 488 Future<Response> _getResponse(Request request) async { |
| 466 ResponseResult result = null; | 489 ResponseResult result = null; |
| 467 switch (request.method) { | 490 switch (request.method) { |
| 468 case ANALYSIS_REQUEST_HANDLE_WATCH_EVENTS: | 491 case ANALYSIS_REQUEST_HANDLE_WATCH_EVENTS: |
| 469 var params = new AnalysisHandleWatchEventsParams.fromRequest(request); | 492 var params = new AnalysisHandleWatchEventsParams.fromRequest(request); |
| 470 result = await handleAnalysisHandleWatchEvents(params); | 493 result = await handleAnalysisHandleWatchEvents(params); |
| 471 break; | 494 break; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 response = new Response(id, | 571 response = new Response(id, |
| 549 error: new RequestError( | 572 error: new RequestError( |
| 550 RequestErrorCode.PLUGIN_ERROR, exception.toString(), | 573 RequestErrorCode.PLUGIN_ERROR, exception.toString(), |
| 551 stackTrace: stackTrace.toString())); | 574 stackTrace: stackTrace.toString())); |
| 552 } | 575 } |
| 553 if (response != null) { | 576 if (response != null) { |
| 554 _channel.sendResponse(response); | 577 _channel.sendResponse(response); |
| 555 } | 578 } |
| 556 } | 579 } |
| 557 } | 580 } |
| OLD | NEW |