Skip to content

Commit b471d04

Browse files
authored
Merge pull request #484 from jneira/exec-path
Improve serverExecutablePath description and error when pointing to a directory
2 parents 2020488 + d95f784 commit b471d04

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
"scope": "resource",
137137
"type": "string",
138138
"default": "",
139-
"markdownDescription": "Manually set a language server executable. Can be something on the $PATH or a path to an executable itself. Works with `~,` `${HOME}` and `${workspaceFolder}`. **Deprecated scope**: This option will be set to `machine` scope in a future release, so it can be changed only globally, not per workspace."
139+
"markdownDescription": "Manually set a language server executable. Can be something on the $PATH or the full path to the executable itself. Works with `~,` `${HOME}` and `${workspaceFolder}`. **Deprecated scope**: This option will be set to `machine` scope in a future release, so it can be changed only globally, not per workspace."
140140
},
141141
"haskell.serverExtraArgs": {
142142
"scope": "resource",

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)