| 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'; |
| 11 import 'package:analysis_server/src/computer/computer_hover.dart'; | 11 import 'package:analysis_server/src/computer/computer_hover.dart'; |
| 12 import 'package:analysis_server/src/computer/computer_navigation.dart'; | |
| 13 import 'package:analysis_server/src/constants.dart'; | 12 import 'package:analysis_server/src/constants.dart'; |
| 13 import 'package:analysis_server/src/domains/analysis/navigation.dart'; |
| 14 import 'package:analysis_server/src/protocol_server.dart'; | 14 import 'package:analysis_server/src/protocol_server.dart'; |
| 15 import 'package:analysis_server/src/services/dependencies/library_dependencies.d
art'; | 15 import 'package:analysis_server/src/services/dependencies/library_dependencies.d
art'; |
| 16 import 'package:analyzer/file_system/file_system.dart'; | 16 import 'package:analyzer/file_system/file_system.dart'; |
| 17 import 'package:analyzer/src/generated/ast.dart'; | 17 import 'package:analyzer/src/generated/ast.dart'; |
| 18 import 'package:analyzer/src/generated/element.dart'; |
| 18 import 'package:analyzer/src/generated/engine.dart' as engine; | 19 import 'package:analyzer/src/generated/engine.dart' as engine; |
| 19 | 20 |
| 20 /** | 21 /** |
| 21 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] | 22 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] |
| 22 * that handles requests in the `analysis` domain. | 23 * that handles requests in the `analysis` domain. |
| 23 */ | 24 */ |
| 24 class AnalysisDomainHandler implements RequestHandler { | 25 class AnalysisDomainHandler implements RequestHandler { |
| 25 /** | 26 /** |
| 26 * The analysis server that is using this handler to process requests. | 27 * The analysis server that is using this handler to process requests. |
| 27 */ | 28 */ |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 return new Response.getNavigationInvalidFile(request); | 119 return new Response.getNavigationInvalidFile(request); |
| 119 } | 120 } |
| 120 analysisFuture.then((AnalysisDoneReason reason) { | 121 analysisFuture.then((AnalysisDoneReason reason) { |
| 121 switch (reason) { | 122 switch (reason) { |
| 122 case AnalysisDoneReason.COMPLETE: | 123 case AnalysisDoneReason.COMPLETE: |
| 123 List<CompilationUnit> units = | 124 List<CompilationUnit> units = |
| 124 server.getResolvedCompilationUnits(file); | 125 server.getResolvedCompilationUnits(file); |
| 125 if (units.isEmpty) { | 126 if (units.isEmpty) { |
| 126 server.sendResponse(new Response.getNavigationInvalidFile(request)); | 127 server.sendResponse(new Response.getNavigationInvalidFile(request)); |
| 127 } else { | 128 } else { |
| 128 DartUnitNavigationComputer computer = | 129 CompilationUnitElement unitElement = units.first.element; |
| 129 new DartUnitNavigationComputer(); | 130 NavigationHolderImpl holder = computeNavigation( |
| 130 _GetNavigationAstVisitor visitor = new _GetNavigationAstVisitor( | 131 server, |
| 131 params.offset, params.offset + params.length, computer); | 132 unitElement.context, |
| 132 for (CompilationUnit unit in units) { | 133 unitElement.source, |
| 133 unit.accept(visitor); | 134 params.offset, |
| 134 } | 135 params.length); |
| 135 server.sendResponse(new AnalysisGetNavigationResult( | 136 server.sendResponse(new AnalysisGetNavigationResult( |
| 136 computer.files, computer.targets, computer.regions) | 137 holder.files, holder.targets, holder.regions) |
| 137 .toResponse(request.id)); | 138 .toResponse(request.id)); |
| 138 } | 139 } |
| 139 break; | 140 break; |
| 140 case AnalysisDoneReason.CONTEXT_REMOVED: | 141 case AnalysisDoneReason.CONTEXT_REMOVED: |
| 141 // The active contexts have changed, so try again. | 142 // The active contexts have changed, so try again. |
| 142 Response response = getNavigation(request); | 143 Response response = getNavigation(request); |
| 143 if (response != Response.DELAYED_RESPONSE) { | 144 if (response != Response.DELAYED_RESPONSE) { |
| 144 server.sendResponse(response); | 145 server.sendResponse(response); |
| 145 } | 146 } |
| 146 break; | 147 break; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 284 } |
| 284 if (newOptions.enableSuperMixins != null) { | 285 if (newOptions.enableSuperMixins != null) { |
| 285 updaters.add((engine.AnalysisOptionsImpl options) { | 286 updaters.add((engine.AnalysisOptionsImpl options) { |
| 286 options.enableSuperMixins = newOptions.enableSuperMixins; | 287 options.enableSuperMixins = newOptions.enableSuperMixins; |
| 287 }); | 288 }); |
| 288 } | 289 } |
| 289 server.updateOptions(updaters); | 290 server.updateOptions(updaters); |
| 290 return new AnalysisUpdateOptionsResult().toResponse(request.id); | 291 return new AnalysisUpdateOptionsResult().toResponse(request.id); |
| 291 } | 292 } |
| 292 } | 293 } |
| 293 | |
| 294 /** | |
| 295 * An AST visitor that computer navigation regions in the givne region. | |
| 296 */ | |
| 297 class _GetNavigationAstVisitor extends UnifyingAstVisitor { | |
| 298 final int rangeStart; | |
| 299 final int rangeEnd; | |
| 300 final DartUnitNavigationComputer computer; | |
| 301 | |
| 302 _GetNavigationAstVisitor(this.rangeStart, this.rangeEnd, this.computer); | |
| 303 | |
| 304 bool isInRange(int offset) { | |
| 305 return rangeStart <= offset && offset <= rangeEnd; | |
| 306 } | |
| 307 | |
| 308 @override | |
| 309 visitNode(AstNode node) { | |
| 310 // The node ends before the range starts. | |
| 311 if (node.end < rangeStart) { | |
| 312 return; | |
| 313 } | |
| 314 // The node starts after the range ends. | |
| 315 if (node.offset > rangeEnd) { | |
| 316 return; | |
| 317 } | |
| 318 // The node starts or ends in the range. | |
| 319 if (isInRange(node.offset) || isInRange(node.end)) { | |
| 320 computer.compute(node); | |
| 321 return; | |
| 322 } | |
| 323 super.visitNode(node); | |
| 324 } | |
| 325 } | |
| OLD | NEW |