Skip to content

Commit 09af1eb

Browse files
committed
Add haskell.ghcupExecutablePath
1 parent 96102ba commit 09af1eb

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@
151151
"default": "",
152152
"markdownDescription": "Pass additional arguments to the language server."
153153
},
154+
"haskell.ghcupExecutablePath": {
155+
"scope": "resource",
156+
"type": "string",
157+
"default": "",
158+
"markdownDescription": "Manually set a ghcup executable path."
159+
},
154160
"haskell.serverEnvironment": {
155161
"scope": "resource",
156162
"type": "object",

src/hlsBinaries.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ async function findServerExecutable(context: ExtensionContext, logger: Logger, f
168168
return exePath;
169169
} else {
170170
const msg = `Could not find a HLS binary at ${exePath}! Consider installing HLS via ghcup or change "haskell.manageHLS" in your settings.`;
171-
window.showErrorMessage(msg);
172171
throw new Error(msg);
173172
}
174173
}
@@ -188,7 +187,6 @@ async function findHLSinPATH(context: ExtensionContext, logger: Logger, folder?:
188187
}
189188
const msg =
190189
'Could not find a HLS binary in PATH! Consider installing HLS via ghcup or change "haskell.manageHLS" in your settings.';
191-
window.showErrorMessage(msg);
192190
throw new Error(msg);
193191
}
194192

@@ -359,7 +357,6 @@ async function getLatestProjectHLS(
359357
.pop();
360358

361359
if (!latest) {
362-
window.showErrorMessage(noMatchingHLS);
363360
throw new Error(noMatchingHLS);
364361
} else {
365362
return [latest[0], projectGhc];
@@ -433,14 +430,26 @@ export async function upgradeGHCup(context: ExtensionContext, logger: Logger): P
433430
}
434431
}
435432

436-
export async function findGHCup(context: ExtensionContext, logger: Logger): Promise<string> {
433+
export async function findGHCup(context: ExtensionContext, logger: Logger, folder?: WorkspaceFolder): Promise<string> {
437434
logger.info('Checking for ghcup installation');
438-
const localGHCup = ['ghcup'].find(executableExists);
439-
if (!localGHCup) {
440-
throw new MissingToolError('ghcup');
435+
let exePath = workspace.getConfiguration('haskell').get('ghcupExecutablePath') as string;
436+
if (exePath) {
437+
logger.info(`Trying to find the ghcup executable in: ${exePath}`);
438+
exePath = resolvePathPlaceHolders(exePath, folder);
439+
logger.log(`Location after path variables substitution: ${exePath}`);
440+
if (await executableExists(exePath)) {
441+
return exePath;
442+
} else {
443+
throw new Error(`Could not find a ghcup binary at ${exePath}!`);
444+
}
441445
} else {
442-
logger.info(`found ghcup at ${localGHCup}`);
443-
return localGHCup
446+
const localGHCup = ['ghcup'].find(executableExists);
447+
if (!localGHCup) {
448+
throw new MissingToolError('ghcup');
449+
} else {
450+
logger.info(`found ghcup at ${localGHCup}`);
451+
return localGHCup
452+
}
444453
}
445454
}
446455

0 commit comments

Comments
 (0)