| 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'; | 12 import 'package:analysis_server/src/domains/analysis/navigation_dart.dart'; |
| 13 import 'package:analysis_server/src/constants.dart'; | 13 import 'package:analysis_server/src/constants.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/engine.dart' as engine; | 18 import 'package:analyzer/src/generated/engine.dart' as engine; |
| 19 import 'package:analysis_server/src/domains/analysis/navigation.dart'; |
| 20 import 'package:analysis_server/analysis/navigation/navigation_core.dart'; |
| 21 import 'package:analyzer/src/generated/element.dart'; |
| 19 | 22 |
| 20 /** | 23 /** |
| 21 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] | 24 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] |
| 22 * that handles requests in the `analysis` domain. | 25 * that handles requests in the `analysis` domain. |
| 23 */ | 26 */ |
| 24 class AnalysisDomainHandler implements RequestHandler { | 27 class AnalysisDomainHandler implements RequestHandler { |
| 25 /** | 28 /** |
| 26 * The analysis server that is using this handler to process requests. | 29 * The analysis server that is using this handler to process requests. |
| 27 */ | 30 */ |
| 28 final AnalysisServer server; | 31 final AnalysisServer server; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 return new Response.getNavigationInvalidFile(request); | 121 return new Response.getNavigationInvalidFile(request); |
| 119 } | 122 } |
| 120 analysisFuture.then((AnalysisDoneReason reason) { | 123 analysisFuture.then((AnalysisDoneReason reason) { |
| 121 switch (reason) { | 124 switch (reason) { |
| 122 case AnalysisDoneReason.COMPLETE: | 125 case AnalysisDoneReason.COMPLETE: |
| 123 List<CompilationUnit> units = | 126 List<CompilationUnit> units = |
| 124 server.getResolvedCompilationUnits(file); | 127 server.getResolvedCompilationUnits(file); |
| 125 if (units.isEmpty) { | 128 if (units.isEmpty) { |
| 126 server.sendResponse(new Response.getNavigationInvalidFile(request)); | 129 server.sendResponse(new Response.getNavigationInvalidFile(request)); |
| 127 } else { | 130 } else { |
| 128 DartUnitNavigationComputer computer = | 131 CompilationUnitElement unitElement = units.first.element; |
| 129 new DartUnitNavigationComputer(); | 132 NavigationHolder holder = computeNavigation( |
| 130 _GetNavigationAstVisitor visitor = new _GetNavigationAstVisitor( | 133 server, |
| 131 params.offset, params.offset + params.length, computer); | 134 unitElement.context, |
| 132 for (CompilationUnit unit in units) { | 135 unitElement.source, |
| 133 unit.accept(visitor); | 136 params.offset, |
| 134 } | 137 params.length); |
| 135 server.sendResponse(new AnalysisGetNavigationResult( | 138 server.sendResponse(new AnalysisGetNavigationResult( |
| 136 computer.files, computer.targets, computer.regions) | 139 holder.files, holder.targets, holder.regions) |
| 137 .toResponse(request.id)); | 140 .toResponse(request.id)); |
| 138 } | 141 } |
| 139 break; | 142 break; |
| 140 case AnalysisDoneReason.CONTEXT_REMOVED: | 143 case AnalysisDoneReason.CONTEXT_REMOVED: |
| 141 // The active contexts have changed, so try again. | 144 // The active contexts have changed, so try again. |
| 142 Response response = getNavigation(request); | 145 Response response = getNavigation(request); |
| 143 if (response != Response.DELAYED_RESPONSE) { | 146 if (response != Response.DELAYED_RESPONSE) { |
| 144 server.sendResponse(response); | 147 server.sendResponse(response); |
| 145 } | 148 } |
| 146 break; | 149 break; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 286 } |
| 284 if (newOptions.enableSuperMixins != null) { | 287 if (newOptions.enableSuperMixins != null) { |
| 285 updaters.add((engine.AnalysisOptionsImpl options) { | 288 updaters.add((engine.AnalysisOptionsImpl options) { |
| 286 options.enableSuperMixins = newOptions.enableSuperMixins; | 289 options.enableSuperMixins = newOptions.enableSuperMixins; |
| 287 }); | 290 }); |
| 288 } | 291 } |
| 289 server.updateOptions(updaters); | 292 server.updateOptions(updaters); |
| 290 return new AnalysisUpdateOptionsResult().toResponse(request.id); | 293 return new AnalysisUpdateOptionsResult().toResponse(request.id); |
| 291 } | 294 } |
| 292 } | 295 } |
| 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 |