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'; | 8 import 'dart:core'; |
9 | 9 |
10 import 'package:analysis_server/plugin/analysis/analysis_domain.dart'; | 10 import 'package:analysis_server/plugin/analysis/analysis_domain.dart'; |
11 import 'package:analysis_server/src/analysis_server.dart'; | 11 import 'package:analysis_server/src/analysis_server.dart'; |
12 import 'package:analysis_server/src/computer/computer_hover.dart'; | 12 import 'package:analysis_server/src/computer/computer_hover.dart'; |
13 import 'package:analysis_server/src/constants.dart'; | 13 import 'package:analysis_server/src/constants.dart'; |
14 import 'package:analysis_server/src/context_manager.dart'; | 14 import 'package:analysis_server/src/context_manager.dart'; |
15 import 'package:analysis_server/src/domains/analysis/navigation.dart'; | 15 import 'package:analysis_server/src/domains/analysis/navigation.dart'; |
16 import 'package:analysis_server/src/operation/operation_analysis.dart' | 16 import 'package:analysis_server/src/operation/operation_analysis.dart' |
17 show NavigationOperation, OccurrencesOperation; | 17 show NavigationOperation, OccurrencesOperation; |
18 import 'package:analysis_server/src/protocol/protocol_internal.dart'; | 18 import 'package:analysis_server/src/protocol/protocol_internal.dart'; |
19 import 'package:analysis_server/src/protocol_server.dart'; | 19 import 'package:analysis_server/src/protocol_server.dart'; |
20 import 'package:analysis_server/src/services/dependencies/library_dependencies.d
art'; | 20 import 'package:analysis_server/src/services/dependencies/library_dependencies.d
art'; |
21 import 'package:analysis_server/src/services/dependencies/reachable_source_colle
ctor.dart'; | 21 import 'package:analysis_server/src/services/dependencies/reachable_source_colle
ctor.dart'; |
22 import 'package:analyzer/dart/ast/ast.dart'; | 22 import 'package:analyzer/dart/ast/ast.dart'; |
23 import 'package:analyzer/dart/element/element.dart'; | 23 import 'package:analyzer/dart/element/element.dart'; |
| 24 import 'package:analyzer/error/error.dart' as engine; |
24 import 'package:analyzer/exception/exception.dart'; | 25 import 'package:analyzer/exception/exception.dart'; |
25 import 'package:analyzer/file_system/file_system.dart'; | 26 import 'package:analyzer/file_system/file_system.dart'; |
26 import 'package:analyzer/src/dart/analysis/driver.dart'; | 27 import 'package:analyzer/src/dart/analysis/driver.dart'; |
27 import 'package:analyzer/src/generated/engine.dart' as engine; | 28 import 'package:analyzer/src/generated/engine.dart' as engine; |
28 import 'package:analyzer/src/generated/source.dart'; | 29 import 'package:analyzer/src/generated/source.dart'; |
29 import 'package:analyzer/task/model.dart' show ResultDescriptor; | 30 import 'package:analyzer/task/model.dart' show ResultDescriptor; |
30 | 31 |
31 /** | 32 /** |
32 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] | 33 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] |
33 * that handles requests in the `analysis` domain. | 34 * that handles requests in the `analysis` domain. |
34 */ | 35 */ |
35 class AnalysisDomainHandler implements RequestHandler { | 36 class AnalysisDomainHandler implements RequestHandler { |
36 /** | 37 /** |
37 * The analysis server that is using this handler to process requests. | 38 * The analysis server that is using this handler to process requests. |
38 */ | 39 */ |
39 final AnalysisServer server; | 40 final AnalysisServer server; |
40 | 41 |
41 /** | 42 /** |
42 * Initialize a newly created handler to handle requests for the given [server
]. | 43 * Initialize a newly created handler to handle requests for the given [server
]. |
43 */ | 44 */ |
44 AnalysisDomainHandler(this.server) { | 45 AnalysisDomainHandler(this.server) { |
45 _callAnalysisDomainReceivers(); | 46 _callAnalysisDomainReceivers(); |
46 } | 47 } |
47 | 48 |
48 /** | 49 /** |
49 * Implement the `analysis.getErrors` request. | 50 * Implement the `analysis.getErrors` request. |
50 */ | 51 */ |
51 Response getErrors(Request request) { | 52 Future<Null> getErrors(Request request) async { |
52 String file = new AnalysisGetErrorsParams.fromRequest(request).file; | 53 String file = new AnalysisGetErrorsParams.fromRequest(request).file; |
| 54 |
| 55 void send(engine.AnalysisOptions analysisOptions, LineInfo lineInfo, |
| 56 List<engine.AnalysisError> errors) { |
| 57 if (lineInfo == null) { |
| 58 server.sendResponse(new Response.getErrorsInvalidFile(request)); |
| 59 } else { |
| 60 List<AnalysisError> protocolErrors = |
| 61 doAnalysisError_listFromEngine(analysisOptions, lineInfo, errors); |
| 62 server.sendResponse( |
| 63 new AnalysisGetErrorsResult(protocolErrors).toResponse(request.id)); |
| 64 } |
| 65 } |
| 66 |
| 67 if (server.options.enableNewAnalysisDriver) { |
| 68 var result = await server.getAnalysisResult(file); |
| 69 send(result?.driver?.analysisOptions, result?.lineInfo, result?.errors); |
| 70 return; |
| 71 } |
| 72 |
53 Future<AnalysisDoneReason> completionFuture = | 73 Future<AnalysisDoneReason> completionFuture = |
54 server.onFileAnalysisComplete(file); | 74 server.onFileAnalysisComplete(file); |
55 if (completionFuture == null) { | 75 if (completionFuture == null) { |
56 return new Response.getErrorsInvalidFile(request); | 76 server.sendResponse(new Response.getErrorsInvalidFile(request)); |
57 } | 77 } |
58 completionFuture.then((AnalysisDoneReason reason) { | 78 completionFuture.then((AnalysisDoneReason reason) async { |
59 switch (reason) { | 79 switch (reason) { |
60 case AnalysisDoneReason.COMPLETE: | 80 case AnalysisDoneReason.COMPLETE: |
61 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); | 81 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); |
62 List<AnalysisError> errors; | |
63 if (errorInfo == null) { | 82 if (errorInfo == null) { |
64 server.sendResponse(new Response.getErrorsInvalidFile(request)); | 83 server.sendResponse(new Response.getErrorsInvalidFile(request)); |
65 } else { | 84 } else { |
66 engine.AnalysisContext context = server.getAnalysisContext(file); | 85 engine.AnalysisContext context = server.getAnalysisContext(file); |
67 errors = doAnalysisError_listFromEngine( | 86 send(context.analysisOptions, errorInfo.lineInfo, errorInfo.errors); |
68 context, errorInfo.lineInfo, errorInfo.errors); | |
69 server.sendResponse( | |
70 new AnalysisGetErrorsResult(errors).toResponse(request.id)); | |
71 } | 87 } |
72 break; | 88 break; |
73 case AnalysisDoneReason.CONTEXT_REMOVED: | 89 case AnalysisDoneReason.CONTEXT_REMOVED: |
74 // The active contexts have changed, so try again. | 90 // The active contexts have changed, so try again. |
75 Response response = getErrors(request); | 91 await getErrors(request); |
76 if (response != Response.DELAYED_RESPONSE) { | |
77 server.sendResponse(response); | |
78 } | |
79 break; | 92 break; |
80 } | 93 } |
81 }); | 94 }); |
82 // delay response | |
83 return Response.DELAYED_RESPONSE; | |
84 } | 95 } |
85 | 96 |
86 /** | 97 /** |
87 * Implement the `analysis.getHover` request. | 98 * Implement the `analysis.getHover` request. |
88 */ | 99 */ |
89 Future<Null> getHover(Request request) async { | 100 Future<Null> getHover(Request request) async { |
90 var params = new AnalysisGetHoverParams.fromRequest(request); | 101 var params = new AnalysisGetHoverParams.fromRequest(request); |
91 | 102 |
92 // Prepare the resolved units. | 103 // Prepare the resolved units. |
93 CompilationUnit unit; | 104 CompilationUnit unit; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 .collectSources(); | 202 .collectSources(); |
192 return new AnalysisGetReachableSourcesResult(sources) | 203 return new AnalysisGetReachableSourcesResult(sources) |
193 .toResponse(request.id); | 204 .toResponse(request.id); |
194 } | 205 } |
195 | 206 |
196 @override | 207 @override |
197 Response handleRequest(Request request) { | 208 Response handleRequest(Request request) { |
198 try { | 209 try { |
199 String requestName = request.method; | 210 String requestName = request.method; |
200 if (requestName == ANALYSIS_GET_ERRORS) { | 211 if (requestName == ANALYSIS_GET_ERRORS) { |
201 return getErrors(request); | 212 getErrors(request); |
| 213 return Response.DELAYED_RESPONSE; |
202 } else if (requestName == ANALYSIS_GET_HOVER) { | 214 } else if (requestName == ANALYSIS_GET_HOVER) { |
203 getHover(request); | 215 getHover(request); |
204 return Response.DELAYED_RESPONSE; | 216 return Response.DELAYED_RESPONSE; |
205 } else if (requestName == ANALYSIS_GET_LIBRARY_DEPENDENCIES) { | 217 } else if (requestName == ANALYSIS_GET_LIBRARY_DEPENDENCIES) { |
206 return getLibraryDependencies(request); | 218 return getLibraryDependencies(request); |
207 } else if (requestName == ANALYSIS_GET_NAVIGATION) { | 219 } else if (requestName == ANALYSIS_GET_NAVIGATION) { |
208 return getNavigation(request); | 220 return getNavigation(request); |
209 } else if (requestName == ANALYSIS_GET_REACHABLE_SOURCES) { | 221 } else if (requestName == ANALYSIS_GET_REACHABLE_SOURCES) { |
210 return getReachableSources(request); | 222 return getReachableSources(request); |
211 } else if (requestName == ANALYSIS_REANALYZE) { | 223 } else if (requestName == ANALYSIS_REANALYZE) { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 context.onResultChanged(descriptor).listen((result) { | 425 context.onResultChanged(descriptor).listen((result) { |
414 StreamController<engine.ResultChangedEvent> controller = | 426 StreamController<engine.ResultChangedEvent> controller = |
415 controllers[result.descriptor]; | 427 controllers[result.descriptor]; |
416 if (controller != null) { | 428 if (controller != null) { |
417 controller.add(result); | 429 controller.add(result); |
418 } | 430 } |
419 }); | 431 }); |
420 } | 432 } |
421 } | 433 } |
422 } | 434 } |
OLD | NEW |