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 switch (reason) { | 121 print(' reason: $reason'); |
122 case AnalysisDoneReason.COMPLETE: | 122 try { |
123 print('AnalysisDoneReason.COMPLETE'); | 123 switch (reason) { |
124 List<CompilationUnit> units = | 124 case AnalysisDoneReason.COMPLETE: |
125 server.getResolvedCompilationUnits(file); | 125 print(' AnalysisDoneReason.COMPLETE'); |
126 print('units: $units'); | 126 List<CompilationUnit> units = |
127 if (units.isEmpty) { | 127 server.getResolvedCompilationUnits(file); |
128 server.sendResponse(new Response.getNavigationInvalidFile(request)); | 128 print(' units: $units'); |
129 } else { | 129 if (units.isEmpty) { |
130 DartUnitNavigationComputer computer = | 130 server |
131 new DartUnitNavigationComputer(); | 131 .sendResponse(new Response.getNavigationInvalidFile(request)); |
132 _GetNavigationAstVisitor visitor = new _GetNavigationAstVisitor( | 132 } else { |
133 params.offset, params.offset + params.length, computer); | 133 DartUnitNavigationComputer computer = |
134 for (CompilationUnit unit in units) { | 134 new DartUnitNavigationComputer(); |
135 unit.accept(visitor); | 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)); |
136 } | 143 } |
137 server.sendResponse(new AnalysisGetNavigationResult( | 144 break; |
138 computer.files, computer.targets, computer.regions) | 145 case AnalysisDoneReason.CONTEXT_REMOVED: |
139 .toResponse(request.id)); | 146 print(' AnalysisDoneReason.CONTEXT_REMOVED'); |
140 } | 147 // The active contexts have changed, so try again. |
141 break; | 148 Response response = getNavigation(request); |
142 case AnalysisDoneReason.CONTEXT_REMOVED: | 149 if (response != Response.DELAYED_RESPONSE) { |
143 print('AnalysisDoneReason.CONTEXT_REMOVED'); | 150 server.sendResponse(response); |
144 // The active contexts have changed, so try again. | 151 } |
145 Response response = getNavigation(request); | 152 break; |
146 if (response != Response.DELAYED_RESPONSE) { | 153 } |
147 server.sendResponse(response); | 154 } on Exception catch (e, st) { |
148 } | 155 print('Exception1 in AnalysisDomainHandler.getNavigation()'); |
149 break; | 156 print(e); |
| 157 print(st); |
150 } | 158 } |
151 }).catchError((e, st) { | 159 }).catchError((e, st) { |
152 print('Exception in AnalysisDomainHandler.getNavigation()'); | 160 print('Exception2 in AnalysisDomainHandler.getNavigation()'); |
153 print(e); | 161 print(e); |
154 print(st); | 162 print(st); |
155 }); | 163 }); |
156 // delay response | 164 // delay response |
157 return Response.DELAYED_RESPONSE; | 165 return Response.DELAYED_RESPONSE; |
158 } | 166 } |
159 | 167 |
160 @override | 168 @override |
161 Response handleRequest(Request request) { | 169 Response handleRequest(Request request) { |
162 try { | 170 try { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 return; | 326 return; |
319 } | 327 } |
320 // The node starts or ends in the range. | 328 // The node starts or ends in the range. |
321 if (isInRange(node.offset) || isInRange(node.end)) { | 329 if (isInRange(node.offset) || isInRange(node.end)) { |
322 computer.compute(node); | 330 computer.compute(node); |
323 return; | 331 return; |
324 } | 332 } |
325 super.visitNode(node); | 333 super.visitNode(node); |
326 } | 334 } |
327 } | 335 } |
OLD | NEW |