Skip to content

Commit 5158096

Browse files
committed
add third option: never check for newer versions
Shouldn't save too much bandwidth, but why not? Also fix default option
1 parent 65a55b6 commit 5158096

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,15 @@
157157
"type": "string",
158158
"enum": [
159159
"keep-up-to-date",
160-
"prompt"
160+
"prompt",
161+
"never-check"
161162
],
162163
"enumDescriptions": [
163164
"Always download the latest available version when it is published",
164-
"Prompt before downloading a newer version"
165+
"Prompt before upgrading to a newer version",
166+
"Don't check for newer versions"
165167
],
166-
"default": true,
168+
"default": "keep-up-to-date",
167169
"markdownDescription": "Only applicable with `#haskell.languageServerVariant#` set to `haskell-language-server`. Determine what to do when a new version of the language server is available."
168170
}
169171
}

src/hlsBinaries.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface IAsset {
2020
name: string;
2121
}
2222

23-
type UpdateBehaviour = 'keep-up-to-date' | 'prompt';
23+
type UpdateBehaviour = 'keep-up-to-date' | 'prompt' | 'never-check';
2424

2525
const assetValidator: validate.Validator<IAsset> = validate.object({
2626
browser_download_url: validate.string(),
@@ -179,14 +179,18 @@ async function getLatestReleaseMetadata(context: ExtensionContext): Promise<IRel
179179
throw err;
180180
}
181181
}
182+
// Not all users want to upgrade right away, in that case prompt
183+
const updateBehaviour = workspace.getConfiguration('haskell').get('hlsUpdateBehavior') as UpdateBehaviour;
184+
185+
if (updateBehaviour === 'never-check') {
186+
return readCachedReleaseData();
187+
}
182188

183189
try {
184190
const releaseInfo = await httpsGetSilently(opts);
185191
const latestInfoParsed =
186192
validate.parseAndValidate(releaseInfo, githubReleaseApiValidator).find((x) => !x.prerelease) || null;
187193

188-
// Not all users want to upgrade right away, in that case prompt
189-
const updateBehaviour = workspace.getConfiguration('haskell').get('hlsUpdateBehavior') as UpdateBehaviour;
190194
if (updateBehaviour === 'prompt') {
191195
const cachedInfoParsed = await readCachedReleaseData();
192196

@@ -248,7 +252,12 @@ export async function downloadHaskellLanguageServer(
248252
// Fetch the latest release from GitHub or from cache
249253
const release = await getLatestReleaseMetadata(context);
250254
if (!release) {
251-
window.showErrorMessage("Couldn't find any pre-built haskell-language-server binaries");
255+
let message = "Couldn't find any pre-built haskell-language-server binaries";
256+
const updateBehaviour = workspace.getConfiguration('haskell').get('hlsUpdateBehavior') as UpdateBehaviour;
257+
if (updateBehaviour === 'never-check') {
258+
message += ' (and checking for newer versions is disabled)';
259+
}
260+
window.showErrorMessage(message);
252261
return null;
253262
}
254263

src/utils.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as http from 'http';
66
import * as https from 'https';
77
import { extname } from 'path';
88
import * as url from 'url';
9+
import { promisify } from 'util';
910
import { ProgressLocation, window } from 'vscode';
1011
import * as yazul from 'yauzl';
1112
import { createGunzip } from 'zlib';
@@ -50,6 +51,13 @@ export async function httpsGetSilently(options: https.RequestOptions): Promise<s
5051
});
5152
}
5253

54+
async function ignoreFileNotExists(err: NodeJS.ErrnoException): Promise<void> {
55+
if (err.code === 'ENOENT') {
56+
return;
57+
}
58+
throw err;
59+
}
60+
5361
export async function downloadFile(titleMsg: string, src: string, dest: string): Promise<void> {
5462
// Check to see if we're already in the process of downloading the same thing
5563
const inFlightDownload = inFlightDownloads.get(src)?.get(dest);
@@ -158,10 +166,10 @@ export async function downloadFile(titleMsg: string, src: string, dest: string):
158166
} else {
159167
inFlightDownloads.set(src, new Map([[dest, downloadTask]]));
160168
}
161-
return downloadTask;
169+
return await downloadTask;
162170
} catch (e) {
163-
fs.unlinkSync(downloadDest);
164-
throw new Error(`Failed to download ${url}`);
171+
await promisify(fs.unlink)(downloadDest).catch(ignoreFileNotExists);
172+
throw new Error(`Failed to download ${src}:\n${e.message}`);
165173
}
166174
}
167175

0 commit comments

Comments
 (0)