Merge pull request #196619 from microsoft/merogge/format-cases

cover more cases of formatting, call accessible notification service notify
This commit is contained in:
Megan Rogge 2023-10-25 10:10:20 -07:00 committed by GitHub
commit e06ad018da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 10 deletions

View file

@ -105,7 +105,8 @@ export async function formatDocumentRangesWithSelectedProvider(
rangeOrRanges: Range | Range[],
mode: FormattingMode,
progress: IProgress<DocumentRangeFormattingEditProvider>,
token: CancellationToken
token: CancellationToken,
userGesture: boolean
): Promise<void> {
const instaService = accessor.get(IInstantiationService);
@ -115,7 +116,7 @@ export async function formatDocumentRangesWithSelectedProvider(
const selected = await FormattingConflicts.select(provider, model, mode);
if (selected) {
progress.report(selected);
await instaService.invokeFunction(formatDocumentRangesWithProvider, selected, editorOrModel, rangeOrRanges, token);
await instaService.invokeFunction(formatDocumentRangesWithProvider, selected, editorOrModel, rangeOrRanges, token, userGesture);
}
}
@ -124,10 +125,12 @@ export async function formatDocumentRangesWithProvider(
provider: DocumentRangeFormattingEditProvider,
editorOrModel: ITextModel | IActiveCodeEditor,
rangeOrRanges: Range | Range[],
token: CancellationToken
token: CancellationToken,
userGesture: boolean
): Promise<boolean> {
const workerService = accessor.get(IEditorWorkerService);
const logService = accessor.get(ILogService);
const accessibleNotificationService = accessor.get(IAccessibleNotificationService);
let model: ITextModel;
let cts: CancellationTokenSource;
@ -271,7 +274,7 @@ export async function formatDocumentRangesWithProvider(
return null;
});
}
accessibleNotificationService.notify(AccessibleNotificationEvent.Format, userGesture);
return true;
}

View file

@ -21,6 +21,7 @@ import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeat
import { formatDocumentRangesWithSelectedProvider, formatDocumentWithSelectedProvider, FormattingMode, getOnTypeFormattingEdits } from 'vs/editor/contrib/format/browser/format';
import { FormattingEdit } from 'vs/editor/contrib/format/browser/formattingEdit';
import * as nls from 'vs/nls';
import { AccessibleNotificationEvent, IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility';
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@ -38,7 +39,8 @@ export class FormatOnType implements IEditorContribution {
constructor(
private readonly _editor: ICodeEditor,
@ILanguageFeaturesService private readonly _languageFeaturesService: ILanguageFeaturesService,
@IEditorWorkerService private readonly _workerService: IEditorWorkerService
@IEditorWorkerService private readonly _workerService: IEditorWorkerService,
@IAccessibleNotificationService private readonly _accessibleNotificationService: IAccessibleNotificationService
) {
this._disposables.add(_languageFeaturesService.onTypeFormattingEditProvider.onDidChange(this._update, this));
this._disposables.add(_editor.onDidChangeModel(() => this._update()));
@ -141,6 +143,7 @@ export class FormatOnType implements IEditorContribution {
return;
}
if (isNonEmptyArray(edits)) {
this._accessibleNotificationService.notify(AccessibleNotificationEvent.Format, false);
FormattingEdit.execute(this._editor, edits, true);
}
}).finally(() => {
@ -202,7 +205,7 @@ class FormatOnPaste implements IEditorContribution {
if (this.editor.getSelections().length > 1) {
return;
}
this._instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, this.editor, range, FormattingMode.Silent, Progress.None, CancellationToken.None).catch(onUnexpectedError);
this._instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, this.editor, range, FormattingMode.Silent, Progress.None, CancellationToken.None, false).catch(onUnexpectedError);
}
}
@ -275,7 +278,7 @@ class FormatSelectionAction extends EditorAction {
const progressService = accessor.get(IEditorProgressService);
await progressService.showWhile(
instaService.invokeFunction(formatDocumentRangesWithSelectedProvider, editor, ranges, FormattingMode.Explicit, Progress.None, CancellationToken.None),
instaService.invokeFunction(formatDocumentRangesWithSelectedProvider, editor, ranges, FormattingMode.Explicit, Progress.None, CancellationToken.None, true),
250
);
}

View file

@ -258,7 +258,7 @@ class FormatOnSaveParticipant implements ITextFileSaveParticipant {
} else if (ranges) {
// formatted modified ranges
await this.instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, editorOrModel, ranges, FormattingMode.Silent, nestedProgress, token);
await this.instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, editorOrModel, ranges, FormattingMode.Silent, nestedProgress, token, false);
}
}
}

View file

@ -405,7 +405,7 @@ registerEditorAction(class FormatSelectionMultipleAction extends EditorAction {
const provider = languageFeaturesService.documentRangeFormattingEditProvider.ordered(model);
const pick = await instaService.invokeFunction(showFormatterPick, model, provider);
if (typeof pick === 'number') {
await instaService.invokeFunction(formatDocumentRangesWithProvider, provider[pick], editor, range, CancellationToken.None);
await instaService.invokeFunction(formatDocumentRangesWithProvider, provider[pick], editor, range, CancellationToken.None, true);
}
logFormatterTelemetry(telemetryService, 'range', provider, typeof pick === 'number' && provider[pick] || undefined);

View file

@ -42,7 +42,8 @@ registerEditorAction(class FormatModifiedAction extends EditorAction {
if (isNonEmptyArray(ranges)) {
return instaService.invokeFunction(
formatDocumentRangesWithSelectedProvider, editor, ranges,
FormattingMode.Explicit, Progress.None, CancellationToken.None
FormattingMode.Explicit, Progress.None, CancellationToken.None,
true
);
}
}