@@ -3,7 +3,8 @@ import Current from "./Current";
3
3
4
4
enum FormatErrorInteraction {
5
5
configure = "Configure" ,
6
- reset = "Reset"
6
+ reset = "Reset" ,
7
+ howTo = "How?"
7
8
}
8
9
9
10
enum UnknownErrorInteraction {
@@ -14,21 +15,32 @@ export async function handleFormatError(
14
15
error : any ,
15
16
document : vscode . TextDocument
16
17
) {
17
- if ( error . code === "ENOENT" ) {
18
+ function matches ( ...codeOrStatus : Array < number | string > ) {
19
+ return codeOrStatus . some ( c => c === error . code || c === error . status ) ;
20
+ }
21
+ if ( matches ( "ENOENT" , 127 ) ) {
18
22
const selection = await Current . editor . showErrorMessage (
19
- `Could not find SwiftFormat: ${ Current . config . swiftFormatPath ( document ) } ` ,
23
+ `Could not find SwiftFormat: ${ Current . config
24
+ . swiftFormatPath ( document )
25
+ ?. join ( " " ) } .\nEnsure it is installed and in your PATH.`,
20
26
FormatErrorInteraction . reset ,
21
- FormatErrorInteraction . configure
27
+ FormatErrorInteraction . configure ,
28
+ FormatErrorInteraction . howTo
22
29
) ;
23
30
switch ( selection ) {
24
31
case FormatErrorInteraction . reset :
25
- await Current . config . resetSwiftFormatPath ( ) ;
32
+ Current . config . resetSwiftFormatPath ( ) ;
26
33
break ;
27
34
case FormatErrorInteraction . configure :
28
- await Current . config . configureSwiftFormatPath ( ) ;
35
+ Current . config . configureSwiftFormatPath ( ) ;
36
+ break ;
37
+ case FormatErrorInteraction . howTo :
38
+ await Current . editor . openURL (
39
+ "https://github.com/nicklockwood/SwiftFormat#command-line-tool"
40
+ ) ;
29
41
break ;
30
42
}
31
- } else if ( error . status === 70 ) {
43
+ } else if ( matches ( 70 ) ) {
32
44
await Current . editor . showErrorMessage (
33
45
`SwiftFormat failed. ${ error . stderr || "" } `
34
46
) ;
0 commit comments