Skip to content

Commit 0146d78

Browse files
committed
Implement annoying download popups
1 parent 383fb8f commit 0146d78

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/hlsBinaries.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,37 @@ export async function findHaskellLanguageServer(
307307
: null;
308308
}
309309

310+
const dontAskOnDownload = context.globalState.get("dontAskOnDownload") as boolean | null;
311+
if (!dontAskOnDownload) {
312+
const hlsInstalled = await toolInstalled(context, logger, 'hls', latestHLS);
313+
const cabalInstalled = await toolInstalled(context, logger, 'cabal', latestCabal);
314+
const stackInstalled = await toolInstalled(context, logger, 'stack', latestStack);
315+
const ghcInstalled = await executableExists('ghc') ? [true, 'ghc', ''] as [boolean, string, string] : await toolInstalled(context, logger, 'ghc', recGHC!);
316+
const toInstall = [hlsInstalled, cabalInstalled, stackInstalled, ghcInstalled].filter(([b, t, v]) => !b).map(([_, t, v]) => `${t}-${v}`);
317+
logger.info(`toInstall length: ${toInstall.length}`)
318+
logger.info(`toInstall: ${toInstall}`)
319+
if (toInstall.length > 0) {
320+
const decision = await window.showInformationMessage(`Need to download ${toInstall.join(', ')}, continue?`, 'Yes', 'No', 'Yes, don\'t ask again');
321+
if (decision === 'Yes') {
322+
} else if (decision === 'Yes, don\'t ask again') {
323+
context.globalState.update("dontAskOnDownload", true);
324+
} else {
325+
[hlsInstalled, cabalInstalled, stackInstalled, ghcInstalled].forEach(([b, t]) => {
326+
if (!b) {
327+
if (t === 'hls') {
328+
throw new MissingToolError('hls');
329+
} else if (t === 'cabal') {
330+
latestCabal = null;
331+
} else if (t === 'stack') {
332+
latestStack = null;
333+
} else if (t === 'ghc') {
334+
recGHC = null;
335+
}
336+
}
337+
});
338+
}
339+
}
340+
}
310341
const latestToolchainBindir = await callGHCup(
311342
context,
312343
logger,
@@ -338,6 +369,31 @@ export async function findHaskellLanguageServer(
338369
}
339370
}
340371

372+
if (!dontAskOnDownload) {
373+
const hlsInstalled = await toolInstalled(context, logger, 'hls', projectHls);
374+
const ghcInstalled = await toolInstalled(context, logger, 'ghc', projectGhc);
375+
const toInstall = [hlsInstalled, ghcInstalled].filter(([b, t, v]) => !b).map(([_, t, v]) => `${t}-${v}`);
376+
logger.info(`toInstall length: ${toInstall.length}`)
377+
logger.info(`toInstall: ${toInstall}`)
378+
if (toInstall.length > 0) {
379+
const decision = await window.showInformationMessage(`Need to download ${toInstall.join(', ')}, continue?`, 'Yes', 'No', 'Yes, don\'t ask again');
380+
if (decision === 'Yes') {
381+
} else if (decision === 'Yes, don\'t ask again') {
382+
context.globalState.update("dontAskOnDownload", true);
383+
} else {
384+
[hlsInstalled, ghcInstalled].forEach(([b, t]) => {
385+
if (!b) {
386+
if (t === 'hls') {
387+
throw new MissingToolError('hls');
388+
} else if (t === 'ghc') {
389+
projectGhc = null;
390+
}
391+
}
392+
});
393+
}
394+
}
395+
}
396+
341397
// now install said version in an isolated symlink directory
342398
const hlsBinDir = await callGHCup(
343399
context,
@@ -666,6 +722,11 @@ async function getHLSesFromGHCup(context: ExtensionContext, logger: Logger): Pro
666722
}
667723
}
668724

725+
async function toolInstalled(context: ExtensionContext, logger: Logger, tool: string, version: string): Promise<[boolean, string, string]> {
726+
const b = await callGHCup(context, logger, ['whereis', tool, version], undefined, false).then(x => true).catch(x => false);
727+
return [b, tool, version];
728+
}
729+
669730
/**
670731
* Given a GHC version, download at least one HLS version that can be used.
671732
* This also honours the OS architecture we are on.

0 commit comments

Comments
 (0)