@@ -23,8 +23,29 @@ export function create(): LanguageServicePlugin {
2323 sfcDataProvider ??= html . newHTMLDataProvider ( 'vue' , loadLanguageBlocks ( context . env . locale ?? 'en' ) ) ;
2424 return [ sfcDataProvider ] ;
2525 } ,
26+ async getFormattingOptions ( document , options , context ) {
27+ return await worker ( document , async vueCode => {
28+
29+ const formatSettings = await context . env . getConfiguration ?.< html . HTMLFormatConfiguration > ( 'html.format' ) ?? { } ;
30+ const blockTypes = [ 'template' , 'script' , 'style' ] ;
31+
32+ for ( const customBlock of vueCode . sfc . customBlocks ) {
33+ blockTypes . push ( customBlock . type ) ;
34+ }
35+
36+ return {
37+ ...options ,
38+ ...formatSettings ,
39+ wrapAttributes : 'auto' ,
40+ unformatted : '' ,
41+ contentUnformatted : blockTypes . join ( ',' ) ,
42+ endWithNewline : options . insertFinalNewline ? true
43+ : options . trimFinalNewlines ? false
44+ : document . getText ( ) . endsWith ( '\n' ) ,
45+ } ;
46+ } ) ?? { } ;
47+ } ,
2648 } ) . create ( context ) ;
27- const htmlLanguageService : html . LanguageService = htmlPlugin . provide [ 'html/languageService' ] ( ) ;
2849
2950 return {
3051
@@ -148,28 +169,6 @@ export function create(): LanguageServicePlugin {
148169 return result ;
149170 } ) ;
150171 } ,
151-
152- provideDocumentFormattingEdits ( document , range , options ) {
153- return worker ( document , async vueCode => {
154-
155- const formatSettings = await context . env . getConfiguration ?.< html . HTMLFormatConfiguration > ( 'html.format' ) ?? { } ;
156- const blockTypes = [ 'template' , 'script' , 'style' ] ;
157-
158- for ( const customBlock of vueCode . sfc . customBlocks ) {
159- blockTypes . push ( customBlock . type ) ;
160- }
161-
162- return htmlLanguageService . format ( document , range , {
163- ...options ,
164- ...formatSettings ,
165- unformatted : '' ,
166- contentUnformatted : blockTypes . join ( ',' ) ,
167- endWithNewline : options . insertFinalNewline ? true
168- : options . trimFinalNewlines ? false
169- : document . getText ( ) . endsWith ( '\n' ) ,
170- } ) ;
171- } ) ;
172- } ,
173172 } ;
174173
175174 function worker < T > ( document : TextDocument , callback : ( vueSourceFile : vue . VueGeneratedCode ) => T ) {
0 commit comments