Index: pkg/analysis_server/lib/src/domain_analysis.dart |
diff --git a/pkg/analysis_server/lib/src/domain_analysis.dart b/pkg/analysis_server/lib/src/domain_analysis.dart |
index fd326462dfac71230d3b8fbbba2f758024c14e35..c09c5113d6b630b17a463d8fa0c1f81e948647b9 100644 |
--- a/pkg/analysis_server/lib/src/domain_analysis.dart |
+++ b/pkg/analysis_server/lib/src/domain_analysis.dart |
@@ -9,6 +9,7 @@ import 'dart:core' hide Resource; |
import 'package:analysis_server/src/analysis_server.dart'; |
import 'package:analysis_server/src/computer/computer_hover.dart'; |
+import 'package:analysis_server/src/computer/computer_navigation.dart'; |
import 'package:analysis_server/src/constants.dart'; |
import 'package:analysis_server/src/protocol_server.dart'; |
import 'package:analysis_server/src/services/dependencies/library_dependencies.dart'; |
@@ -105,6 +106,52 @@ class AnalysisDomainHandler implements RequestHandler { |
return Response.DELAYED_RESPONSE; |
} |
+ /** |
+ * Implement the `analysis.getNavigation` request. |
+ */ |
+ Response getNavigation(Request request) { |
+ var params = new AnalysisGetNavigationParams.fromRequest(request); |
+ String file = params.file; |
+ int offset = params.offset; |
+ Future<AnalysisDoneReason> completionFuture = |
+ server.onFileAnalysisComplete(file); |
+ if (completionFuture == null) { |
+ return new Response.getNavigationInvalidFile(request); |
+ } |
+ completionFuture.then((AnalysisDoneReason reason) { |
+ switch (reason) { |
+ case AnalysisDoneReason.COMPLETE: |
+ List<CompilationUnit> units = |
+ server.getResolvedCompilationUnits(file); |
+ if (units.isEmpty) { |
+ server.sendResponse(new Response.getNavigationInvalidFile(request)); |
+ } else { |
+ DartUnitNavigationComputer computer = |
+ new DartUnitNavigationComputer(); |
+ for (CompilationUnit unit in units) { |
+ AstNode node = new NodeLocator(offset).searchWithin(unit); |
+ if (node != null) { |
+ computer.compute(node); |
+ } |
+ } |
+ server.sendResponse(new AnalysisGetNavigationResult( |
+ computer.files, computer.targets, computer.regions) |
+ .toResponse(request.id)); |
+ } |
+ break; |
+ case AnalysisDoneReason.CONTEXT_REMOVED: |
+ // The active contexts have changed, so try again. |
+ Response response = getNavigation(request); |
+ if (response != Response.DELAYED_RESPONSE) { |
+ server.sendResponse(response); |
+ } |
+ break; |
+ } |
+ }); |
+ // delay response |
+ return Response.DELAYED_RESPONSE; |
+ } |
+ |
@override |
Response handleRequest(Request request) { |
try { |
@@ -115,6 +162,8 @@ class AnalysisDomainHandler implements RequestHandler { |
return getHover(request); |
} else if (requestName == ANALYSIS_GET_LIBRARY_DEPENDENCIES) { |
return getLibraryDependencies(request); |
+ } else if (requestName == ANALYSIS_GET_NAVIGATION) { |
+ return getNavigation(request); |
} else if (requestName == ANALYSIS_REANALYZE) { |
return reanalyze(request); |
} else if (requestName == ANALYSIS_SET_ANALYSIS_ROOTS) { |