From 5784b254600f47e5a6b97c886780a0eb90092e63 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Fri, 25 Mar 2022 19:25:19 +0100 Subject: [PATCH 1/2] Improve plugin initialization --- package.json | 2 +- src/hlsBinaries.ts | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index fc8d7656..71dbdc5b 100644 --- a/package.json +++ b/package.json @@ -166,7 +166,7 @@ "haskell.manageHLS": { "scope": "resource", "type": "string", - "default": null, + "default": "PATH", "description": "How to manage/find HLS installations.", "enum": [ "GHCup", diff --git a/src/hlsBinaries.ts b/src/hlsBinaries.ts index e6e327f4..93d606fc 100644 --- a/src/hlsBinaries.ts +++ b/src/hlsBinaries.ts @@ -30,7 +30,7 @@ export { IEnvVars }; export type ReleaseMetadata = Map>>; type ManageHLS = 'GHCup' | 'PATH'; -let manageHLS = workspace.getConfiguration('haskell').get('manageHLS') as ManageHLS | null; +let manageHLS = workspace.getConfiguration('haskell').get('manageHLS') as ManageHLS; // On Windows the executable needs to be stored somewhere with an .exe extension const exeExt = process.platform === 'win32' ? '.exe' : ''; @@ -239,12 +239,14 @@ export async function findHaskellLanguageServer( fs.mkdirSync(storagePath); } - if (!manageHLS) { - // plugin needs initialization + + // first plugin initialization + if (manageHLS !== 'GHCup' && !context.globalState.get("pluginInitialized") as boolean | null) { const promptMessage = 'How do you want the extension to manage/discover HLS and the relevant toolchain?'; - const decision = - (await window.showInformationMessage(promptMessage, 'Automatically via GHCup', 'Manually via PATH')) || null; + const popup = window.showInformationMessage(promptMessage, 'Automatically via GHCup', 'Manually via PATH'); + + const decision = (await popup) || null; if (decision === 'Automatically via GHCup') { manageHLS = 'GHCup'; } else if (decision === 'Manually via PATH') { @@ -256,9 +258,10 @@ export async function findHaskellLanguageServer( manageHLS = 'PATH'; } workspace.getConfiguration('haskell').update('manageHLS', manageHLS, ConfigurationTarget.Global); + context.globalState.update("pluginInitialized", true); } - if (manageHLS === 'PATH' || manageHLS === null) { + if (manageHLS === 'PATH') { return findHLSinPATH(context, logger, folder); } else { // we manage HLS, make sure ghcup is installed/available From 04a593837ff4c21cf4fa6f59b28ac916c018ce00 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Fri, 25 Mar 2022 19:27:17 +0100 Subject: [PATCH 2/2] Avoid running `tool --numeric-version` --- src/hlsBinaries.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/hlsBinaries.ts b/src/hlsBinaries.ts index 93d606fc..55cf3b74 100644 --- a/src/hlsBinaries.ts +++ b/src/hlsBinaries.ts @@ -553,15 +553,7 @@ async function getLatestToolFromGHCup(context: ExtensionContext, logger: Logger, ); const latestInstalled = installedVersions.split(/\r?\n/).pop(); if (latestInstalled) { - const latestInstalledVersion = latestInstalled.split(/\s+/)[1]; - - const bin = await callGHCup(context, logger, ['whereis', tool, `${latestInstalledVersion}`], undefined, false); - const ver = await callAsync(`${bin}`, ['--numeric-version'], logger, undefined, undefined, false); - if (ver) { - return ver; - } else { - throw new Error(`Could not figure out version of ${bin}`); - } + return latestInstalled.split(/\s+/)[1]; } return getLatestAvailableToolFromGHCup(context, logger, tool);