66
77import { Range , Position , TextEdit , FormattingOptions } from 'vscode-languageserver-types' ;
88import { CustomFormatterOptions , LanguageSettings } from '../yamlLanguageService' ;
9- import * as prettier from 'prettier' ;
10- import { Options } from 'prettier' ;
11- import * as parser from 'prettier/parser-yaml' ;
9+ import { format , Options } from 'prettier' ;
10+ import * as parser from 'prettier/plugins/yaml' ;
1211import { TextDocument } from 'vscode-languageserver-textdocument' ;
1312
1413export class YAMLFormatter {
@@ -20,7 +19,10 @@ export class YAMLFormatter {
2019 }
2120 }
2221
23- public format ( document : TextDocument , options : Partial < FormattingOptions > & CustomFormatterOptions = { } ) : TextEdit [ ] {
22+ public async format (
23+ document : TextDocument ,
24+ options : Partial < FormattingOptions > & CustomFormatterOptions = { }
25+ ) : Promise < TextEdit [ ] > {
2426 if ( ! this . formatterEnabled ) {
2527 return [ ] ;
2628 }
@@ -43,7 +45,7 @@ export class YAMLFormatter {
4345 printWidth : options . printWidth ,
4446 } ;
4547
46- const formatted = prettier . format ( text , prettierOptions ) ;
48+ const formatted = await format ( text , prettierOptions ) ;
4749
4850 return [ TextEdit . replace ( Range . create ( Position . create ( 0 , 0 ) , document . positionAt ( text . length ) ) , formatted ) ] ;
4951 } catch ( error ) {
0 commit comments