Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: pkg/analysis_server/lib/src/domain_diagnostic.dart

Issue 2703033002: Add a diagnostic.getServerPort analysis server request. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analysis_server.src.domain_diagnostic; 5 library analysis_server.src.domain_diagnostic;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:core'; 8 import 'dart:core';
9 9
10 import 'package:analysis_server/plugin/protocol/protocol.dart'; 10 import 'package:analysis_server/plugin/protocol/protocol.dart';
(...skipping 10 matching lines...) Expand all
21 int _workItemCount(AnalysisContextImpl context) { 21 int _workItemCount(AnalysisContextImpl context) {
22 AnalysisDriver driver = context.driver; 22 AnalysisDriver driver = context.driver;
23 List<WorkItem> items = driver.currentWorkOrder?.workItems; 23 List<WorkItem> items = driver.currentWorkOrder?.workItems;
24 return items?.length ?? 0; 24 return items?.length ?? 0;
25 } 25 }
26 26
27 /// Instances of the class [DiagnosticDomainHandler] implement a 27 /// Instances of the class [DiagnosticDomainHandler] implement a
28 /// [RequestHandler] that handles requests in the `diagnostic` domain. 28 /// [RequestHandler] that handles requests in the `diagnostic` domain.
29 class DiagnosticDomainHandler implements RequestHandler { 29 class DiagnosticDomainHandler implements RequestHandler {
30 /// The name of the request used to get diagnostic information. 30 /// The name of the request used to get diagnostic information.
31 static const String DIAGNOSTICS = 'diagnostic.getDiagnostics'; 31 static const String GET_DIAGNOSTICS = 'diagnostic.getDiagnostics';
32 static const String GET_SERVER_PORT = 'diagnostic.getServerPort';
Brian Wilkerson 2017/02/18 21:41:03 The rest of the constants like this are in the fil
devoncarew 2017/02/19 02:43:05 Good to know; moved these into constants.dart and
32 33
33 /// The analysis server that is using this handler to process requests. 34 /// The analysis server that is using this handler to process requests.
34 final AnalysisServer server; 35 final AnalysisServer server;
35 36
36 /// Initialize a newly created handler to handle requests for the given 37 /// Initialize a newly created handler to handle requests for the given
37 /// [server]. 38 /// [server].
38 DiagnosticDomainHandler(this.server); 39 DiagnosticDomainHandler(this.server);
39 40
40 /// Answer the `diagnostic.diagnostics` request. 41 /// Answer the `diagnostic.diagnostics` request.
41 Response computeDiagnostics(Request request) { 42 Response computeDiagnostics(Request request) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 int explicitFileCount = driver.addedFiles.length; 95 int explicitFileCount = driver.addedFiles.length;
95 int knownFileCount = driver.knownFiles.length; 96 int knownFileCount = driver.knownFiles.length;
96 return new ContextData(driver.name, explicitFileCount, 97 return new ContextData(driver.name, explicitFileCount,
97 knownFileCount - explicitFileCount, driver.numberOfFilesToAnalyze, []); 98 knownFileCount - explicitFileCount, driver.numberOfFilesToAnalyze, []);
98 } 99 }
99 100
100 @override 101 @override
101 Response handleRequest(Request request) { 102 Response handleRequest(Request request) {
102 try { 103 try {
103 String requestName = request.method; 104 String requestName = request.method;
104 if (requestName == DIAGNOSTICS) { 105 if (requestName == GET_DIAGNOSTICS) {
105 return computeDiagnostics(request); 106 return computeDiagnostics(request);
107 } else if (requestName == GET_SERVER_PORT) {
108 return getServerPort(request);
106 } 109 }
107 } on RequestFailure catch (exception) { 110 } on RequestFailure catch (exception) {
108 return exception.response; 111 return exception.response;
109 } 112 }
110 return null; 113 return null;
111 } 114 }
115
116 /// Answer the `diagnostic.getServerPort` request.
117 Response getServerPort(Request request) {
Brian Wilkerson 2017/02/18 21:41:03 Convert this to use an async body? I find it to be
devoncarew 2017/02/19 02:43:04 Sure, done. As an aside, I'm wondering if the `Re
118 // Open a port (or return the existing one).
119 server.diagnosticServer.getServerPort().then((int port) {
120 Response response =
121 new DiagnosticGetServerPortResult(port).toResponse(request.id);
122 server.sendResponse(response);
123 }).catchError((error) {
124 server.sendResponse(new Response.errorHandlingRequest(request, error));
125 });
126
127 // delay response
128 return Response.DELAYED_RESPONSE;
129 }
112 } 130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698