Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve #558

Merged
merged 2 commits into from
Mar 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"haskell.manageHLS": {
"scope": "resource",
"type": "string",
"default": null,
"default": "PATH",
"description": "How to manage/find HLS installations.",
"enum": [
"GHCup",
Expand Down
25 changes: 10 additions & 15 deletions src/hlsBinaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export { IEnvVars };
export type ReleaseMetadata = Map<string, Map<string, Map<string, string[]>>>;

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' : '';
Expand Down Expand Up @@ -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') {
Expand All @@ -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
Expand Down Expand Up @@ -550,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);
Expand Down