| OLD | NEW |
| 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 analysis.server; | 5 library analysis.server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 } on UnimplementedError catch (e) { | 490 } on UnimplementedError catch (e) { |
| 491 throw new RequestFailure( | 491 throw new RequestFailure( |
| 492 new Response.unsupportedFeature( | 492 new Response.unsupportedFeature( |
| 493 requestId, e.message)); | 493 requestId, e.message)); |
| 494 } | 494 } |
| 495 } | 495 } |
| 496 | 496 |
| 497 /** | 497 /** |
| 498 * Implementation for `analysis.updateContent`. | 498 * Implementation for `analysis.updateContent`. |
| 499 */ | 499 */ |
| 500 void updateContent(Map<String, dynamic> changes) { | 500 void updateContent(String id, Map<String, dynamic> changes) { |
| 501 changes.forEach((file, change) { | 501 changes.forEach((file, change) { |
| 502 AnalysisContext analysisContext = getAnalysisContext(file); | 502 AnalysisContext analysisContext = getAnalysisContext(file); |
| 503 // TODO(paulberry): handle the case where a file is referred to by more | 503 // TODO(paulberry): handle the case where a file is referred to by more |
| 504 // than one context (e.g package A depends on package B using a local | 504 // than one context (e.g package A depends on package B using a local |
| 505 // path, user has both packages open for editing in separate contexts, | 505 // path, user has both packages open for editing in separate contexts, |
| 506 // and user modifies a file in package B). | 506 // and user modifies a file in package B). |
| 507 if (analysisContext != null) { | 507 if (analysisContext != null) { |
| 508 Source source = getSource(file); | 508 Source source = getSource(file); |
| 509 if (change is AddContentOverlay) { | 509 if (change is AddContentOverlay) { |
| 510 analysisContext.setContents(source, change.content); | 510 analysisContext.setContents(source, change.content); |
| 511 } else if (change is ChangeContentOverlay) { | 511 } else if (change is ChangeContentOverlay) { |
| 512 // TODO(paulberry): an error should be generated if source is not | 512 // TODO(paulberry): an error should be generated if source is not |
| 513 // currently in the content cache. | 513 // currently in the content cache. |
| 514 TimestampedData<String> oldContents = analysisContext.getContents( | 514 TimestampedData<String> oldContents = analysisContext.getContents( |
| 515 source); | 515 source); |
| 516 String newContents = SourceEdit.applySequence(oldContents.data, change
.edits); | 516 String newContents; |
| 517 try { |
| 518 newContents = SourceEdit.applySequence(oldContents.data, |
| 519 change.edits); |
| 520 } on RangeError { |
| 521 throw new RequestFailure(new Response(id, error: new RequestError( |
| 522 RequestErrorCode.INVALID_OVERLAY_CHANGE, |
| 523 'Invalid overlay change'))); |
| 524 } |
| 517 // TODO(paulberry): to aid in incremental processing it would be | 525 // TODO(paulberry): to aid in incremental processing it would be |
| 518 // better to use setChangedContents. | 526 // better to use setChangedContents. |
| 519 analysisContext.setContents(source, newContents); | 527 analysisContext.setContents(source, newContents); |
| 520 } else if (change is RemoveContentOverlay) { | 528 } else if (change is RemoveContentOverlay) { |
| 521 analysisContext.setContents(source, null); | 529 analysisContext.setContents(source, null); |
| 522 } else { | 530 } else { |
| 523 // Protocol parsing should have ensured that we never get here. | 531 // Protocol parsing should have ensured that we never get here. |
| 524 throw new AnalysisException('Illegal change type'); | 532 throw new AnalysisException('Illegal change type'); |
| 525 } | 533 } |
| 526 schedulePerformAnalysisOperation(analysisContext); | 534 schedulePerformAnalysisOperation(analysisContext); |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 stackTraceString = 'null stackTrace'; | 857 stackTraceString = 'null stackTrace'; |
| 850 } | 858 } |
| 851 // send the notification | 859 // send the notification |
| 852 channel.sendNotification(new ServerErrorParams(true, exceptionString, | 860 channel.sendNotification(new ServerErrorParams(true, exceptionString, |
| 853 stackTraceString).toNotification()); | 861 stackTraceString).toNotification()); |
| 854 } | 862 } |
| 855 } | 863 } |
| 856 | 864 |
| 857 | 865 |
| 858 typedef void OptionUpdater(AnalysisOptionsImpl options); | 866 typedef void OptionUpdater(AnalysisOptionsImpl options); |
| OLD | NEW |