Skip to content

Commit d95f784

Browse files
committed
Use specific error for a dir
1 parent 3373970 commit d95f784

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/extension.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { CommandNames } from './commands/constants';
2323
import { ImportIdentifier } from './commands/importIdentifier';
2424
import { DocsBrowser } from './docsBrowser';
2525
import { downloadHaskellLanguageServer } from './hlsBinaries';
26-
import { executableExists, ExtensionLogger, resolvePathPlaceHolders } from './utils';
26+
import { directoryExists, executableExists, ExtensionLogger, resolvePathPlaceHolders } from './utils';
2727

2828
// The current map of documents & folders to language servers.
2929
// It may be null to indicate that we are in the process of launching a server,
@@ -103,10 +103,16 @@ function findManualExecutable(logger: Logger, uri: Uri, folder?: WorkspaceFolder
103103
}
104104
logger.info(`Trying to find the server executable in: ${exePath}`);
105105
exePath = resolvePathPlaceHolders(exePath, folder);
106-
logger.info(`Location after path variables subsitution: ${exePath}`);
106+
logger.info(`Location after path variables substitution: ${exePath}`);
107107

108108
if (!executableExists(exePath)) {
109-
throw new Error(`serverExecutablePath is set to ${exePath} but it doesn't exist and it is not on the PATH`);
109+
let msg = `serverExecutablePath is set to ${exePath}`;
110+
if (directoryExists(exePath)) {
111+
msg += ' but it is a directory and the config option should point to the executable *full* path';
112+
} else {
113+
msg += " but it doesn't exist and it is not on the PATH";
114+
}
115+
throw new Error(msg);
110116
}
111117
return exePath;
112118
}

src/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ export function executableExists(exe: string): boolean {
263263
return out.status === 0 || (isWindows && fs.existsSync(exe));
264264
}
265265

266+
export function directoryExists(path: string): boolean {
267+
return fs.existsSync(path) && fs.lstatSync(path).isDirectory();
268+
}
269+
266270
export function resolvePathPlaceHolders(path: string, folder?: WorkspaceFolder) {
267271
path = path.replace('${HOME}', os.homedir).replace('${home}', os.homedir).replace(/^~/, os.homedir);
268272
if (folder) {

0 commit comments

Comments
 (0)