@@ -57,6 +57,22 @@ class MissingToolError extends Error {
57
57
}
58
58
}
59
59
60
+ /**
61
+ * Call a process asynchronously.
62
+ * While doing so, update the windows with progress information.
63
+ * If you need to run a process, consider preferring this over running
64
+ * the command directly.
65
+ *
66
+ * @param binary Name of the binary to invoke.
67
+ * @param args Arguments passed directly to the binary.
68
+ * @param dir Directory in which the process shall be executed.
69
+ * @param logger Logger for progress updates.
70
+ * @param title Title of the action, shown to users if available.
71
+ * @param cancellable Can the user cancel this process invocation?
72
+ * @param envAdd Extra environment variables for this process only.
73
+ * @param callback Upon process termination, execute this callback. If given, must resolve promise.
74
+ * @returns Stdout of the process invocation, trimmed off newlines, or whatever the `callback` resolved to.
75
+ */
60
76
async function callAsync (
61
77
binary : string ,
62
78
args : string [ ] ,
@@ -133,7 +149,14 @@ async function callAsync(
133
149
134
150
/**
135
151
* Downloads the latest haskell-language-server binaries via ghcup.
136
- * Returns null if it can't find any match.
152
+ * If we figure out the correct GHC version, but it isn't compatible with
153
+ * the latest HLS executables, we download the latest compatible HLS binaries
154
+ * as a fallback.
155
+ *
156
+ * @param context Context of the extension, required for metadata.
157
+ * @param logger Logger for progress updates.
158
+ * @param workingDir Directory in which the process shall be executed.
159
+ * @returns Path to haskell-language-server-wrapper
137
160
*/
138
161
export async function downloadHaskellLanguageServer (
139
162
context : ExtensionContext ,
@@ -318,17 +341,25 @@ export async function validateHLSToolchain(
318
341
}
319
342
}
320
343
321
- // also serves as sanity check
344
+ /**
345
+ * Obtain the project ghc version from the HLS - Wrapper.
346
+ * Also, serves as a sanity check.
347
+ * @param wrapper Path to the Haskell-Language-Server wrapper
348
+ * @param workingDir Directory to run the process, usually the root of the workspace.
349
+ * @param logger Logger for feedback.
350
+ * @returns The GHC version, or fail with an `Error`.
351
+ */
322
352
export async function getProjectGHCVersion (
323
353
wrapper : string ,
324
354
workingDir : string ,
325
355
logger : Logger
326
- ) : Promise < string | null > {
356
+ ) : Promise < string > {
327
357
const title = 'Working out the project GHC version. This might take a while...' ;
328
358
logger . info ( title ) ;
329
359
const args = [ '--project-ghc-version' ] ;
330
- const callWrapper = ( ) =>
331
- callAsync ( wrapper , args , workingDir , logger , title , false , undefined , ( err , stdout , stderr , resolve , reject ) => {
360
+
361
+ return callAsync ( wrapper , args , workingDir , logger , title , false , undefined ,
362
+ ( err , stdout , stderr , resolve , reject ) => {
332
363
const command : string = wrapper + ' ' + args . join ( ' ' ) ;
333
364
if ( err ) {
334
365
logger . error ( `Error executing '${ command } ' with error code ${ err . code } ` ) ;
@@ -348,9 +379,8 @@ export async function getProjectGHCVersion(
348
379
logger . info ( `The GHC version for the project or file: ${ stdout ?. trim ( ) } ` ) ;
349
380
resolve ( stdout ?. trim ( ) ) ;
350
381
}
351
- } ) ;
352
-
353
- return callWrapper ( ) ;
382
+ }
383
+ ) ;
354
384
}
355
385
356
386
/**
@@ -406,6 +436,14 @@ export async function downloadGHCup(context: ExtensionContext, logger: Logger):
406
436
return ghcup ;
407
437
}
408
438
439
+ /**
440
+ * Compare the PVP versions of two strings.
441
+ * Details: https://github.com/haskell/pvp/
442
+ *
443
+ * @param l First version
444
+ * @param r second version
445
+ * @returns `1` if l is newer than r, `0` if they are equal and `-1` otherwise.
446
+ */
409
447
export function comparePVP ( l : string , r : string ) : number {
410
448
const al = l . split ( '.' ) ;
411
449
const ar = r . split ( '.' ) ;
@@ -456,6 +494,16 @@ export function addPathToProcessPath(extraPath: string): string {
456
494
return PATH . join ( pathSep ) ;
457
495
}
458
496
497
+ /**
498
+ * Given a GHC version, download at least one HLS version that can be used.
499
+ * This also honours the OS architecture we are on.
500
+ *
501
+ * @param context Context of the extension, required for metadata.
502
+ * @param storagePath Path to store binaries, caching information, etc...
503
+ * @param targetGhc GHC version we want a HLS for.
504
+ * @param logger Logger for feedback
505
+ * @returns
506
+ */
459
507
async function getLatestHLSforGHC (
460
508
context : ExtensionContext ,
461
509
storagePath : string ,
@@ -507,6 +555,14 @@ async function getLatestHLSforGHC(
507
555
return curHls ;
508
556
}
509
557
558
+ /**
559
+ * Download GHCUP metadata.
560
+ *
561
+ * @param context Extension context.
562
+ * @param storagePath Path to put in binary files and caches.
563
+ * @param logger Logger for feedback.
564
+ * @returns Metadata of releases, or null if the cache can not be found.
565
+ */
510
566
async function getReleaseMetadata (
511
567
context : ExtensionContext ,
512
568
storagePath : string ,
0 commit comments