mirror of
https://github.com/Microsoft/vscode
synced 2024-09-18 01:58:27 +00:00
Merge pull request #196619 from microsoft/merogge/format-cases
cover more cases of formatting, call accessible notification service notify
This commit is contained in:
commit
e06ad018da
|
@ -105,7 +105,8 @@ export async function formatDocumentRangesWithSelectedProvider(
|
||||||
rangeOrRanges: Range | Range[],
|
rangeOrRanges: Range | Range[],
|
||||||
mode: FormattingMode,
|
mode: FormattingMode,
|
||||||
progress: IProgress<DocumentRangeFormattingEditProvider>,
|
progress: IProgress<DocumentRangeFormattingEditProvider>,
|
||||||
token: CancellationToken
|
token: CancellationToken,
|
||||||
|
userGesture: boolean
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
|
||||||
const instaService = accessor.get(IInstantiationService);
|
const instaService = accessor.get(IInstantiationService);
|
||||||
|
@ -115,7 +116,7 @@ export async function formatDocumentRangesWithSelectedProvider(
|
||||||
const selected = await FormattingConflicts.select(provider, model, mode);
|
const selected = await FormattingConflicts.select(provider, model, mode);
|
||||||
if (selected) {
|
if (selected) {
|
||||||
progress.report(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,
|
provider: DocumentRangeFormattingEditProvider,
|
||||||
editorOrModel: ITextModel | IActiveCodeEditor,
|
editorOrModel: ITextModel | IActiveCodeEditor,
|
||||||
rangeOrRanges: Range | Range[],
|
rangeOrRanges: Range | Range[],
|
||||||
token: CancellationToken
|
token: CancellationToken,
|
||||||
|
userGesture: boolean
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const workerService = accessor.get(IEditorWorkerService);
|
const workerService = accessor.get(IEditorWorkerService);
|
||||||
const logService = accessor.get(ILogService);
|
const logService = accessor.get(ILogService);
|
||||||
|
const accessibleNotificationService = accessor.get(IAccessibleNotificationService);
|
||||||
|
|
||||||
let model: ITextModel;
|
let model: ITextModel;
|
||||||
let cts: CancellationTokenSource;
|
let cts: CancellationTokenSource;
|
||||||
|
@ -271,7 +274,7 @@ export async function formatDocumentRangesWithProvider(
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
accessibleNotificationService.notify(AccessibleNotificationEvent.Format, userGesture);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 { formatDocumentRangesWithSelectedProvider, formatDocumentWithSelectedProvider, FormattingMode, getOnTypeFormattingEdits } from 'vs/editor/contrib/format/browser/format';
|
||||||
import { FormattingEdit } from 'vs/editor/contrib/format/browser/formattingEdit';
|
import { FormattingEdit } from 'vs/editor/contrib/format/browser/formattingEdit';
|
||||||
import * as nls from 'vs/nls';
|
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 { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
|
||||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||||
|
@ -38,7 +39,8 @@ export class FormatOnType implements IEditorContribution {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _editor: ICodeEditor,
|
private readonly _editor: ICodeEditor,
|
||||||
@ILanguageFeaturesService private readonly _languageFeaturesService: ILanguageFeaturesService,
|
@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(_languageFeaturesService.onTypeFormattingEditProvider.onDidChange(this._update, this));
|
||||||
this._disposables.add(_editor.onDidChangeModel(() => this._update()));
|
this._disposables.add(_editor.onDidChangeModel(() => this._update()));
|
||||||
|
@ -141,6 +143,7 @@ export class FormatOnType implements IEditorContribution {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isNonEmptyArray(edits)) {
|
if (isNonEmptyArray(edits)) {
|
||||||
|
this._accessibleNotificationService.notify(AccessibleNotificationEvent.Format, false);
|
||||||
FormattingEdit.execute(this._editor, edits, true);
|
FormattingEdit.execute(this._editor, edits, true);
|
||||||
}
|
}
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
|
@ -202,7 +205,7 @@ class FormatOnPaste implements IEditorContribution {
|
||||||
if (this.editor.getSelections().length > 1) {
|
if (this.editor.getSelections().length > 1) {
|
||||||
return;
|
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);
|
const progressService = accessor.get(IEditorProgressService);
|
||||||
await progressService.showWhile(
|
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
|
250
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,7 +258,7 @@ class FormatOnSaveParticipant implements ITextFileSaveParticipant {
|
||||||
|
|
||||||
} else if (ranges) {
|
} else if (ranges) {
|
||||||
// formatted modified 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -405,7 +405,7 @@ registerEditorAction(class FormatSelectionMultipleAction extends EditorAction {
|
||||||
const provider = languageFeaturesService.documentRangeFormattingEditProvider.ordered(model);
|
const provider = languageFeaturesService.documentRangeFormattingEditProvider.ordered(model);
|
||||||
const pick = await instaService.invokeFunction(showFormatterPick, model, provider);
|
const pick = await instaService.invokeFunction(showFormatterPick, model, provider);
|
||||||
if (typeof pick === 'number') {
|
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);
|
logFormatterTelemetry(telemetryService, 'range', provider, typeof pick === 'number' && provider[pick] || undefined);
|
||||||
|
|
|
@ -42,7 +42,8 @@ registerEditorAction(class FormatModifiedAction extends EditorAction {
|
||||||
if (isNonEmptyArray(ranges)) {
|
if (isNonEmptyArray(ranges)) {
|
||||||
return instaService.invokeFunction(
|
return instaService.invokeFunction(
|
||||||
formatDocumentRangesWithSelectedProvider, editor, ranges,
|
formatDocumentRangesWithSelectedProvider, editor, ranges,
|
||||||
FormattingMode.Explicit, Progress.None, CancellationToken.None
|
FormattingMode.Explicit, Progress.None, CancellationToken.None,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue