@@ -23,8 +23,29 @@ export function create(): LanguageServicePlugin {
23
23
sfcDataProvider ??= html . newHTMLDataProvider ( 'vue' , loadLanguageBlocks ( context . env . locale ?? 'en' ) ) ;
24
24
return [ sfcDataProvider ] ;
25
25
} ,
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
+ } ,
26
48
} ) . create ( context ) ;
27
- const htmlLanguageService : html . LanguageService = htmlPlugin . provide [ 'html/languageService' ] ( ) ;
28
49
29
50
return {
30
51
@@ -148,28 +169,6 @@ export function create(): LanguageServicePlugin {
148
169
return result ;
149
170
} ) ;
150
171
} ,
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
- } ,
173
172
} ;
174
173
175
174
function worker < T > ( document : TextDocument , callback : ( vueSourceFile : vue . VueGeneratedCode ) => T ) {
0 commit comments