Skip to content

Commit 2daf8c2

Browse files
committed
Improve documentation
1 parent a74e092 commit 2daf8c2

File tree

1 file changed

+64
-8
lines changed

1 file changed

+64
-8
lines changed

src/hlsBinaries.ts

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ class MissingToolError extends Error {
5757
}
5858
}
5959

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+
*/
6076
async function callAsync(
6177
binary: string,
6278
args: string[],
@@ -133,7 +149,14 @@ async function callAsync(
133149

134150
/**
135151
* 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
137160
*/
138161
export async function downloadHaskellLanguageServer(
139162
context: ExtensionContext,
@@ -318,17 +341,25 @@ export async function validateHLSToolchain(
318341
}
319342
}
320343

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+
*/
322352
export async function getProjectGHCVersion(
323353
wrapper: string,
324354
workingDir: string,
325355
logger: Logger
326-
): Promise<string | null> {
356+
): Promise<string> {
327357
const title = 'Working out the project GHC version. This might take a while...';
328358
logger.info(title);
329359
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) => {
332363
const command: string = wrapper + ' ' + args.join(' ');
333364
if (err) {
334365
logger.error(`Error executing '${command}' with error code ${err.code}`);
@@ -348,9 +379,8 @@ export async function getProjectGHCVersion(
348379
logger.info(`The GHC version for the project or file: ${stdout?.trim()}`);
349380
resolve(stdout?.trim());
350381
}
351-
});
352-
353-
return callWrapper();
382+
}
383+
);
354384
}
355385

356386
/**
@@ -406,6 +436,14 @@ export async function downloadGHCup(context: ExtensionContext, logger: Logger):
406436
return ghcup;
407437
}
408438

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+
*/
409447
export function comparePVP(l: string, r: string): number {
410448
const al = l.split('.');
411449
const ar = r.split('.');
@@ -456,6 +494,16 @@ export function addPathToProcessPath(extraPath: string): string {
456494
return PATH.join(pathSep);
457495
}
458496

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+
*/
459507
async function getLatestHLSforGHC(
460508
context: ExtensionContext,
461509
storagePath: string,
@@ -507,6 +555,14 @@ async function getLatestHLSforGHC(
507555
return curHls;
508556
}
509557

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+
*/
510566
async function getReleaseMetadata(
511567
context: ExtensionContext,
512568
storagePath: string,

0 commit comments

Comments
 (0)