Skip to content

Improve serverExecutablePath description and error when pointing to a directory #484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"scope": "resource",
"type": "string",
"default": "",
"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."
"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."
},
"haskell.serverExtraArgs": {
"scope": "resource",
Expand Down
12 changes: 9 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { CommandNames } from './commands/constants';
import { ImportIdentifier } from './commands/importIdentifier';
import { DocsBrowser } from './docsBrowser';
import { downloadHaskellLanguageServer } from './hlsBinaries';
import { executableExists, ExtensionLogger, resolvePathPlaceHolders } from './utils';
import { directoryExists, executableExists, ExtensionLogger, resolvePathPlaceHolders } from './utils';

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

if (!executableExists(exePath)) {
throw new Error(`serverExecutablePath is set to ${exePath} but it doesn't exist and it is not on the PATH`);
let msg = `serverExecutablePath is set to ${exePath}`;
if (directoryExists(exePath)) {
msg += ' but it is a directory and the config option should point to the executable *full* path';
} else {
msg += " but it doesn't exist and it is not on the PATH";
}
throw new Error(msg);
}
return exePath;
}
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ export function executableExists(exe: string): boolean {
return out.status === 0 || (isWindows && fs.existsSync(exe));
}

export function directoryExists(path: string): boolean {
return fs.existsSync(path) && fs.lstatSync(path).isDirectory();
}

export function resolvePathPlaceHolders(path: string, folder?: WorkspaceFolder) {
path = path.replace('${HOME}', os.homedir).replace('${home}', os.homedir).replace(/^~/, os.homedir);
if (folder) {
Expand Down