Skip to content
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

Consider user installed HLSes (e.g. via ghcup compile) #543

Merged
merged 8 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,27 @@ The environment _only will be visible for the lsp server_, not for other extensi

### Downloaded binaries

This extension will download `haskell-language-server` binaries via an (internal) ghcup to a specific location depending
on your system, unless you set the config option `haskell.manageHLS` to `false` (the default is `true`).
This extension will download `haskell-language-server` binaries either via an internal ghcup (it will download it automaticlaly)
or via a system ghcup (which must be present), unless you set the config option `haskell.manageHLS` to `PATH` (the extension
will ask you on first start).

It will download the newest version of haskell-language-server which has support for the required ghc.
It will then download the newest version of haskell-language-server which has support for the required ghc.
That means it could use an older version than the latest one, without the last features and bug fixes.
For example, if a project needs ghc-8.10.4 the extension will download and use haskell-language-server-1.4.0, the lastest version which supported ghc-8.10.4. Even if the lastest global haskell language-server version is 1.5.1.

If you find yourself running out of disk space, you can try deleting old versions of language servers in this directory. The extension will redownload them, no strings attached.
If you have disk space issues and use system ghcup, check `ghcup gc --help`.
If you have disk space issues and use the internal ghcup, check the following directories, depending on your platform
and possible delete them:

| Platform | Path |
| -------- | ------------------------------------------------------------------------------- |
| macOS | `~/Library/Application\ Support/Code/User/globalStorage/haskell.haskell/.ghcup` |
| Windows | `%APPDATA%\Code\User\globalStorage\haskell.haskell\ghcup` |
| Linux | `$HOME/.config/Code/User/globalStorage/haskell.haskell/.ghcup` |

If you want to manage HLS yourself, set `haskell.manageHLS` to `false` and make sure HLS is in your PATH
If you want to manage HLS yourself, set `haskell.manageHLS` to `PATH` and make sure HLS is in your PATH
or set `haskell.serverExecutablePath` to a valid executable.

You can also tell HLS to use your system provided ghcup by setting `haskell.useSystemGHCup` to `true` (default is `false`).

If you need to set mirrors for ghcup download info, check the settings `haskell.metadataURL` and `haskell.releasesURL`.

### Supported GHC versions
Expand Down
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,19 @@
},
"haskell.manageHLS": {
"scope": "resource",
"type": "boolean",
"default": true,
"description": "Let this extension manage required HLS versions via ghcup."
"type": "string",
"default": null,
"description": "How to manage/find HLS installations.",
"enum": [
"system-ghcup",
"internal-ghcup",
"PATH"
],
"enumDescriptions": [
"Will use a user-wide installation of ghcup (usually in '~/.ghcup') to manage HLS automatically",
"Will use an internal installation of ghcup to manage HLS automatically, to avoid interfering with system ghcup",
"Discovers HLS executables in system PATH"
]
},
"haskell.useSystemGHCup": {
"scope": "resource",
Expand Down
14 changes: 12 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
import * as path from 'path';
import {
env,
commands,
ExtensionContext,
OutputChannel,
Expand All @@ -22,7 +23,7 @@ import {
import { CommandNames } from './commands/constants';
import { ImportIdentifier } from './commands/importIdentifier';
import { DocsBrowser } from './docsBrowser';
import { addPathToProcessPath, findHaskellLanguageServer, IEnvVars } from './hlsBinaries';
import { MissingToolError, addPathToProcessPath, findHaskellLanguageServer, IEnvVars } from './hlsBinaries';
import { expandHomeDir, ExtensionLogger } from './utils';

// The current map of documents & folders to language servers.
Expand Down Expand Up @@ -153,7 +154,16 @@ async function activateServerForFolder(context: ExtensionContext, uri: Uri, fold
return;
}
} catch (e) {
if (e instanceof Error) {
if (e instanceof MissingToolError) {
const link = e.installLink();
if (link) {
if (await window.showErrorMessage(e.message, `Install ${e.tool}`)) {
env.openExternal(link);
}
} else {
await window.showErrorMessage(e.message);
}
} else if (e instanceof Error) {
Comment on lines +157 to +166
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here at the top-level of extension init we catch all promise errors and also restore the MissingToolError with link popup.

logger.error(`Error getting the server executable: ${e.message}`);
window.showErrorMessage(e.message);
}
Expand Down
Loading