File tree Expand file tree Collapse file tree 3 files changed +20
-6
lines changed Expand file tree Collapse file tree 3 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -212,16 +212,20 @@ let rename ~path ~line ~col ~newName =
212
212
213
213
let format ~path =
214
214
if Filename. check_suffix path " .res" then
215
- let {Res_driver. parsetree = structure; comments} =
215
+ let {Res_driver. parsetree = structure; comments; diagnostics } =
216
216
Res_driver. parsingEngine.parseImplementation ~for Printer:true
217
217
~filename: path
218
218
in
219
- Res_printer. printImplementation ! Res_cli.ResClflags. width structure comments
219
+ if List. length diagnostics > 0 then " "
220
+ else
221
+ Res_printer. printImplementation ! Res_cli.ResClflags. width structure
222
+ comments
220
223
else if Filename. check_suffix path " .resi" then
221
- let {Res_driver. parsetree = signature; comments} =
224
+ let {Res_driver. parsetree = signature; comments; diagnostics } =
222
225
Res_driver. parsingEngine.parseInterface ~for Printer:true ~filename: path
223
226
in
224
- Res_printer. printInterface ! Res_cli.ResClflags. width signature comments
227
+ if List. length diagnostics > 0 then " "
228
+ else Res_printer. printInterface ! Res_cli.ResClflags. width signature comments
225
229
else " "
226
230
227
231
let test ~path =
Original file line number Diff line number Diff line change @@ -466,7 +466,7 @@ function format(msg: p.RequestMessage): Array<m.Message> {
466
466
467
467
// code will always be defined here, even though technically it can be undefined
468
468
let code = getOpenedFileContent ( params . textDocument . uri ) ;
469
- let formattedResult = utils . formatUsingValidBscNativePath (
469
+ let formattedResult = utils . formatCode (
470
470
code ,
471
471
bscNativePath ,
472
472
extension === c . resiExt
Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ type execResult =
93
93
kind : "error" ;
94
94
error : string ;
95
95
} ;
96
- export let formatUsingValidBscNativePath = (
96
+ export let formatCode = (
97
97
code : string ,
98
98
bscNativePath : p . DocumentUri | null ,
99
99
isInterface : boolean
@@ -124,6 +124,16 @@ export let formatUsingValidBscNativePath = (
124
124
false
125
125
) ;
126
126
127
+ // The formatter returning an empty string means it couldn't format the
128
+ // sources, probably because of errors. In that case, we bail from
129
+ // formatting by returning the unformatted content.
130
+ if ( result === "" ) {
131
+ return {
132
+ kind : "success" ,
133
+ result : code ,
134
+ } ;
135
+ }
136
+
127
137
return {
128
138
kind : "success" ,
129
139
result,
You can’t perform that action at this time.
0 commit comments