Skip to content

Commit b2917ec

Browse files
committed
Don't download ghcup on 'internal-ghcup', fix docs
1 parent a006e23 commit b2917ec

File tree

3 files changed

+12
-54
lines changed

3 files changed

+12
-54
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@
168168
"PATH"
169169
],
170170
"enumDescriptions": [
171-
"Will use a user-wide installation of ghcup (usually in '~/.ghcup') to manage HLS automatically",
172-
"Will use an internal installation of ghcup to manage HLS automatically, to avoid interfering with system ghcup",
171+
"Will use ghcup and manage Haskell toolchain in the default location (usually '~/.ghcup')",
172+
"Will use ghcup and manage Haskell toolchain in an isolated VSCode specific location (to not interfere with system installations)",
173173
"Discovers HLS executables in system PATH"
174174
]
175175
},

src/hlsBinaries.ts

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
WorkspaceFolder,
1818
} from 'vscode';
1919
import { Logger } from 'vscode-languageclient';
20-
import { downloadFile, executableExists, httpsGetSilently, resolvePathPlaceHolders } from './utils';
20+
import { executableExists, httpsGetSilently, resolvePathPlaceHolders } from './utils';
2121

2222
export type ReleaseMetadata = Map<string, Map<string, Map<string, string[]>>>;
2323

@@ -461,57 +461,15 @@ export async function getProjectGHCVersion(toolchainBindir: string, workingDir:
461461
export async function getGHCup(context: ExtensionContext, logger: Logger): Promise<string | undefined> {
462462
logger.info('Checking for ghcup installation');
463463
const localGHCup = ['ghcup'].find(executableExists);
464+
if (!localGHCup) {
465+
throw new MissingToolError('ghcup');
466+
}
464467

465-
if (manageHLS === 'system-ghcup') {
466-
if (!localGHCup) {
467-
throw new MissingToolError('ghcup');
468-
} else {
469-
logger.info(`found system ghcup at ${localGHCup}`);
470-
const args = ['upgrade'];
471-
await callGHCup(context, logger, args, 'Upgrading ghcup', true);
472-
return localGHCup;
473-
}
474-
} else if (manageHLS === 'internal-ghcup') {
475-
const storagePath: string = await getStoragePath(context);
476-
let ghcup = path.join(storagePath, `ghcup${exeExt}`);
477-
if (!fs.existsSync(storagePath)) {
478-
fs.mkdirSync(storagePath);
479-
}
480-
481-
// ghcup exists, just upgrade
482-
if (fs.existsSync(ghcup)) {
483-
logger.info('ghcup already installed, trying to upgrade');
484-
const args = ['upgrade', '-i'];
485-
await callGHCup(context, logger, args, 'Upgrading ghcup', true);
486-
} else {
487-
// needs to download ghcup
488-
const plat = match(process.platform)
489-
.with('darwin', (_) => 'apple-darwin')
490-
.with('linux', (_) => 'linux')
491-
.with('win32', (_) => 'mingw64')
492-
.with('freebsd', (_) => 'freebsd12')
493-
.otherwise((_) => null);
494-
if (plat === null) {
495-
throw new Error(`Couldn't find any pre-built ghcup binary for ${process.platform}`);
496-
}
497-
const arch = match(process.arch)
498-
.with('arm', (_) => 'armv7')
499-
.with('arm64', (_) => 'aarch64')
500-
.with('x32', (_) => 'i386')
501-
.with('x64', (_) => 'x86_64')
502-
.otherwise((_) => null);
503-
if (arch === null) {
504-
throw new Error(`Couldn't find any pre-built ghcup binary for ${process.arch}`);
505-
}
506-
const dlUri = `https://downloads.haskell.org/~ghcup/${arch}-${plat}-ghcup${exeExt}`;
507-
const title = `Downloading ${dlUri}`;
508-
logger.info(`Downloading ${dlUri}`);
509-
const downloaded = await downloadFile(title, dlUri, ghcup);
510-
if (!downloaded) {
511-
throw new Error(`Couldn't download ${dlUri} as ${ghcup}`);
512-
}
513-
}
514-
return ghcup;
468+
if (manageHLS === 'system-ghcup' || manageHLS == 'internal-ghcup') {
469+
logger.info(`found ghcup at ${localGHCup}`);
470+
const args = ['upgrade'];
471+
await callGHCup(context, logger, args, 'Upgrading ghcup', true);
472+
return localGHCup;
515473
} else {
516474
throw new Error(`Internal error: tried to call ghcup while haskell.manageHLS is set to ${manageHLS}. Aborting!`);
517475
}

test/suite/extension.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ suite('Extension Test Suite', () => {
131131
, joinUri(getWorkspaceRoot().uri, 'bin', process.platform === 'win32' ? 'ghcup' : '.ghcup', 'cache')
132132
]
133133
);
134-
await getHaskellConfig().update('manageHLS', 'internal-ghcup');
134+
await getHaskellConfig().update('manageHLS', 'system-ghcup');
135135
await getHaskellConfig().update('logFile', 'hls.log');
136136
await getHaskellConfig().update('trace.server', 'messages');
137137
await getHaskellConfig().update('releasesDownloadStoragePath', path.normalize(getWorkspaceFile('bin').fsPath));

0 commit comments

Comments
 (0)