Skip to content

Commit e06ad01

Browse files
authored
Merge pull request microsoft#196619 from microsoft/merogge/format-cases
cover more cases of formatting, call accessible notification service notify
2 parents 267d00c + ae1953b commit e06ad01

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

src/vs/editor/contrib/format/browser/format.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ export async function formatDocumentRangesWithSelectedProvider(
105105
rangeOrRanges: Range | Range[],
106106
mode: FormattingMode,
107107
progress: IProgress<DocumentRangeFormattingEditProvider>,
108-
token: CancellationToken
108+
token: CancellationToken,
109+
userGesture: boolean
109110
): Promise<void> {
110111

111112
const instaService = accessor.get(IInstantiationService);
@@ -115,7 +116,7 @@ export async function formatDocumentRangesWithSelectedProvider(
115116
const selected = await FormattingConflicts.select(provider, model, mode);
116117
if (selected) {
117118
progress.report(selected);
118-
await instaService.invokeFunction(formatDocumentRangesWithProvider, selected, editorOrModel, rangeOrRanges, token);
119+
await instaService.invokeFunction(formatDocumentRangesWithProvider, selected, editorOrModel, rangeOrRanges, token, userGesture);
119120
}
120121
}
121122

@@ -124,10 +125,12 @@ export async function formatDocumentRangesWithProvider(
124125
provider: DocumentRangeFormattingEditProvider,
125126
editorOrModel: ITextModel | IActiveCodeEditor,
126127
rangeOrRanges: Range | Range[],
127-
token: CancellationToken
128+
token: CancellationToken,
129+
userGesture: boolean
128130
): Promise<boolean> {
129131
const workerService = accessor.get(IEditorWorkerService);
130132
const logService = accessor.get(ILogService);
133+
const accessibleNotificationService = accessor.get(IAccessibleNotificationService);
131134

132135
let model: ITextModel;
133136
let cts: CancellationTokenSource;
@@ -271,7 +274,7 @@ export async function formatDocumentRangesWithProvider(
271274
return null;
272275
});
273276
}
274-
277+
accessibleNotificationService.notify(AccessibleNotificationEvent.Format, userGesture);
275278
return true;
276279
}
277280

src/vs/editor/contrib/format/browser/formatActions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeat
2121
import { formatDocumentRangesWithSelectedProvider, formatDocumentWithSelectedProvider, FormattingMode, getOnTypeFormattingEdits } from 'vs/editor/contrib/format/browser/format';
2222
import { FormattingEdit } from 'vs/editor/contrib/format/browser/formattingEdit';
2323
import * as nls from 'vs/nls';
24+
import { AccessibleNotificationEvent, IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility';
2425
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
2526
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
2627
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -38,7 +39,8 @@ export class FormatOnType implements IEditorContribution {
3839
constructor(
3940
private readonly _editor: ICodeEditor,
4041
@ILanguageFeaturesService private readonly _languageFeaturesService: ILanguageFeaturesService,
41-
@IEditorWorkerService private readonly _workerService: IEditorWorkerService
42+
@IEditorWorkerService private readonly _workerService: IEditorWorkerService,
43+
@IAccessibleNotificationService private readonly _accessibleNotificationService: IAccessibleNotificationService
4244
) {
4345
this._disposables.add(_languageFeaturesService.onTypeFormattingEditProvider.onDidChange(this._update, this));
4446
this._disposables.add(_editor.onDidChangeModel(() => this._update()));
@@ -141,6 +143,7 @@ export class FormatOnType implements IEditorContribution {
141143
return;
142144
}
143145
if (isNonEmptyArray(edits)) {
146+
this._accessibleNotificationService.notify(AccessibleNotificationEvent.Format, false);
144147
FormattingEdit.execute(this._editor, edits, true);
145148
}
146149
}).finally(() => {
@@ -202,7 +205,7 @@ class FormatOnPaste implements IEditorContribution {
202205
if (this.editor.getSelections().length > 1) {
203206
return;
204207
}
205-
this._instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, this.editor, range, FormattingMode.Silent, Progress.None, CancellationToken.None).catch(onUnexpectedError);
208+
this._instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, this.editor, range, FormattingMode.Silent, Progress.None, CancellationToken.None, false).catch(onUnexpectedError);
206209
}
207210
}
208211

@@ -275,7 +278,7 @@ class FormatSelectionAction extends EditorAction {
275278

276279
const progressService = accessor.get(IEditorProgressService);
277280
await progressService.showWhile(
278-
instaService.invokeFunction(formatDocumentRangesWithSelectedProvider, editor, ranges, FormattingMode.Explicit, Progress.None, CancellationToken.None),
281+
instaService.invokeFunction(formatDocumentRangesWithSelectedProvider, editor, ranges, FormattingMode.Explicit, Progress.None, CancellationToken.None, true),
279282
250
280283
);
281284
}

src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class FormatOnSaveParticipant implements ITextFileSaveParticipant {
258258

259259
} else if (ranges) {
260260
// formatted modified ranges
261-
await this.instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, editorOrModel, ranges, FormattingMode.Silent, nestedProgress, token);
261+
await this.instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, editorOrModel, ranges, FormattingMode.Silent, nestedProgress, token, false);
262262
}
263263
}
264264
}

src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ registerEditorAction(class FormatSelectionMultipleAction extends EditorAction {
405405
const provider = languageFeaturesService.documentRangeFormattingEditProvider.ordered(model);
406406
const pick = await instaService.invokeFunction(showFormatterPick, model, provider);
407407
if (typeof pick === 'number') {
408-
await instaService.invokeFunction(formatDocumentRangesWithProvider, provider[pick], editor, range, CancellationToken.None);
408+
await instaService.invokeFunction(formatDocumentRangesWithProvider, provider[pick], editor, range, CancellationToken.None, true);
409409
}
410410

411411
logFormatterTelemetry(telemetryService, 'range', provider, typeof pick === 'number' && provider[pick] || undefined);

src/vs/workbench/contrib/format/browser/formatModified.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ registerEditorAction(class FormatModifiedAction extends EditorAction {
4242
if (isNonEmptyArray(ranges)) {
4343
return instaService.invokeFunction(
4444
formatDocumentRangesWithSelectedProvider, editor, ranges,
45-
FormattingMode.Explicit, Progress.None, CancellationToken.None
45+
FormattingMode.Explicit, Progress.None, CancellationToken.None,
46+
true
4647
);
4748
}
4849
}

0 commit comments

Comments
 (0)