mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
use editor for format on save and honor silent mode
This commit is contained in:
committed by
Karl Burtram
parent
e9d04d75ac
commit
7ebf746584
@@ -214,7 +214,7 @@ export async function formatDocumentWithSelectedProvider(
|
|||||||
const provider = getRealAndSyntheticDocumentFormattersOrdered(model);
|
const provider = getRealAndSyntheticDocumentFormattersOrdered(model);
|
||||||
const selected = await FormattingConflicts.select(provider, model, mode);
|
const selected = await FormattingConflicts.select(provider, model, mode);
|
||||||
if (selected) {
|
if (selected) {
|
||||||
await instaService.invokeFunction(formatDocumentWithProvider, selected, editorOrModel, token);
|
await instaService.invokeFunction(formatDocumentWithProvider, selected, editorOrModel, mode, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,6 +222,7 @@ export async function formatDocumentWithProvider(
|
|||||||
accessor: ServicesAccessor,
|
accessor: ServicesAccessor,
|
||||||
provider: DocumentFormattingEditProvider,
|
provider: DocumentFormattingEditProvider,
|
||||||
editorOrModel: ITextModel | IActiveCodeEditor,
|
editorOrModel: ITextModel | IActiveCodeEditor,
|
||||||
|
mode: FormattingMode,
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const workerService = accessor.get(IEditorWorkerService);
|
const workerService = accessor.get(IEditorWorkerService);
|
||||||
@@ -257,10 +258,13 @@ export async function formatDocumentWithProvider(
|
|||||||
if (isCodeEditor(editorOrModel)) {
|
if (isCodeEditor(editorOrModel)) {
|
||||||
// use editor to apply edits
|
// use editor to apply edits
|
||||||
FormattingEdit.execute(editorOrModel, edits);
|
FormattingEdit.execute(editorOrModel, edits);
|
||||||
alertFormattingEdits(edits);
|
|
||||||
editorOrModel.pushUndoStop();
|
if (mode !== FormattingMode.Silent) {
|
||||||
editorOrModel.focus();
|
alertFormattingEdits(edits);
|
||||||
editorOrModel.revealPositionInCenterIfOutsideViewport(editorOrModel.getPosition(), editorCommon.ScrollType.Immediate);
|
editorOrModel.pushUndoStop();
|
||||||
|
editorOrModel.focus();
|
||||||
|
editorOrModel.revealPositionInCenterIfOutsideViewport(editorOrModel.getPosition(), editorCommon.ScrollType.Immediate);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// use model to apply edits
|
// use model to apply edits
|
||||||
|
|||||||
@@ -240,6 +240,7 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@IConfigurationService private readonly _configurationService: IConfigurationService,
|
@IConfigurationService private readonly _configurationService: IConfigurationService,
|
||||||
|
@ICodeEditorService private readonly _codeEditorService: ICodeEditorService,
|
||||||
@IInstantiationService private readonly _instantiationService: IInstantiationService,
|
@IInstantiationService private readonly _instantiationService: IInstantiationService,
|
||||||
) {
|
) {
|
||||||
// Nothing
|
// Nothing
|
||||||
@@ -256,8 +257,9 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant {
|
|||||||
|
|
||||||
return new Promise<any>((resolve, reject) => {
|
return new Promise<any>((resolve, reject) => {
|
||||||
const source = new CancellationTokenSource();
|
const source = new CancellationTokenSource();
|
||||||
|
const editorOrModel = findEditor(model, this._codeEditorService) || model;
|
||||||
const timeout = this._configurationService.getValue<number>('editor.formatOnSaveTimeout', overrides);
|
const timeout = this._configurationService.getValue<number>('editor.formatOnSaveTimeout', overrides);
|
||||||
const request = this._instantiationService.invokeFunction(formatDocumentWithSelectedProvider, model, FormattingMode.Silent, source.token);
|
const request = this._instantiationService.invokeFunction(formatDocumentWithSelectedProvider, editorOrModel, FormattingMode.Silent, source.token);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
reject(localize('timeout.formatOnSave', "Aborted format on save after {0}ms", timeout));
|
reject(localize('timeout.formatOnSave', "Aborted format on save after {0}ms", timeout));
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ registerEditorAction(class FormatDocumentMultipleAction extends EditorAction {
|
|||||||
const provider = getRealAndSyntheticDocumentFormattersOrdered(model);
|
const provider = getRealAndSyntheticDocumentFormattersOrdered(model);
|
||||||
const pick = await instaService.invokeFunction(showFormatterPick, model, provider);
|
const pick = await instaService.invokeFunction(showFormatterPick, model, provider);
|
||||||
if (pick) {
|
if (pick) {
|
||||||
await instaService.invokeFunction(formatDocumentWithProvider, provider[pick], editor, CancellationToken.None);
|
await instaService.invokeFunction(formatDocumentWithProvider, provider[pick], editor, FormattingMode.Explicit, CancellationToken.None);
|
||||||
}
|
}
|
||||||
logFormatterTelemetry(telemetryService, 'document', provider, typeof pick === 'number' && provider[pick] || undefined);
|
logFormatterTelemetry(telemetryService, 'document', provider, typeof pick === 'number' && provider[pick] || undefined);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user