Skip to content

Add traces for download hls #508

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
Nov 25, 2021
Merged
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
47 changes: 29 additions & 18 deletions src/hlsBinaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ class NoBinariesError extends Error {
const supportedReleasesLink =
'[See the list of supported versions here](https://github.com/haskell/vscode-haskell#supported-ghc-versions)';
if (ghcVersion) {
super(`haskell-language-server ${hlsVersion} or earlier for GHC ${ghcVersion} is not available on ${os.type()}.
${supportedReleasesLink}`);
super(`haskell-language-server ${hlsVersion} or earlier for GHC ${ghcVersion} is not available on ${os.type()}. ${supportedReleasesLink}`);
} else {
super(`haskell-language-server ${hlsVersion} is not available on ${os.type()}.
${supportedReleasesLink}`);
super(`haskell-language-server ${hlsVersion} is not available on ${os.type()}. ${supportedReleasesLink}`);
}
}
}
Expand Down Expand Up @@ -246,11 +244,13 @@ async function getReleaseMetadata(

async function readCachedReleaseData(): Promise<IRelease[] | null> {
try {
logger.info(`Reading cached release data at ${offlineCache}`);
const cachedInfo = await promisify(fs.readFile)(offlineCache, { encoding: 'utf-8' });
return validate.parseAndValidate(cachedInfo, cachedReleaseValidator);
} catch (err: any) {
// If file doesn't exist, return null, otherwise consider it a failure
if (err.code === 'ENOENT') {
logger.warn(`No cached release data found at ${offlineCache}`);
return null;
}
throw err;
Expand All @@ -260,6 +260,8 @@ async function getReleaseMetadata(
const updateBehaviour = workspace.getConfiguration('haskell').get('updateBehavior') as UpdateBehaviour;

if (updateBehaviour === 'never-check') {
logger.warn("As 'haskell.updateBehaviour' config option is set to 'never-check' " +
'we try to use the possibly obsolete cached release data');
return readCachedReleaseData();
}

Expand Down Expand Up @@ -298,11 +300,13 @@ async function getReleaseMetadata(
const cachedInfoParsed = await readCachedReleaseData();

window.showWarningMessage(
`Couldn't get the latest haskell-language-server releases from GitHub, used local cache instead:\n${githubError.message}`
"Couldn't get the latest haskell-language-server releases from GitHub, used local cache instead: " +
githubError.message
);
return cachedInfoParsed;
} catch (fileError) {
throw new Error(`Couldn't get the latest haskell-language-server releases from GitHub:\n${githubError.message}`);
throw new Error("Couldn't get the latest haskell-language-server releases from GitHub: " +
githubError.message);
}
}
}
Expand Down Expand Up @@ -341,16 +345,16 @@ export async function downloadHaskellLanguageServer(

logger.info('Fetching the latest release from GitHub or from cache');
const releases = await getReleaseMetadata(context, storagePath, logger);
const updateBehaviour = workspace.getConfiguration('haskell').get('updateBehavior') as UpdateBehaviour;
if (!releases) {
let message = "Couldn't find any pre-built haskell-language-server binaries";
const updateBehaviour = workspace.getConfiguration('haskell').get('updateBehavior') as UpdateBehaviour;
if (updateBehaviour === 'never-check') {
message += ' (and checking for newer versions is disabled)';
}
window.showErrorMessage(message);
return null;
}
logger.info(`The latest release is ${releases[0].tag_name}`);
logger.info(`The latest known release is ${releases[0].tag_name}`);
logger.info('Figure out the ghc version to use or advertise an installation link for missing components');
const dir: string = folder?.uri?.fsPath ?? path.dirname(resource.fsPath);
let ghcVersion: string;
Expand All @@ -370,7 +374,7 @@ export async function downloadHaskellLanguageServer(
window.showInformationMessage(error.message);
} else if (error instanceof Error) {
// We couldn't figure out the right ghc version to download
window.showErrorMessage(`Couldn't figure out what GHC version the project is using:\n${error.message}`);
window.showErrorMessage(`Couldn't figure out what GHC version the project is using: ${error.message}`);
}
return null;
}
Expand All @@ -382,31 +386,38 @@ export async function downloadHaskellLanguageServer(
const release = releases?.find(r => r.assets.find((x) => x.name.startsWith(assetName)));
const asset = release?.assets.find((x) => x.name.startsWith(assetName));
if (!asset) {
logger.error(
`No binary ${assetName} found in the release assets`
);
window.showInformationMessage(new NoBinariesError(releases[0].tag_name, ghcVersion).message);
let msg = new NoBinariesError(releases[0].tag_name, ghcVersion).message;
if (updateBehaviour === 'never-check') {
msg += ". Consider set 'haskell.updateBehaviour' to 'up-to-date' to check if another release includes the missing binary";
}
logger.error(msg);
window.showErrorMessage(msg);
return null;
}

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

logger.info(`Looking for an existing ${binaryDest} or download it from release assets`);
const title = `Downloading haskell-language-server ${release?.tag_name} for GHC ${ghcVersion}`;
logger.info(title);

const downloaded = await downloadFile(title, asset.browser_download_url, binaryDest);
if (ghcVersion.startsWith('9.')) {
const warning =
'Currently, HLS supports GHC 9 only partially. ' +
'See [issue #297](https://github.com/haskell/haskell-language-server/issues/297) for more detail.';
'See [issue #297](https://github.com/haskell/haskell-language-server/issues/297) for more details.';
logger.warn(warning);
window.showWarningMessage(warning);
if (downloaded) {
window.showWarningMessage(warning);
}
}
if (release?.tag_name !== releases[0].tag_name) {
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}`;
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}`;
logger.warn(warning);
if (downloaded) {
window.showInformationMessage(warning);
window.showWarningMessage(warning);
}
}
return binaryDest;
Expand Down