Skip to content

Commit 2cc84cb

Browse files
authored
Merge pull request #562 from hasufell/haskell-toolchain
Introduce 'haskell.toolchain' setting
2 parents 104a1c7 + eedba7d commit 2cc84cb

File tree

5 files changed

+249
-51
lines changed

5 files changed

+249
-51
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,57 @@ or set `haskell.serverExecutablePath` (overrides all other settings) to a valid
105105

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

108+
### Setting a specific toolchain
109+
110+
When `manageHLS` is set to `GHCup`, you can define a specific toolchain (`hls`, `ghc`, `cabal` and `stack`),
111+
either globally or per project. E.g.:
112+
113+
```json
114+
{
115+
"haskell.toolchain": {
116+
"hls": "1.6.1.1",
117+
"cabal": "recommended",
118+
"stack": null
119+
}
120+
}
121+
```
122+
123+
This means:
124+
125+
1. install the `ghc` version corresponding to the project (default, because it's omitted)
126+
2. install `hls` 1.6.1.1
127+
3. install the recommended `cabal` version from ghcup
128+
4. don't install any `stack` version
129+
130+
Another config could be:
131+
132+
```json
133+
{
134+
"haskell.toolchain": {
135+
"ghc": "9.2.2",
136+
"hls": "latest"
137+
"cabal": "recommended"
138+
}
139+
}
140+
```
141+
142+
Meaning:
143+
144+
1. install `ghc` 9.2.2 regardless of what the project requires
145+
2. always install latest `hls`, even if it doesn't support the given GHC version
146+
3. install recommended `cabal`
147+
4. install latest `stack` (default, because it's omitted)
148+
149+
The defaults (when omitted) are as follows:
150+
151+
1. install the project required `ghc` (corresponding to `with-compiler` setting in `cabal.project` for example)
152+
2. install the latest `hls` version that supports the project required ghc version
153+
3. install latest `cabal`
154+
3. install latest `stack`
155+
156+
When a the value is `null`, the extension will refrain from installing it.
157+
158+
108159
### Supported GHC versions
109160

110161
These are the versions of GHC that there are binaries of `haskell-language-server-1.6.1` for. Building from source may support more versions!

package.json

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@
163163
"default": {},
164164
"markdownDescription": "Define environment variables for the language server."
165165
},
166+
"haskell.promptBeforeDownloads": {
167+
"scope": "machine",
168+
"type": "boolean",
169+
"default": "true",
170+
"markdownDescription": "Prompt before performing any downloads."
171+
},
166172
"haskell.manageHLS": {
167173
"scope": "resource",
168174
"type": "string",
@@ -177,23 +183,11 @@
177183
"Discovers HLS and other executables in system PATH"
178184
]
179185
},
180-
"haskell.installStack": {
181-
"scope": "resource",
182-
"type": "boolean",
183-
"default": true,
184-
"description": "Whether to also install/manage stack when 'manageHLS' is set to 'GHCup'."
185-
},
186-
"haskell.installCabal": {
187-
"scope": "resource",
188-
"type": "boolean",
189-
"default": true,
190-
"description": "Whether to also install/manage cabal when 'manageHLS' is set to 'GHCup'."
191-
},
192-
"haskell.installGHC": {
186+
"haskell.toolchain": {
193187
"scope": "resource",
194-
"type": "boolean",
195-
"default": true,
196-
"description": "Whether to also install/manage GHC when 'manageHLS' is set to 'GHCup'."
188+
"type": "object",
189+
"default": {},
190+
"description": "When manageHLS is set to GHCup, this can overwrite the automatic toolchain configuration with a more specific one. When a tool is omitted, the extension will manage the version (for 'ghc' we try to figure out the version the project requires). The format is '{\"tool\": \"version\", ...}'. 'version' accepts all identifiers that 'ghcup' accepts."
197191
},
198192
"haskell.upgradeGHCup": {
199193
"scope": "resource",

src/extension.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,15 @@ async function activateServerForFolder(context: ExtensionContext, uri: Uri, fold
145145
logger.log(` ${key}: ${value}`);
146146
});
147147

148-
let serverExecutable;
148+
let serverExecutable: string;
149149
let addInternalServerPath: string | undefined; // if we download HLS, add that bin dir to PATH
150150
try {
151-
serverExecutable = await findHaskellLanguageServer(context, logger, currentWorkingDir, folder);
152-
addInternalServerPath = path.dirname(serverExecutable);
151+
[serverExecutable, addInternalServerPath] = await findHaskellLanguageServer(
152+
context,
153+
logger,
154+
currentWorkingDir,
155+
folder
156+
);
153157
if (!serverExecutable) {
154158
return;
155159
}

0 commit comments

Comments
 (0)