OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 import 'dart:async'; |
| 6 import 'dart:core'; |
| 7 |
| 8 import 'package:analysis_server/protocol/protocol.dart'; |
| 9 import 'package:analysis_server/protocol/protocol_constants.dart'; |
| 10 import 'package:analysis_server/protocol/protocol_generated.dart'; |
| 11 import 'package:analysis_server/src/analysis_server.dart'; |
| 12 import 'package:analysis_server/src/services/kythe/kythe_visitors.dart'; |
| 13 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 14 import 'package:analyzer/src/dart/resolver/inheritance_manager.dart'; |
| 15 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 16 |
| 17 /** |
| 18 * Instances of the class [KytheDomainHandler] implement a [RequestHandler] |
| 19 * that handles requests in the `kythe` domain. |
| 20 */ |
| 21 class KytheDomainHandler implements RequestHandler { |
| 22 /** |
| 23 * The analysis server that is using this handler to process requests. |
| 24 */ |
| 25 final AnalysisServer server; |
| 26 |
| 27 /** |
| 28 * Initialize a newly created handler to handle requests for the given [server
]. |
| 29 */ |
| 30 KytheDomainHandler(this.server); |
| 31 |
| 32 /** |
| 33 * Implement the `kythe.getKytheEntries` request. |
| 34 */ |
| 35 Future<Null> getKytheEntries(Request request) async { |
| 36 String file = new KytheGetKytheEntriesParams.fromRequest(request).file; |
| 37 AnalysisResult result = await server.getAnalysisResult(file); |
| 38 List<KytheEntry> entries = <KytheEntry>[]; |
| 39 // TODO(brianwilkerson) Figure out how to get the list of files. |
| 40 List<String> files = <String>[]; |
| 41 result.unit.accept(new KytheDartVisitor([] /*entries*/, file, |
| 42 new InheritanceManager(result.libraryElement), result.content)); |
| 43 server.sendResponse( |
| 44 new KytheGetKytheEntriesResult(entries, files).toResponse(request.id)); |
| 45 } |
| 46 |
| 47 @override |
| 48 Response handleRequest(Request request) { |
| 49 try { |
| 50 String requestName = request.method; |
| 51 if (requestName == KYTHE_REQUEST_GET_KYTHE_ENTRIES) { |
| 52 getKytheEntries(request); |
| 53 return Response.DELAYED_RESPONSE; |
| 54 } |
| 55 } on RequestFailure catch (exception) { |
| 56 return exception.response; |
| 57 } |
| 58 return null; |
| 59 } |
| 60 } |
OLD | NEW |