| 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; |
| 11 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 11 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 12 import 'package:analyzer/src/generated/sdk.dart'; | 12 import 'package:analyzer/src/generated/sdk.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; | |
| 14 import 'package:analyzer_plugin/channel/channel.dart'; | 13 import 'package:analyzer_plugin/channel/channel.dart'; |
| 15 import 'package:analyzer_plugin/protocol/protocol.dart'; | 14 import 'package:analyzer_plugin/protocol/protocol.dart'; |
| 16 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 15 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 17 import 'package:analyzer_plugin/protocol/protocol_constants.dart'; | 16 import 'package:analyzer_plugin/protocol/protocol_constants.dart'; |
| 18 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; | 17 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; |
| 19 import 'package:analyzer_plugin/src/protocol/protocol_internal.dart'; | 18 import 'package:analyzer_plugin/src/protocol/protocol_internal.dart'; |
| 20 import 'package:analyzer_plugin/src/utilities/null_string_sink.dart'; | 19 import 'package:analyzer_plugin/src/utilities/null_string_sink.dart'; |
| 21 import 'package:analyzer_plugin/utilities/subscriptions/subscription_manager.dar
t'; | 20 import 'package:analyzer_plugin/utilities/subscriptions/subscription_manager.dar
t'; |
| 22 import 'package:front_end/src/base/performace_logger.dart'; | 21 import 'package:front_end/src/base/performace_logger.dart'; |
| 23 import 'package:front_end/src/incremental/byte_store.dart'; | 22 import 'package:front_end/src/incremental/byte_store.dart'; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 331 |
| 333 /** | 332 /** |
| 334 * Handle an 'analysis.updateContent' request. Most subclasses should not | 333 * Handle an 'analysis.updateContent' request. Most subclasses should not |
| 335 * override this method, but should instead use the [contentCache] to access | 334 * override this method, but should instead use the [contentCache] to access |
| 336 * the current content of overlaid files. | 335 * the current content of overlaid files. |
| 337 */ | 336 */ |
| 338 Future<AnalysisUpdateContentResult> handleAnalysisUpdateContent( | 337 Future<AnalysisUpdateContentResult> handleAnalysisUpdateContent( |
| 339 AnalysisUpdateContentParams parameters) async { | 338 AnalysisUpdateContentParams parameters) async { |
| 340 Map<String, Object> files = parameters.files; | 339 Map<String, Object> files = parameters.files; |
| 341 files.forEach((String filePath, Object overlay) { | 340 files.forEach((String filePath, Object overlay) { |
| 342 // We don't need to get the correct URI because only the full path is | |
| 343 // used by the contentCache. | |
| 344 Source source = resourceProvider.getFile(filePath).createSource(); | |
| 345 if (overlay is AddContentOverlay) { | 341 if (overlay is AddContentOverlay) { |
| 346 fileContentOverlay[source.fullName] = overlay.content; | 342 fileContentOverlay[filePath] = overlay.content; |
| 347 } else if (overlay is ChangeContentOverlay) { | 343 } else if (overlay is ChangeContentOverlay) { |
| 348 String fileName = source.fullName; | 344 String oldContents = fileContentOverlay[filePath]; |
| 349 String oldContents = fileContentOverlay[fileName]; | |
| 350 String newContents; | 345 String newContents; |
| 351 if (oldContents == null) { | 346 if (oldContents == null) { |
| 352 // The server should only send a ChangeContentOverlay if there is | 347 // The server should only send a ChangeContentOverlay if there is |
| 353 // already an existing overlay for the source. | 348 // already an existing overlay for the source. |
| 354 throw new RequestFailure( | 349 throw new RequestFailure( |
| 355 RequestErrorFactory.invalidOverlayChangeNoContent()); | 350 RequestErrorFactory.invalidOverlayChangeNoContent()); |
| 356 } | 351 } |
| 357 try { | 352 try { |
| 358 newContents = SourceEdit.applySequence(oldContents, overlay.edits); | 353 newContents = SourceEdit.applySequence(oldContents, overlay.edits); |
| 359 } on RangeError { | 354 } on RangeError { |
| 360 throw new RequestFailure( | 355 throw new RequestFailure( |
| 361 RequestErrorFactory.invalidOverlayChangeInvalidEdit()); | 356 RequestErrorFactory.invalidOverlayChangeInvalidEdit()); |
| 362 } | 357 } |
| 363 fileContentOverlay[fileName] = newContents; | 358 fileContentOverlay[filePath] = newContents; |
| 364 } else if (overlay is RemoveContentOverlay) { | 359 } else if (overlay is RemoveContentOverlay) { |
| 365 fileContentOverlay[source.fullName] = null; | 360 fileContentOverlay[filePath] = null; |
| 366 } | 361 } |
| 367 contentChanged(filePath); | 362 contentChanged(filePath); |
| 368 }); | 363 }); |
| 369 return new AnalysisUpdateContentResult(); | 364 return new AnalysisUpdateContentResult(); |
| 370 } | 365 } |
| 371 | 366 |
| 372 /** | 367 /** |
| 373 * Handle a 'completion.getSuggestions' request. | 368 * Handle a 'completion.getSuggestions' request. |
| 374 */ | 369 */ |
| 375 Future<CompletionGetSuggestionsResult> handleCompletionGetSuggestions( | 370 Future<CompletionGetSuggestionsResult> handleCompletionGetSuggestions( |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 response = new Response(id, requestTime, | 584 response = new Response(id, requestTime, |
| 590 error: new RequestError( | 585 error: new RequestError( |
| 591 RequestErrorCode.PLUGIN_ERROR, exception.toString(), | 586 RequestErrorCode.PLUGIN_ERROR, exception.toString(), |
| 592 stackTrace: stackTrace.toString())); | 587 stackTrace: stackTrace.toString())); |
| 593 } | 588 } |
| 594 if (response != null) { | 589 if (response != null) { |
| 595 _channel.sendResponse(response); | 590 _channel.sendResponse(response); |
| 596 } | 591 } |
| 597 } | 592 } |
| 598 } | 593 } |
| OLD | NEW |