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 domain.analysis; | 5 library domain.analysis; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:core'; | 8 import 'dart:core'; |
9 | 9 |
10 import 'package:analysis_server/plugin/analysis/analysis_domain.dart'; | 10 import 'package:analysis_server/plugin/analysis/analysis_domain.dart'; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 return Response.DELAYED_RESPONSE; | 83 return Response.DELAYED_RESPONSE; |
84 } | 84 } |
85 | 85 |
86 /** | 86 /** |
87 * Implement the `analysis.getHover` request. | 87 * Implement the `analysis.getHover` request. |
88 */ | 88 */ |
89 Future<Null> getHover(Request request) async { | 89 Future<Null> getHover(Request request) async { |
90 var params = new AnalysisGetHoverParams.fromRequest(request); | 90 var params = new AnalysisGetHoverParams.fromRequest(request); |
91 | 91 |
92 // Prepare the resolved units. | 92 // Prepare the resolved units. |
93 List<CompilationUnit> units; | 93 CompilationUnit unit; |
94 if (server.options.enableNewAnalysisDriver) { | 94 if (server.options.enableNewAnalysisDriver) { |
95 AnalysisResult result = await server.getAnalysisResult(params.file); | 95 AnalysisResult result = await server.getAnalysisResult(params.file); |
96 units = result != null ? [result.unit] : null; | 96 unit = result?.unit; |
97 } else { | 97 } else { |
98 units = server.getResolvedCompilationUnits(params.file); | 98 unit = server.getResolvedCompilationUnit(params.file); |
99 } | 99 } |
100 | 100 |
101 // Prepare the hovers. | 101 // Prepare the hovers. |
102 List<HoverInformation> hovers = <HoverInformation>[]; | 102 List<HoverInformation> hovers = <HoverInformation>[]; |
103 for (CompilationUnit unit in units) { | 103 if (unit != null) { |
104 HoverInformation hoverInformation = | 104 HoverInformation hoverInformation = |
105 new DartUnitHoverComputer(unit, params.offset).compute(); | 105 new DartUnitHoverComputer(unit, params.offset).compute(); |
106 if (hoverInformation != null) { | 106 if (hoverInformation != null) { |
107 hovers.add(hoverInformation); | 107 hovers.add(hoverInformation); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 // Send the response. | 111 // Send the response. |
112 server.sendResponse( | 112 server.sendResponse( |
113 new AnalysisGetHoverResult(hovers).toResponse(request.id)); | 113 new AnalysisGetHoverResult(hovers).toResponse(request.id)); |
(...skipping 26 matching lines...) Expand all Loading... |
140 var params = new AnalysisGetNavigationParams.fromRequest(request); | 140 var params = new AnalysisGetNavigationParams.fromRequest(request); |
141 String file = params.file; | 141 String file = params.file; |
142 Future<AnalysisDoneReason> analysisFuture = | 142 Future<AnalysisDoneReason> analysisFuture = |
143 server.onFileAnalysisComplete(file); | 143 server.onFileAnalysisComplete(file); |
144 if (analysisFuture == null) { | 144 if (analysisFuture == null) { |
145 return new Response.getNavigationInvalidFile(request); | 145 return new Response.getNavigationInvalidFile(request); |
146 } | 146 } |
147 analysisFuture.then((AnalysisDoneReason reason) { | 147 analysisFuture.then((AnalysisDoneReason reason) { |
148 switch (reason) { | 148 switch (reason) { |
149 case AnalysisDoneReason.COMPLETE: | 149 case AnalysisDoneReason.COMPLETE: |
150 List<CompilationUnit> units = | 150 CompilationUnit unit = server.getResolvedCompilationUnit(file); |
151 server.getResolvedCompilationUnits(file); | 151 if (unit == null) { |
152 if (units.isEmpty) { | |
153 server.sendResponse(new Response.getNavigationInvalidFile(request)); | 152 server.sendResponse(new Response.getNavigationInvalidFile(request)); |
154 } else { | 153 } else { |
155 CompilationUnitElement unitElement = units.first.element; | 154 CompilationUnitElement unitElement = unit.element; |
156 NavigationCollectorImpl collector = computeNavigation( | 155 NavigationCollectorImpl collector = computeNavigation( |
157 server, | 156 server, |
158 unitElement.context, | 157 unitElement.context, |
159 unitElement.source, | 158 unitElement.source, |
160 params.offset, | 159 params.offset, |
161 params.length); | 160 params.length); |
162 server.sendResponse(new AnalysisGetNavigationResult( | 161 server.sendResponse(new AnalysisGetNavigationResult( |
163 collector.files, collector.targets, collector.regions) | 162 collector.files, collector.targets, collector.regions) |
164 .toResponse(request.id)); | 163 .toResponse(request.id)); |
165 } | 164 } |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 context.onResultChanged(descriptor).listen((result) { | 413 context.onResultChanged(descriptor).listen((result) { |
415 StreamController<engine.ResultChangedEvent> controller = | 414 StreamController<engine.ResultChangedEvent> controller = |
416 controllers[result.descriptor]; | 415 controllers[result.descriptor]; |
417 if (controller != null) { | 416 if (controller != null) { |
418 controller.add(result); | 417 controller.add(result); |
419 } | 418 } |
420 }); | 419 }); |
421 } | 420 } |
422 } | 421 } |
423 } | 422 } |
OLD | NEW |