Skip to content

Commit db4a691

Browse files
committed
Inform on fallback to outdated hls only on first download
1 parent 73d7e0e commit db4a691

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/hlsBinaries.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,25 +365,27 @@ export async function downloadHaskellLanguageServer(
365365
window.showInformationMessage(new NoBinariesError(releases[0].tag_name, ghcVersion).message);
366366
return null;
367367
}
368-
if (release?.tag_name != releases[0].tag_name) {
369-
const message = `haskell-language-server ${releases[0].tag_name} for GHC ${ghcVersion} is not available on ${os.type()}. Falling back to haskell-language-server ${release?.tag_name}`
370-
logger.warn(message)
371-
window.showInformationMessage(message)
372-
}
373368

374369
const serverName = `haskell-language-server-${release?.tag_name}-${process.platform}-${ghcVersion}${exeExt}`;
375370
const binaryDest = path.join(storagePath, serverName);
376371

377372
const title = `Downloading haskell-language-server ${release?.tag_name} for GHC ${ghcVersion}`;
378373
logger.info(title);
379-
await downloadFile(title, asset.browser_download_url, binaryDest);
374+
const downloaded = await downloadFile(title, asset.browser_download_url, binaryDest);
380375
if (ghcVersion.startsWith('9.')) {
381376
const warning =
382377
'Currently, HLS supports GHC 9 only partially. ' +
383378
'See [issue #297](https://github.com/haskell/haskell-language-server/issues/297) for more detail.';
384379
logger.warn(warning);
385380
window.showWarningMessage(warning);
386381
}
382+
if (release?.tag_name != releases[0].tag_name) {
383+
const warning = `haskell-language-server ${releases[0].tag_name} for GHC ${ghcVersion} is not available on ${os.type()}. Falling back to haskell-language-server ${release?.tag_name}`
384+
logger.warn(warning)
385+
if (downloaded) {
386+
window.showInformationMessage(warning)
387+
}
388+
}
387389
return binaryDest;
388390
}
389391

src/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const userAgentHeader = { 'User-Agent': 'vscode-haskell' };
9595
* equality is by reference, not value in Map. And we are using a tuple of
9696
* [src, dest] as the key.
9797
*/
98-
const inFlightDownloads = new Map<string, Map<string, Thenable<void>>>();
98+
const inFlightDownloads = new Map<string, Map<string, Thenable<boolean>>>();
9999

100100
export async function httpsGetSilently(options: https.RequestOptions): Promise<string> {
101101
const opts: https.RequestOptions = {
@@ -141,7 +141,7 @@ async function ignoreFileNotExists(err: NodeJS.ErrnoException): Promise<void> {
141141
throw err;
142142
}
143143

144-
export async function downloadFile(titleMsg: string, src: string, dest: string): Promise<void> {
144+
export async function downloadFile(titleMsg: string, src: string, dest: string): Promise<boolean> {
145145
// Check to see if we're already in the process of downloading the same thing
146146
const inFlightDownload = inFlightDownloads.get(src)?.get(dest);
147147
if (inFlightDownload) {
@@ -150,7 +150,7 @@ export async function downloadFile(titleMsg: string, src: string, dest: string):
150150

151151
// If it already is downloaded just use that
152152
if (fs.existsSync(dest)) {
153-
return;
153+
return false;
154154
}
155155

156156
// Download it to a .tmp location first, then rename it!
@@ -241,7 +241,7 @@ export async function downloadFile(titleMsg: string, src: string, dest: string):
241241
inFlightDownloads.get(src)?.delete(dest);
242242
}
243243
}
244-
);
244+
).then(_ => true);
245245

246246
try {
247247
if (inFlightDownloads.has(src)) {

0 commit comments

Comments
 (0)