@@ -116,12 +116,12 @@ async function getProjectGhcVersion(
116
116
async ( progress , token ) => {
117
117
return new Promise < string > ( ( resolve , reject ) => {
118
118
const command : string = wrapper + ' --project-ghc-version' ;
119
- logger . info ( `Executing '${ command } ' in cwd ${ dir } to get the project ghc version` ) ;
119
+ logger . info ( `Executing '${ command } ' in cwd ' ${ dir } ' to get the project or file ghc version` ) ;
120
120
token . onCancellationRequested ( ( ) => {
121
- logger . warn ( `User canceled the executon of '${ command } '` ) ;
121
+ logger . warn ( `User canceled the execution of '${ command } '` ) ;
122
122
} ) ;
123
123
// Need to set the encoding to 'utf8' in order to get back a string
124
- // We execute the command in a shell for windows, to allow use cmd or bat scripts
124
+ // We execute the command in a shell for windows, to allow use . cmd or . bat scripts
125
125
const childProcess = child_process
126
126
. execFile (
127
127
command ,
@@ -130,25 +130,33 @@ async function getProjectGhcVersion(
130
130
if ( err ) {
131
131
logger . error ( `Error executing '${ command } ' with error code ${ err . code } ` ) ;
132
132
logger . error ( `stderr: ${ stderr } ` ) ;
133
- logger . error ( `stdout: ${ stdout } ` ) ;
133
+ if ( stdout ) {
134
+ logger . error ( `stdout: ${ stdout } ` ) ;
135
+ }
134
136
const regex = / C r a d l e r e q u i r e s ( .+ ) b u t c o u l d n ' t f i n d i t / ;
135
137
const res = regex . exec ( stderr ) ;
136
138
if ( res ) {
137
- throw new MissingToolError ( res [ 1 ] ) ;
139
+ reject ( new MissingToolError ( res [ 1 ] ) ) ;
138
140
}
139
- throw Error (
140
- `${ wrapper } --project-ghc-version exited with exit code ${ err . code } :\n${ stdout } \n${ stderr } `
141
+ reject (
142
+ Error ( `${ wrapper } --project-ghc-version exited with exit code ${ err . code } :\n${ stdout } \n${ stderr } ` )
141
143
) ;
144
+ } else {
145
+ logger . info ( `The GHC version for the project or file: ${ stdout ?. trim ( ) } ` ) ;
146
+ resolve ( stdout ?. trim ( ) ) ;
142
147
}
143
- resolve ( stdout . trim ( ) ) ;
144
148
}
145
149
)
146
- . on ( 'close' , ( code , signal ) => {
147
- logger . info ( `Execution of '${ command } ' closed with code ${ code } and signal ${ signal } ` ) ;
150
+ . on ( 'exit' , ( code , signal ) => {
151
+ const msg =
152
+ `Execution of '${ command } ' terminated with code ${ code } ` + ( signal ? `and signal ${ signal } ` : '' ) ;
153
+ logger . info ( msg ) ;
148
154
} )
149
155
. on ( 'error' , ( err ) => {
150
- logger . error ( `Error executing '${ command } ': name = ${ err . name } , message = ${ err . message } ` ) ;
151
- throw err ;
156
+ if ( err ) {
157
+ logger . error ( `Error executing '${ command } ': name = ${ err . name } , message = ${ err . message } ` ) ;
158
+ reject ( err ) ;
159
+ }
152
160
} ) ;
153
161
token . onCancellationRequested ( ( _ ) => childProcess . kill ( ) ) ;
154
162
} ) ;
@@ -306,7 +314,7 @@ export async function downloadHaskellLanguageServer(
306
314
return null ;
307
315
}
308
316
logger . info ( `The latest release is ${ release . tag_name } ` ) ;
309
- logger . info ( ` Figure out the ghc version to use or advertise an installation link for missing components` ) ;
317
+ logger . info ( ' Figure out the ghc version to use or advertise an installation link for missing components' ) ;
310
318
const dir : string = folder ?. uri ?. fsPath ?? path . dirname ( resource . fsPath ) ;
311
319
let ghcVersion : string ;
312
320
try {
0 commit comments