| 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' hide Resource; | 8 import 'dart:core' hide Resource; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 */ | 111 */ |
| 112 Response getNavigation(Request request) { | 112 Response getNavigation(Request request) { |
| 113 var params = new AnalysisGetNavigationParams.fromRequest(request); | 113 var params = new AnalysisGetNavigationParams.fromRequest(request); |
| 114 String file = params.file; | 114 String file = params.file; |
| 115 Future<AnalysisDoneReason> analysisFuture = | 115 Future<AnalysisDoneReason> analysisFuture = |
| 116 server.onFileAnalysisComplete(file); | 116 server.onFileAnalysisComplete(file); |
| 117 if (analysisFuture == null) { | 117 if (analysisFuture == null) { |
| 118 return new Response.getNavigationInvalidFile(request); | 118 return new Response.getNavigationInvalidFile(request); |
| 119 } | 119 } |
| 120 analysisFuture.then((AnalysisDoneReason reason) { | 120 analysisFuture.then((AnalysisDoneReason reason) { |
| 121 print(' reason: $reason'); | 121 switch (reason) { |
| 122 try { | 122 case AnalysisDoneReason.COMPLETE: |
| 123 switch (reason) { | 123 List<CompilationUnit> units = |
| 124 case AnalysisDoneReason.COMPLETE: | 124 server.getResolvedCompilationUnits(file); |
| 125 print(' AnalysisDoneReason.COMPLETE'); | 125 if (units.isEmpty) { |
| 126 List<CompilationUnit> units = | 126 server.sendResponse(new Response.getNavigationInvalidFile(request)); |
| 127 server.getResolvedCompilationUnits(file); | 127 } else { |
| 128 print(' units: $units'); | 128 DartUnitNavigationComputer computer = |
| 129 if (units.isEmpty) { | 129 new DartUnitNavigationComputer(); |
| 130 server | 130 _GetNavigationAstVisitor visitor = new _GetNavigationAstVisitor( |
| 131 .sendResponse(new Response.getNavigationInvalidFile(request)); | 131 params.offset, params.offset + params.length, computer); |
| 132 } else { | 132 for (CompilationUnit unit in units) { |
| 133 DartUnitNavigationComputer computer = | 133 unit.accept(visitor); |
| 134 new DartUnitNavigationComputer(); | |
| 135 _GetNavigationAstVisitor visitor = new _GetNavigationAstVisitor( | |
| 136 params.offset, params.offset + params.length, computer); | |
| 137 for (CompilationUnit unit in units) { | |
| 138 unit.accept(visitor); | |
| 139 } | |
| 140 server.sendResponse(new AnalysisGetNavigationResult( | |
| 141 computer.files, computer.targets, computer.regions) | |
| 142 .toResponse(request.id)); | |
| 143 } | 134 } |
| 144 break; | 135 server.sendResponse(new AnalysisGetNavigationResult( |
| 145 case AnalysisDoneReason.CONTEXT_REMOVED: | 136 computer.files, computer.targets, computer.regions) |
| 146 print(' AnalysisDoneReason.CONTEXT_REMOVED'); | 137 .toResponse(request.id)); |
| 147 // The active contexts have changed, so try again. | 138 } |
| 148 Response response = getNavigation(request); | 139 break; |
| 149 if (response != Response.DELAYED_RESPONSE) { | 140 case AnalysisDoneReason.CONTEXT_REMOVED: |
| 150 server.sendResponse(response); | 141 // The active contexts have changed, so try again. |
| 151 } | 142 Response response = getNavigation(request); |
| 152 break; | 143 if (response != Response.DELAYED_RESPONSE) { |
| 153 } | 144 server.sendResponse(response); |
| 154 } on Exception catch (e, st) { | 145 } |
| 155 print('Exception1 in AnalysisDomainHandler.getNavigation()'); | 146 break; |
| 156 print(e); | |
| 157 print(st); | |
| 158 } | 147 } |
| 159 }).catchError((e, st) { | |
| 160 print('Exception2 in AnalysisDomainHandler.getNavigation()'); | |
| 161 print(e); | |
| 162 print(st); | |
| 163 }); | 148 }); |
| 164 // delay response | 149 // delay response |
| 165 return Response.DELAYED_RESPONSE; | 150 return Response.DELAYED_RESPONSE; |
| 166 } | 151 } |
| 167 | 152 |
| 168 @override | 153 @override |
| 169 Response handleRequest(Request request) { | 154 Response handleRequest(Request request) { |
| 170 try { | 155 try { |
| 171 String requestName = request.method; | 156 String requestName = request.method; |
| 172 if (requestName == ANALYSIS_GET_ERRORS) { | 157 if (requestName == ANALYSIS_GET_ERRORS) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 return; | 311 return; |
| 327 } | 312 } |
| 328 // The node starts or ends in the range. | 313 // The node starts or ends in the range. |
| 329 if (isInRange(node.offset) || isInRange(node.end)) { | 314 if (isInRange(node.offset) || isInRange(node.end)) { |
| 330 computer.compute(node); | 315 computer.compute(node); |
| 331 return; | 316 return; |
| 332 } | 317 } |
| 333 super.visitNode(node); | 318 super.visitNode(node); |
| 334 } | 319 } |
| 335 } | 320 } |
| OLD | NEW |