Skip to content

Commit 58a2090

Browse files
author
Dart CI
committed
Version 2.10.0-35.0.dev
Merge commit 'd9ce879bc2584792566ac3e92fddbed8fceb90b4' into 'dev'
2 parents 302893b + d9ce879 commit 58a2090

22 files changed

+249
-610
lines changed

pkg/analysis_server/lib/src/analysis_server.dart

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import 'package:analyzer/src/dart/analysis/file_state.dart' as nd;
5555
import 'package:analyzer/src/dart/analysis/status.dart' as nd;
5656
import 'package:analyzer/src/generated/engine.dart';
5757
import 'package:analyzer/src/generated/sdk.dart';
58-
import 'package:analyzer/src/generated/utilities_general.dart';
5958
import 'package:analyzer_plugin/protocol/protocol_common.dart' hide Element;
6059
import 'package:analyzer_plugin/src/utilities/navigation/navigation.dart';
6160
import 'package:analyzer_plugin/utilities/navigation/navigation_dart.dart';
@@ -234,34 +233,32 @@ class AnalysisServer extends AbstractAnalysisServer {
234233
void handleRequest(Request request) {
235234
performance.logRequestTiming(request.clientRequestTime);
236235
runZonedGuarded(() {
237-
ServerPerformanceStatistics.serverRequests.makeCurrentWhile(() {
238-
var count = handlers.length;
239-
for (var i = 0; i < count; i++) {
240-
try {
241-
var response = handlers[i].handleRequest(request);
242-
if (response == Response.DELAYED_RESPONSE) {
243-
return;
244-
}
245-
if (response != null) {
246-
channel.sendResponse(response);
247-
return;
248-
}
249-
} on RequestFailure catch (exception) {
250-
channel.sendResponse(exception.response);
236+
var count = handlers.length;
237+
for (var i = 0; i < count; i++) {
238+
try {
239+
var response = handlers[i].handleRequest(request);
240+
if (response == Response.DELAYED_RESPONSE) {
251241
return;
252-
} catch (exception, stackTrace) {
253-
var error = RequestError(
254-
RequestErrorCode.SERVER_ERROR, exception.toString());
255-
if (stackTrace != null) {
256-
error.stackTrace = stackTrace.toString();
257-
}
258-
var response = Response(request.id, error: error);
242+
}
243+
if (response != null) {
259244
channel.sendResponse(response);
260245
return;
261246
}
247+
} on RequestFailure catch (exception) {
248+
channel.sendResponse(exception.response);
249+
return;
250+
} catch (exception, stackTrace) {
251+
var error =
252+
RequestError(RequestErrorCode.SERVER_ERROR, exception.toString());
253+
if (stackTrace != null) {
254+
error.stackTrace = stackTrace.toString();
255+
}
256+
var response = Response(request.id, error: error);
257+
channel.sendResponse(response);
258+
return;
262259
}
263-
channel.sendResponse(Response.unknownRequest(request));
264-
});
260+
}
261+
channel.sendResponse(Response.unknownRequest(request));
265262
}, (exception, stackTrace) {
266263
AnalysisEngine.instance.instrumentationService.logException(
267264
FatalException(
@@ -931,23 +928,3 @@ class ServerPerformance {
931928
}
932929
}
933930
}
934-
935-
/// Container with global [AnalysisServer] performance statistics.
936-
class ServerPerformanceStatistics {
937-
/// The [PerformanceTag] for `package:analysis_server`.
938-
static final PerformanceTag server = PerformanceTag('server');
939-
940-
/// The [PerformanceTag] for time spent between calls to
941-
/// AnalysisServer.performOperation when the server is idle.
942-
static final PerformanceTag idle = PerformanceTag('idle');
943-
944-
/// The [PerformanceTag] for time spent in
945-
/// PerformAnalysisOperation._sendNotices.
946-
static final PerformanceTag notices = server.createChild('notices');
947-
948-
/// The [PerformanceTag] for time spent in server communication channels.
949-
static final PerformanceTag serverChannel = server.createChild('channel');
950-
951-
/// The [PerformanceTag] for time spent in server request handlers.
952-
static final PerformanceTag serverRequests = server.createChild('requests');
953-
}

pkg/analysis_server/lib/src/channel/byte_stream_channel.dart

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'dart:convert';
77
import 'dart:io';
88

99
import 'package:analysis_server/protocol/protocol.dart';
10-
import 'package:analysis_server/src/analysis_server.dart';
1110
import 'package:analysis_server/src/channel/channel.dart';
1211
import 'package:analysis_server/src/utilities/request_statistics.dart';
1312
import 'package:analyzer/instrumentation/instrumentation.dart';
@@ -115,14 +114,12 @@ class ByteStreamServerChannel implements ServerCommunicationChannel {
115114
if (_closeRequested) {
116115
return;
117116
}
118-
ServerPerformanceStatistics.serverChannel.makeCurrentWhile(() {
119-
var jsonEncoding = json.encode(notification.toJson());
120-
_outputLine(jsonEncoding);
121-
if (!identical(notification.event, 'server.log')) {
122-
_instrumentationService.logNotification(jsonEncoding);
123-
_requestStatistics?.logNotification(notification);
124-
}
125-
});
117+
var jsonEncoding = json.encode(notification.toJson());
118+
_outputLine(jsonEncoding);
119+
if (!identical(notification.event, 'server.log')) {
120+
_instrumentationService.logNotification(jsonEncoding);
121+
_requestStatistics?.logNotification(notification);
122+
}
126123
}
127124

128125
@override
@@ -132,12 +129,10 @@ class ByteStreamServerChannel implements ServerCommunicationChannel {
132129
if (_closeRequested) {
133130
return;
134131
}
135-
ServerPerformanceStatistics.serverChannel.makeCurrentWhile(() {
136-
_requestStatistics?.addResponse(response);
137-
var jsonEncoding = json.encode(response.toJson());
138-
_outputLine(jsonEncoding);
139-
_instrumentationService.logResponse(jsonEncoding);
140-
});
132+
_requestStatistics?.addResponse(response);
133+
var jsonEncoding = json.encode(response.toJson());
134+
_outputLine(jsonEncoding);
135+
_instrumentationService.logResponse(jsonEncoding);
141136
}
142137

143138
/// Send the string [s] to [_output] followed by a newline.
@@ -156,17 +151,15 @@ class ByteStreamServerChannel implements ServerCommunicationChannel {
156151
if (_closed.isCompleted) {
157152
return;
158153
}
159-
ServerPerformanceStatistics.serverChannel.makeCurrentWhile(() {
160-
_instrumentationService.logRequest(data);
161-
// Parse the string as a JSON descriptor and process the resulting
162-
// structure as a request.
163-
var request = Request.fromString(data);
164-
if (request == null) {
165-
sendResponse(Response.invalidRequestFormat());
166-
return;
167-
}
168-
_requestStatistics?.addRequest(request);
169-
onRequest(request);
170-
});
154+
_instrumentationService.logRequest(data);
155+
// Parse the string as a JSON descriptor and process the resulting
156+
// structure as a request.
157+
var request = Request.fromString(data);
158+
if (request == null) {
159+
sendResponse(Response.invalidRequestFormat());
160+
return;
161+
}
162+
_requestStatistics?.addRequest(request);
163+
onRequest(request);
171164
}
172165
}

pkg/analysis_server/lib/src/flutter/flutter_notifications.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ void sendFlutterNotificationOutline(
2525

2626
/// Runs the given notification producing function [f], catching exceptions.
2727
void _sendNotification(AnalysisServer server, Function() f) {
28-
ServerPerformanceStatistics.notices.makeCurrentWhile(() {
29-
try {
30-
f();
31-
} catch (exception, stackTrace) {
32-
AnalysisEngine.instance.instrumentationService.logException(
33-
CaughtException.withMessage(
34-
'Failed to send notification', exception, stackTrace));
35-
}
36-
});
28+
try {
29+
f();
30+
} catch (exception, stackTrace) {
31+
AnalysisEngine.instance.instrumentationService.logException(
32+
CaughtException.withMessage(
33+
'Failed to send notification', exception, stackTrace));
34+
}
3735
}

pkg/analysis_server/lib/src/lsp/channel/lsp_byte_stream_channel.dart

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'dart:io';
88

99
import 'package:analysis_server/lsp_protocol/protocol_generated.dart';
1010
import 'package:analysis_server/lsp_protocol/protocol_special.dart';
11-
import 'package:analysis_server/src/analysis_server.dart';
1211
import 'package:analysis_server/src/lsp/channel/lsp_channel.dart';
1312
import 'package:analysis_server/src/lsp/json_parsing.dart';
1413
import 'package:analysis_server/src/lsp/lsp_packet_transformer.dart';
@@ -80,19 +79,17 @@ class LspByteStreamServerChannel implements LspServerCommunicationChannel {
8079
if (_closed.isCompleted) {
8180
return;
8281
}
83-
ServerPerformanceStatistics.serverChannel.makeCurrentWhile(() {
84-
_instrumentationService.logRequest(data);
85-
final Map<String, Object> json = jsonDecode(data);
86-
if (RequestMessage.canParse(json, nullLspJsonReporter)) {
87-
onMessage(RequestMessage.fromJson(json));
88-
} else if (NotificationMessage.canParse(json, nullLspJsonReporter)) {
89-
onMessage(NotificationMessage.fromJson(json));
90-
} else if (ResponseMessage.canParse(json, nullLspJsonReporter)) {
91-
onMessage(ResponseMessage.fromJson(json));
92-
} else {
93-
_sendParseError();
94-
}
95-
});
82+
_instrumentationService.logRequest(data);
83+
final Map<String, Object> json = jsonDecode(data);
84+
if (RequestMessage.canParse(json, nullLspJsonReporter)) {
85+
onMessage(RequestMessage.fromJson(json));
86+
} else if (NotificationMessage.canParse(json, nullLspJsonReporter)) {
87+
onMessage(NotificationMessage.fromJson(json));
88+
} else if (ResponseMessage.canParse(json, nullLspJsonReporter)) {
89+
onMessage(ResponseMessage.fromJson(json));
90+
} else {
91+
_sendParseError();
92+
}
9693
}
9794

9895
/// Sends a message prefixed with the required LSP headers.
@@ -102,19 +99,17 @@ class LspByteStreamServerChannel implements LspServerCommunicationChannel {
10299
if (_closeRequested) {
103100
return;
104101
}
105-
ServerPerformanceStatistics.serverChannel.makeCurrentWhile(() {
106-
final jsonEncodedBody = jsonEncode(json);
107-
final utf8EncodedBody = utf8.encode(jsonEncodedBody);
108-
final header = 'Content-Length: ${utf8EncodedBody.length}\r\n'
109-
'Content-Type: application/vscode-jsonrpc; charset=utf-8\r\n\r\n';
110-
final asciiEncodedHeader = ascii.encode(header);
111-
112-
// Header is always ascii, body is always utf8!
113-
_write(asciiEncodedHeader);
114-
_write(utf8EncodedBody);
115-
116-
_instrumentationService.logResponse(jsonEncodedBody);
117-
});
102+
final jsonEncodedBody = jsonEncode(json);
103+
final utf8EncodedBody = utf8.encode(jsonEncodedBody);
104+
final header = 'Content-Length: ${utf8EncodedBody.length}\r\n'
105+
'Content-Type: application/vscode-jsonrpc; charset=utf-8\r\n\r\n';
106+
final asciiEncodedHeader = ascii.encode(header);
107+
108+
// Header is always ascii, body is always utf8!
109+
_write(asciiEncodedHeader);
110+
_write(utf8EncodedBody);
111+
112+
_instrumentationService.logResponse(jsonEncodedBody);
118113
}
119114

120115
void _sendParseError() {

pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -258,46 +258,44 @@ class LspAnalysisServer extends AbstractAnalysisServer {
258258
/// Handle a [message] that was read from the communication channel.
259259
void handleMessage(Message message) {
260260
performance.logRequestTiming(null);
261-
runZonedGuarded(() {
262-
ServerPerformanceStatistics.serverRequests.makeCurrentWhile(() async {
263-
try {
264-
if (message is ResponseMessage) {
265-
handleClientResponse(message);
266-
} else if (message is RequestMessage) {
267-
final result = await messageHandler.handleMessage(message);
268-
if (result.isError) {
269-
sendErrorResponse(message, result.error);
270-
} else {
271-
channel.sendResponse(ResponseMessage(
272-
id: message.id,
273-
result: result.result,
274-
jsonrpc: jsonRpcVersion));
275-
}
276-
} else if (message is NotificationMessage) {
277-
final result = await messageHandler.handleMessage(message);
278-
if (result.isError) {
279-
sendErrorResponse(message, result.error);
280-
}
261+
runZonedGuarded(() async {
262+
try {
263+
if (message is ResponseMessage) {
264+
handleClientResponse(message);
265+
} else if (message is RequestMessage) {
266+
final result = await messageHandler.handleMessage(message);
267+
if (result.isError) {
268+
sendErrorResponse(message, result.error);
281269
} else {
282-
showErrorMessageToUser('Unknown message type');
270+
channel.sendResponse(ResponseMessage(
271+
id: message.id,
272+
result: result.result,
273+
jsonrpc: jsonRpcVersion));
283274
}
284-
} catch (error, stackTrace) {
285-
final errorMessage = message is ResponseMessage
286-
? 'An error occurred while handling the response to request ${message.id}'
287-
: message is RequestMessage
288-
? 'An error occurred while handling ${message.method} request'
289-
: message is NotificationMessage
290-
? 'An error occurred while handling ${message.method} notification'
291-
: 'Unknown message type';
292-
sendErrorResponse(
293-
message,
294-
ResponseError(
295-
code: ServerErrorCodes.UnhandledError,
296-
message: errorMessage,
297-
));
298-
logException(errorMessage, error, stackTrace);
275+
} else if (message is NotificationMessage) {
276+
final result = await messageHandler.handleMessage(message);
277+
if (result.isError) {
278+
sendErrorResponse(message, result.error);
279+
}
280+
} else {
281+
showErrorMessageToUser('Unknown message type');
299282
}
300-
});
283+
} catch (error, stackTrace) {
284+
final errorMessage = message is ResponseMessage
285+
? 'An error occurred while handling the response to request ${message.id}'
286+
: message is RequestMessage
287+
? 'An error occurred while handling ${message.method} request'
288+
: message is NotificationMessage
289+
? 'An error occurred while handling ${message.method} notification'
290+
: 'Unknown message type';
291+
sendErrorResponse(
292+
message,
293+
ResponseError(
294+
code: ServerErrorCodes.UnhandledError,
295+
message: errorMessage,
296+
));
297+
logException(errorMessage, error, stackTrace);
298+
}
301299
}, socketError);
302300
}
303301

@@ -623,6 +621,7 @@ class LspInitializationOptions {
623621
final bool closingLabels;
624622
final bool outline;
625623
final bool flutterOutline;
624+
626625
LspInitializationOptions(dynamic options)
627626
: onlyAnalyzeProjectsWithOpenFiles = options != null &&
628627
options['onlyAnalyzeProjectsWithOpenFiles'] == true,

pkg/analysis_server/lib/src/operation/operation_analysis.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,11 @@ String _computeLibraryName(CompilationUnit unit) {
165165

166166
/// Runs the given notification producing function [f], catching exceptions.
167167
void _sendNotification(AnalysisServer server, Function() f) {
168-
ServerPerformanceStatistics.notices.makeCurrentWhile(() {
169-
try {
170-
f();
171-
} catch (exception, stackTrace) {
172-
AnalysisEngine.instance.instrumentationService.logException(
173-
CaughtException.withMessage(
174-
'Failed to send notification', exception, stackTrace));
175-
}
176-
});
168+
try {
169+
f();
170+
} catch (exception, stackTrace) {
171+
AnalysisEngine.instance.instrumentationService.logException(
172+
CaughtException.withMessage(
173+
'Failed to send notification', exception, stackTrace));
174+
}
177175
}

0 commit comments

Comments
 (0)