@@ -16,7 +16,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
1616import { EditorContextKeys } from 'vs/editor/common/editorContextKeys' ;
1717import { DocumentRangeFormattingEditProviderRegistry , OnTypeFormattingEditProviderRegistry } from 'vs/editor/common/modes' ;
1818import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService' ;
19- import { getOnTypeFormattingEdits , formatDocumentWithProvider , formatDocumentRangeWithProvider , alertFormattingEdits , getRealAndSyntheticDocumentFormattersOrdered } from 'vs/editor/contrib/format/format' ;
19+ import { getOnTypeFormattingEdits , alertFormattingEdits , formatDocumentRangeWithFirstProvider , formatDocumentWithFirstProvider } from 'vs/editor/contrib/format/format' ;
2020import { FormattingEdit } from 'vs/editor/contrib/format/formattingEdit' ;
2121import * as nls from 'vs/nls' ;
2222import { CommandsRegistry , ICommandService } from 'vs/platform/commands/common/commands' ;
@@ -211,12 +211,7 @@ class FormatOnPaste implements editorCommon.IEditorContribution {
211211 if ( this . editor . getSelections ( ) . length > 1 ) {
212212 return ;
213213 }
214- const provider = DocumentRangeFormattingEditProviderRegistry . ordered ( this . editor . getModel ( ) ) ;
215- if ( provider . length !== 1 ) {
216- // print status in n>1 case?
217- return ;
218- }
219- this . _instantiationService . invokeFunction ( formatDocumentRangeWithProvider , provider [ 0 ] , this . editor , range , CancellationToken . None ) . catch ( onUnexpectedError ) ;
214+ this . _instantiationService . invokeFunction ( formatDocumentRangeWithFirstProvider , this . editor , range , CancellationToken . None ) . catch ( onUnexpectedError ) ;
220215 }
221216}
222217
@@ -227,7 +222,7 @@ class FormatDocumentAction extends EditorAction {
227222 id : 'editor.action.formatDocument' ,
228223 label : nls . localize ( 'formatDocument.label' , "Format Document" ) ,
229224 alias : 'Format Document' ,
230- precondition : ContextKeyExpr . and ( EditorContextKeys . writable , EditorContextKeys . hasDocumentFormattingProvider , EditorContextKeys . hasMultipleDocumentFormattingProvider . toNegated ( ) ) ,
225+ precondition : ContextKeyExpr . and ( EditorContextKeys . writable , EditorContextKeys . hasDocumentFormattingProvider ) ,
231226 kbOpts : {
232227 kbExpr : ContextKeyExpr . and ( EditorContextKeys . editorTextFocus , EditorContextKeys . hasDocumentFormattingProvider ) ,
233228 primary : KeyMod . Shift | KeyMod . Alt | KeyCode . KEY_F ,
@@ -243,14 +238,9 @@ class FormatDocumentAction extends EditorAction {
243238 }
244239
245240 async run ( accessor : ServicesAccessor , editor : ICodeEditor ) : Promise < void > {
246- if ( ! editor . hasModel ( ) ) {
247- return ;
248- }
249- const instaService = accessor . get ( IInstantiationService ) ;
250- const model = editor . getModel ( ) ;
251- const [ provider ] = getRealAndSyntheticDocumentFormattersOrdered ( model ) ;
252- if ( provider ) {
253- await instaService . invokeFunction ( formatDocumentWithProvider , provider , editor , CancellationToken . None ) ;
241+ if ( editor . hasModel ( ) ) {
242+ const instaService = accessor . get ( IInstantiationService ) ;
243+ await instaService . invokeFunction ( formatDocumentWithFirstProvider , editor , CancellationToken . None ) ;
254244 }
255245 }
256246}
@@ -262,7 +252,7 @@ class FormatSelectionAction extends EditorAction {
262252 id : 'editor.action.formatSelection' ,
263253 label : nls . localize ( 'formatSelection.label' , "Format Selection" ) ,
264254 alias : 'Format Code' ,
265- precondition : ContextKeyExpr . and ( EditorContextKeys . writable , EditorContextKeys . hasDocumentSelectionFormattingProvider , EditorContextKeys . hasMultipleDocumentSelectionFormattingProvider . toNegated ( ) ) ,
255+ precondition : ContextKeyExpr . and ( EditorContextKeys . writable , EditorContextKeys . hasDocumentSelectionFormattingProvider ) ,
266256 kbOpts : {
267257 kbExpr : ContextKeyExpr . and ( EditorContextKeys . editorTextFocus , EditorContextKeys . hasDocumentSelectionFormattingProvider ) ,
268258 primary : KeyChord ( KeyMod . CtrlCmd | KeyCode . KEY_K , KeyMod . CtrlCmd | KeyCode . KEY_F ) ,
@@ -281,14 +271,12 @@ class FormatSelectionAction extends EditorAction {
281271 return ;
282272 }
283273 const instaService = accessor . get ( IInstantiationService ) ;
284- const [ best ] = DocumentRangeFormattingEditProviderRegistry . ordered ( editor . getModel ( ) ) ;
285- if ( best ) {
286- let range : Range = editor . getSelection ( ) ;
287- if ( range . isEmpty ( ) ) {
288- range = new Range ( range . startLineNumber , 1 , range . startLineNumber , editor . getModel ( ) . getLineMaxColumn ( range . startLineNumber ) ) ;
289- }
290- await instaService . invokeFunction ( formatDocumentRangeWithProvider , best , editor , range , CancellationToken . None ) ;
274+ const model = editor . getModel ( ) ;
275+ let range : Range = editor . getSelection ( ) ;
276+ if ( range . isEmpty ( ) ) {
277+ range = new Range ( range . startLineNumber , 1 , range . startLineNumber , model . getLineMaxColumn ( range . startLineNumber ) ) ;
291278 }
279+ await instaService . invokeFunction ( formatDocumentRangeWithFirstProvider , editor , range , CancellationToken . None ) ;
292280 }
293281}
294282
0 commit comments