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 'package:analysis_server/protocol/protocol_generated.dart' as server; | 5 import 'package:analysis_server/protocol/protocol_generated.dart' as server; |
6 import 'package:analysis_server/src/protocol/protocol_internal.dart' as server; | 6 import 'package:analysis_server/src/protocol/protocol_internal.dart' as server; |
7 import 'package:analyzer_plugin/protocol/protocol_common.dart' as plugin; | |
8 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; | 7 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; |
9 | 8 |
10 /** | 9 /** |
11 * An object used to convert between similar objects defined by both the plugin | 10 * An object used to convert between similar objects defined by both the plugin |
12 * protocol and the server protocol. | 11 * protocol and the server protocol. |
13 */ | 12 */ |
14 class RequestConverter { | 13 class RequestConverter { |
15 plugin.AnalysisReanalyzeParams convertAnalysisReanalyzeParams( | 14 plugin.AnalysisReanalyzeParams convertAnalysisReanalyzeParams( |
16 server.AnalysisReanalyzeParams params) { | 15 server.AnalysisReanalyzeParams params) { |
17 return new plugin.AnalysisReanalyzeParams(roots: params.roots); | 16 return new plugin.AnalysisReanalyzeParams(roots: params.roots); |
(...skipping 25 matching lines...) Expand all Loading... |
43 } | 42 } |
44 } | 43 } |
45 return new plugin.AnalysisSetSubscriptionsParams(pluginSubscriptions); | 44 return new plugin.AnalysisSetSubscriptionsParams(pluginSubscriptions); |
46 } | 45 } |
47 | 46 |
48 plugin.AnalysisUpdateContentParams convertAnalysisUpdateContentParams( | 47 plugin.AnalysisUpdateContentParams convertAnalysisUpdateContentParams( |
49 server.AnalysisUpdateContentParams params) { | 48 server.AnalysisUpdateContentParams params) { |
50 Map<String, dynamic> serverOverlays = params.files; | 49 Map<String, dynamic> serverOverlays = params.files; |
51 Map<String, dynamic> pluginOverlays = <String, dynamic>{}; | 50 Map<String, dynamic> pluginOverlays = <String, dynamic>{}; |
52 for (String file in serverOverlays.keys) { | 51 for (String file in serverOverlays.keys) { |
53 pluginOverlays[file] = convertFileOverlay(serverOverlays[file]); | 52 pluginOverlays[file] = serverOverlays[file]; |
54 } | 53 } |
55 return new plugin.AnalysisUpdateContentParams(pluginOverlays); | 54 return new plugin.AnalysisUpdateContentParams(pluginOverlays); |
56 } | 55 } |
57 | |
58 Object convertFileOverlay(Object overlay) { | |
59 if (overlay is server.AddContentOverlay) { | |
60 return new plugin.AddContentOverlay(overlay.content); | |
61 } else if (overlay is server.ChangeContentOverlay) { | |
62 return new plugin.ChangeContentOverlay( | |
63 overlay.edits.map(convertSourceEdit).toList()); | |
64 } else if (overlay is server.RemoveContentOverlay) { | |
65 return new plugin.RemoveContentOverlay(); | |
66 } | |
67 return null; | |
68 } | |
69 | |
70 plugin.SourceEdit convertSourceEdit(server.SourceEdit edit) { | |
71 return new plugin.SourceEdit(edit.offset, edit.length, edit.replacement); | |
72 } | |
73 } | 56 } |
OLD | NEW |