Skip to content

Commit 2c7fd41

Browse files
committed
Be more strict about PATH vs serverExecutablePath
We don't do random fallbacks anymore. If serverExecutablePath is set, it must exist. We only check PATH if no other setting is enabled.
1 parent a9195f4 commit 2c7fd41

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/hlsBinaries.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,25 @@ async function callAsync(
147147
);
148148
}
149149

150-
/** Searches the PATH for whatever is set in 'serverExecutablePath'.
150+
/** Gets serverExecutablePath and fails if it's not set.
151151
*/
152-
function findHLSinPATH(context: ExtensionContext, logger: Logger, folder?: WorkspaceFolder): string | null {
153-
// try 'serverExecutablePath' setting
152+
function findServerExecutable(context: ExtensionContext, logger: Logger, folder?: WorkspaceFolder): string {
154153
let exePath = workspace.getConfiguration('haskell').get('serverExecutablePath') as string;
155-
if (exePath !== '') {
156-
logger.info(`Trying to find the server executable in: ${exePath}`);
157-
exePath = resolvePathPlaceHolders(exePath, folder);
158-
logger.log(`Location after path variables substitution: ${exePath}`);
159-
if (executableExists(exePath)) {
160-
return exePath;
161-
}
154+
logger.info(`Trying to find the server executable in: ${exePath}`);
155+
exePath = resolvePathPlaceHolders(exePath, folder);
156+
logger.log(`Location after path variables substitution: ${exePath}`);
157+
if (executableExists(exePath)) {
158+
return exePath;
159+
} else {
160+
const msg = `Could not find a HLS binary at ${exePath}! Consider installing HLS via ghcup or change "haskell.manageHLS" in your settings.`;
161+
window.showErrorMessage(msg);
162+
throw new Error(msg);
162163
}
164+
}
163165

166+
/** Searches the PATH. Fails if nothing is found.
167+
*/
168+
function findHLSinPATH(context: ExtensionContext, logger: Logger, folder?: WorkspaceFolder): string {
164169
// try PATH
165170
const exes: string[] = ['haskell-language-server-wrapper', 'haskell-language-server'];
166171
logger.info(`Searching for server executables ${exes.join(',')} in $PATH`);
@@ -171,8 +176,9 @@ function findHLSinPATH(context: ExtensionContext, logger: Logger, folder?: Works
171176
return exe;
172177
}
173178
}
174-
175-
return null;
179+
const msg = 'Could not find a HLS binary in PATH! Consider installing HLS via ghcup or change "haskell.manageHLS" in your settings.';
180+
window.showErrorMessage(msg);
181+
throw new Error(msg);
176182
}
177183

178184
/**
@@ -209,13 +215,10 @@ export async function findHaskellLanguageServer(
209215
const manageHLS = workspace.getConfiguration('haskell').get('manageHLS') as boolean;
210216

211217
if (!manageHLS) {
212-
const wrapper = findHLSinPATH(context, logger, folder);
213-
if (!wrapper) {
214-
const msg = 'Could not find a HLS binary! Consider installing HLS via ghcup or set "haskell.manageHLS" to true';
215-
window.showErrorMessage(msg);
216-
throw new Error(msg);
218+
if (workspace.getConfiguration('haskell').get('serverExecutablePath') as string !== '') {
219+
return findServerExecutable(context, logger, folder);
217220
} else {
218-
return wrapper;
221+
return findHLSinPATH(context, logger, folder);
219222
}
220223
} else {
221224
// permissively check if we have HLS installed

0 commit comments

Comments
 (0)