Skip to content

Commit 2fea3c0

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Add progress reporting to "Fix all in Workspace" command
We already have support for sending progress from command handlers, but each handler has to send them explicitly (so we don't trigger progress notifications for trivial commands). This adds that to the "Fix all in Workspace" command. Fixes Dart-Code/Dart-Code#5773 Change-Id: I70d42357323ff88441d64098f96db5ee02e61dba Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460044 Commit-Queue: Keerti Parthasarathy <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Keerti Parthasarathy <[email protected]>
1 parent 76c35b2 commit 2fea3c0

File tree

3 files changed

+59
-29
lines changed

3 files changed

+59
-29
lines changed

pkg/analysis_server/lib/src/lsp/handlers/commands/fix_all_in_workspace.dart

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,35 @@ abstract class AbstractFixAllInWorkspaceCommandHandler
5858
var workspace = DartChangeWorkspace(await server.currentSessions);
5959
var processor = BulkFixProcessor(server.instrumentationService, workspace);
6060

61-
var result = await processor.fixErrors(
62-
server.contextManager.analysisContexts,
63-
);
64-
var errorMessage = result.errorMessage;
65-
if (errorMessage != null) {
66-
return error(ErrorCodes.RequestFailed, errorMessage);
67-
}
61+
progress.begin('Computing fixes…');
62+
try {
63+
var result = await processor.fixErrors(
64+
server.contextManager.analysisContexts,
65+
);
6866

69-
var changeBuilder = result.builder!;
70-
var change = changeBuilder.sourceChange;
71-
if (change.edits.isEmpty) {
72-
return success(null);
67+
var errorMessage = result.errorMessage;
68+
if (errorMessage != null) {
69+
return error(ErrorCodes.RequestFailed, errorMessage);
70+
}
71+
72+
var changeBuilder = result.builder!;
73+
var change = changeBuilder.sourceChange;
74+
if (change.edits.isEmpty) {
75+
return success(null);
76+
}
77+
78+
var edit = createWorkspaceEdit(
79+
server,
80+
clientCapabilities,
81+
change,
82+
annotateChanges: requireConfirmation
83+
? ChangeAnnotations.requireConfirmation
84+
: ChangeAnnotations.include,
85+
);
86+
return sendWorkspaceEditToClient(edit);
87+
} finally {
88+
progress.end();
7389
}
74-
75-
var edit = createWorkspaceEdit(
76-
server,
77-
clientCapabilities,
78-
change,
79-
annotateChanges: requireConfirmation
80-
? ChangeAnnotations.requireConfirmation
81-
: ChangeAnnotations.include,
82-
);
83-
return sendWorkspaceEditToClient(edit);
8490
}
8591
}
8692

pkg/analysis_server/test/lsp/commands/fix_all_in_workspace_test.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:test/test.dart';
1010
import 'package:test_reflective_loader/test_reflective_loader.dart';
1111

1212
import '../../tool/lsp_spec/matchers.dart';
13+
import '../request_helpers_mixin.dart';
1314
import '../server_abstract.dart';
1415

1516
void main() {
@@ -20,7 +21,8 @@ void main() {
2021
}
2122

2223
abstract class AbstractFixAllInWorkspaceTest
23-
extends AbstractLspAnalysisServerTest {
24+
extends AbstractLspAnalysisServerTest
25+
with LspProgressNotificationsMixin {
2426
String get commandId;
2527
String get commandName;
2628
bool get expectRequiresConfirmation;
@@ -229,6 +231,28 @@ C b() {
229231
''');
230232
}
231233

234+
Future<void> test_progressNotifications_supported() async {
235+
// Advertise that we (the client) support progress.
236+
setWorkDoneProgressSupport();
237+
238+
// Expect (during the test) a progress token to be created, started, ended.
239+
expect(progressUpdates, emitsInOrder(['CREATE', 'BEGIN', 'END']));
240+
241+
await initialize();
242+
await executeCommand(Command(command: commandId, title: 'UNUSED'));
243+
}
244+
245+
Future<void> test_progressNotifications_unsupported() async {
246+
// Advertise that we do not support progress.
247+
setWorkDoneProgressSupport(false);
248+
249+
// Expect no progress updates at all.
250+
expect(progressUpdates, neverEmits(anything));
251+
252+
await initialize();
253+
await executeCommand(Command(command: commandId, title: 'UNUSED'));
254+
}
255+
232256
Future<void> test_serverAdvertisesCommand() async {
233257
await initialize();
234258
expect(

pkg/analysis_server/test/lsp/server_abstract.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -771,9 +771,9 @@ mixin ClientCapabilitiesHelperMixin {
771771
setTextDocumentDynamicRegistration('synchronization');
772772
}
773773

774-
void setWorkDoneProgressSupport() {
774+
void setWorkDoneProgressSupport([bool supported = true]) {
775775
windowCapabilities = extendWindowCapabilities(windowCapabilities, {
776-
'workDoneProgress': true,
776+
'workDoneProgress': supported,
777777
});
778778
}
779779

@@ -826,7 +826,7 @@ mixin LspAnalysisServerTestMixin
826826
/// initialize.
827827
ServerCapabilities? _serverCapabilities;
828828

829-
final validProgressTokens = <ProgressToken>{};
829+
final _validProgressTokens = <ProgressToken>{};
830830

831831
/// Default initialization options to be used if [initialize] is not provided
832832
/// options explicitly.
@@ -1574,15 +1574,15 @@ mixin LspAnalysisServerTestMixin
15741574
request.params as Map<String, Object?>,
15751575
);
15761576
if (params.token != clientProvidedTestWorkDoneToken &&
1577-
!validProgressTokens.contains(params.token)) {
1577+
!_validProgressTokens.contains(params.token)) {
15781578
throw Exception(
15791579
'Server sent a progress notification for a token '
15801580
'that has not been created: ${params.token}',
15811581
);
15821582
}
15831583

15841584
if (WorkDoneProgressEnd.canParse(params.value, nullLspJsonReporter)) {
1585-
validProgressTokens.remove(params.token);
1585+
_validProgressTokens.remove(params.token);
15861586
}
15871587

15881588
if (params.token == analyzingProgressToken) {
@@ -1605,10 +1605,10 @@ mixin LspAnalysisServerTestMixin
16051605
var params = WorkDoneProgressCreateParams.fromJson(
16061606
request.params as Map<String, Object?>,
16071607
);
1608-
if (validProgressTokens.contains(params.token)) {
1608+
if (_validProgressTokens.contains(params.token)) {
16091609
throw Exception('Server tried to create already-active progress token');
16101610
}
1611-
validProgressTokens.add(params.token);
1611+
_validProgressTokens.add(params.token);
16121612
}
16131613

16141614
/// Checks whether a notification is likely an error from the server (for

0 commit comments

Comments
 (0)