| 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 socket.server; | 5 library socket.server; |
| 6 | 6 |
| 7 import 'dart:io' as io; |
| 8 |
| 7 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 8 import 'package:analysis_server/src/channel.dart'; | 10 import 'package:analysis_server/src/channel.dart'; |
| 9 import 'package:analysis_server/src/domain_analysis.dart'; | 11 import 'package:analysis_server/src/domain_analysis.dart'; |
| 10 import 'package:analysis_server/src/domain_completion.dart'; | 12 import 'package:analysis_server/src/domain_completion.dart'; |
| 11 import 'package:analysis_server/src/domain_edit.dart'; | 13 import 'package:analysis_server/src/domain_edit.dart'; |
| 12 import 'package:analysis_server/src/domain_search.dart'; | 14 import 'package:analysis_server/src/domain_search.dart'; |
| 13 import 'package:analysis_server/src/domain_server.dart'; | 15 import 'package:analysis_server/src/domain_server.dart'; |
| 16 import 'package:analysis_server/src/index/index.dart'; |
| 14 import 'package:analysis_server/src/package_map_provider.dart'; | 17 import 'package:analysis_server/src/package_map_provider.dart'; |
| 15 import 'package:analysis_server/src/protocol.dart'; | 18 import 'package:analysis_server/src/protocol.dart'; |
| 16 import 'package:analysis_server/src/resource.dart'; | 19 import 'package:analysis_server/src/resource.dart'; |
| 20 import 'package:analyzer/src/generated/index.dart'; |
| 21 import 'package:path/path.dart' as pathos; |
| 22 |
| 23 |
| 24 /** |
| 25 * Creates and runs an [Index]. |
| 26 */ |
| 27 Index _createIndex() { |
| 28 String tempPath = io.Directory.systemTemp.path; |
| 29 String indexPath = pathos.join(tempPath, 'AnalysisServer_index'); |
| 30 io.Directory indexDirectory = new io.Directory(indexPath); |
| 31 if (indexDirectory.existsSync()) { |
| 32 indexDirectory.deleteSync(recursive: true); |
| 33 } |
| 34 if (!indexDirectory.existsSync()) { |
| 35 indexDirectory.createSync(); |
| 36 } |
| 37 Index index = createLocalFileSplitIndex(indexDirectory); |
| 38 index.run(); |
| 39 return index; |
| 40 } |
| 41 |
| 17 | 42 |
| 18 /** | 43 /** |
| 19 * Instances of the class [SocketServer] implement the common parts of | 44 * Instances of the class [SocketServer] implement the common parts of |
| 20 * http-based and stdio-based analysis servers. The primary responsibility of | 45 * http-based and stdio-based analysis servers. The primary responsibility of |
| 21 * the SocketServer is to manage the lifetime of the AnalysisServer and to | 46 * the SocketServer is to manage the lifetime of the AnalysisServer and to |
| 22 * encode and decode the JSON messages exchanged with the client. | 47 * encode and decode the JSON messages exchanged with the client. |
| 23 */ | 48 */ |
| 24 class SocketServer { | 49 class SocketServer { |
| 25 /** | 50 /** |
| 26 * The analysis server that was created when a client established a | 51 * The analysis server that was created when a client established a |
| (...skipping 12 matching lines...) Expand all Loading... |
| 39 serverChannel.listen((Request request) { | 64 serverChannel.listen((Request request) { |
| 40 serverChannel.sendResponse(new Response(request.id, error)); | 65 serverChannel.sendResponse(new Response(request.id, error)); |
| 41 }); | 66 }); |
| 42 return; | 67 return; |
| 43 } | 68 } |
| 44 PhysicalResourceProvider resourceProvider = PhysicalResourceProvider.INSTANC
E; | 69 PhysicalResourceProvider resourceProvider = PhysicalResourceProvider.INSTANC
E; |
| 45 analysisServer = new AnalysisServer( | 70 analysisServer = new AnalysisServer( |
| 46 serverChannel, | 71 serverChannel, |
| 47 resourceProvider, | 72 resourceProvider, |
| 48 new PubPackageMapProvider(resourceProvider), | 73 new PubPackageMapProvider(resourceProvider), |
| 74 _createIndex(), |
| 49 rethrowExceptions: false); | 75 rethrowExceptions: false); |
| 50 _initializeHandlers(analysisServer); | 76 _initializeHandlers(analysisServer); |
| 51 } | 77 } |
| 52 | 78 |
| 53 /** | 79 /** |
| 54 * Initialize the handlers to be used by the given [server]. | 80 * Initialize the handlers to be used by the given [server]. |
| 55 */ | 81 */ |
| 56 void _initializeHandlers(AnalysisServer server) { | 82 void _initializeHandlers(AnalysisServer server) { |
| 57 server.handlers = [ | 83 server.handlers = [ |
| 58 new ServerDomainHandler(server), | 84 new ServerDomainHandler(server), |
| 59 new AnalysisDomainHandler(server), | 85 new AnalysisDomainHandler(server), |
| 60 new EditDomainHandler(server), | 86 new EditDomainHandler(server), |
| 61 new SearchDomainHandler(server), | 87 new SearchDomainHandler(server), |
| 62 new CompletionDomainHandler(server), | 88 new CompletionDomainHandler(server), |
| 63 ]; | 89 ]; |
| 64 } | 90 } |
| 65 | |
| 66 } | 91 } |
| OLD | NEW |