Skip to content

Commit 21c0584

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Allow allowOverlappingHandlers to be controlled via initializationOptions
For troubleshooting, this allows the client to override this flag. I'd originally planned to use ClientConfiguration for this and allow it to be changed on-the-fly, however this can result in a mix of requests and therefore I decided it best to only support setting once during startup (which is part of initialization, and therefore before general requests start being sent). This will require some Dart-Code work to provide a value here (and without a value, it will always be the servers default). See #60440 Change-Id: Ie9843543d6d491afb046f3d1106211b7db852605 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419541 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 0476f21 commit 21c0584

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,14 @@ class LspAnalysisServer extends AnalysisServer {
422422
void handleClientConnection(
423423
ClientCapabilities capabilities,
424424
ClientInfo? clientInfo,
425-
Object? initializationOptions,
425+
Object? rawInitializationOptions,
426426
) {
427427
_clientCapabilities = LspClientCapabilities(capabilities);
428428
_clientInfo = clientInfo;
429-
_initializationOptions = LspInitializationOptions(initializationOptions);
429+
var initializationOptions =
430+
_initializationOptions = LspInitializationOptions(
431+
rawInitializationOptions,
432+
);
430433

431434
/// Enable virtual file support.
432435
var supportsVirtualFiles =
@@ -437,6 +440,16 @@ class LspAnalysisServer extends AnalysisServer {
437440
uriConverter = ClientUriConverter.withVirtualFileSupport(pathContext);
438441
}
439442

443+
// Set whether to allow interleaved requests.
444+
if (initializationOptions.allowOverlappingHandlers
445+
case var allowOverlappingHandlers?) {
446+
MessageScheduler.allowOverlappingHandlers = allowOverlappingHandlers;
447+
instrumentationService.logInfo(
448+
'MessageScheduler.allowOverlappingHandlers set to '
449+
'$allowOverlappingHandlers by LSP client initializationOptions',
450+
);
451+
}
452+
440453
performanceAfterStartup = ServerPerformance();
441454
performance = performanceAfterStartup!;
442455

@@ -1278,6 +1291,12 @@ class LspInitializationOptions {
12781291
final int? completionBudgetMilliseconds;
12791292
final bool allowOpenUri;
12801293

1294+
/// Whether the client has expressed an explicit preference for
1295+
/// overlapping message handlers.
1296+
///
1297+
/// If `null`, the server default will be used.
1298+
final bool? allowOverlappingHandlers;
1299+
12811300
/// A temporary flag passed by Dart-Code to enable using in-editor fixes for
12821301
/// the "dart fix" prompt.
12831302
///
@@ -1307,6 +1326,7 @@ class LspInitializationOptions {
13071326
completionBudgetMilliseconds =
13081327
options['completionBudgetMilliseconds'] as int?,
13091328
allowOpenUri = options['allowOpenUri'] == true,
1329+
allowOverlappingHandlers = options['allowOverlappingHandlers'] as bool?,
13101330
useInEditorDartFixPrompt = options['useInEditorDartFixPrompt'] == true;
13111331
}
13121332

pkg/analysis_server/test/lsp/initialization_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:analysis_server/src/analysis_server.dart' hide MessageType;
99
import 'package:analysis_server/src/lsp/constants.dart';
1010
import 'package:analysis_server/src/lsp/server_capabilities_computer.dart';
1111
import 'package:analysis_server/src/plugin/plugin_manager.dart';
12+
import 'package:analysis_server/src/server/message_scheduler.dart';
1213
import 'package:analyzer/file_system/memory_file_system.dart';
1314
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
1415
import 'package:language_server_protocol/json_parsing.dart';
@@ -27,6 +28,11 @@ void main() {
2728

2829
@reflectiveTest
2930
class InitializationTest extends AbstractLspAnalysisServerTest {
31+
/// The default value of [MessageScheduler.allowOverlappingHandlers] before
32+
/// and test sets it (so that [tearDown] can revert it).
33+
final allowOverlappingHandlersDefault =
34+
MessageScheduler.allowOverlappingHandlers;
35+
3036
/// Waits for any in-progress analysis context rebuild.
3137
///
3238
/// Pumps the event queue before and after, to ensure any server code that
@@ -93,6 +99,12 @@ class InitializationTest extends AbstractLspAnalysisServerTest {
9399
);
94100
}
95101

102+
@override
103+
Future<void> tearDown() async {
104+
await super.tearDown();
105+
MessageScheduler.allowOverlappingHandlers = allowOverlappingHandlersDefault;
106+
}
107+
96108
Future<void> test_blazeWorkspace() async {
97109
var workspacePath = '/home/user/ws';
98110
// Make it a Blaze workspace.
@@ -1051,6 +1063,30 @@ class InitializationTest extends AbstractLspAnalysisServerTest {
10511063
expect(server.contextManager.includedPaths, equals([projectFolderPath]));
10521064
}
10531065

1066+
Future<void> test_interleavedRequests_default() async {
1067+
await initialize(rootUri: projectFolderUri, initializationOptions: {});
1068+
expect(
1069+
MessageScheduler.allowOverlappingHandlers,
1070+
allowOverlappingHandlersDefault,
1071+
);
1072+
}
1073+
1074+
Future<void> test_interleavedRequests_explicitFalse() async {
1075+
await initialize(
1076+
rootUri: projectFolderUri,
1077+
initializationOptions: {'allowOverlappingHandlers': false},
1078+
);
1079+
expect(MessageScheduler.allowOverlappingHandlers, isFalse);
1080+
}
1081+
1082+
Future<void> test_interleavedRequests_explicitTrue() async {
1083+
await initialize(
1084+
rootUri: projectFolderUri,
1085+
initializationOptions: {'allowOverlappingHandlers': true},
1086+
);
1087+
expect(MessageScheduler.allowOverlappingHandlers, isTrue);
1088+
}
1089+
10541090
Future<void> test_invalidExperimental_commands() async {
10551091
await expectInvalidExperimentalParams({
10561092
'commands': 1,

0 commit comments

Comments
 (0)