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

fix: relax .NET runtime version check #443

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export namespace ConfigurationConstants {

export namespace DotnetConstants {
export const ExecutableName = 'dotnet';
export const SupportedRuntimesPattern = /Microsoft\.AspNetCore\.App\s*[56]\.0/i;
export const SupportedRuntimesPattern = /Microsoft\.NETCore\.App\s*((\d+)\.\d+\.\d+)/ig;
export const SupportedRuntimesMinVersion = 5;
}

export namespace LanguageServerConstants {
Expand Down
15 changes: 13 additions & 2 deletions src/dotnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@ export async function checkSupportedDotnetVersion(): Promise<string | undefined>
return dotnetExecutable + Messages.Dotnet.IsNotAnExecutableFile;
}
const { stdout } = await execFileAsync(dotnetExecutable, [ ListRuntimesArg ]);
return DotnetConstants.SupportedRuntimesPattern.test(stdout) ? undefined
: dotnetExecutable + Messages.Dotnet.NotASupportedDotnetInstallation + stdout;
const runtimeVersions = [ ...stdout.matchAll(DotnetConstants.SupportedRuntimesPattern) ]
.map(match => {
const full = match[1];
const major = parseInt(match[2], 10);
return { full, major };
});
if(runtimeVersions.find(({ major }) => major >= DotnetConstants.SupportedRuntimesMinVersion) !== undefined) {
return undefined;
}
const runtimeVersionsStr = runtimeVersions.length === 0
? ' no installed versions'
: runtimeVersions.map(({ full }) => full).join(', ');
return dotnetExecutable + Messages.Dotnet.NotASupportedDotnetInstallation + runtimeVersionsStr;
} catch(error: unknown) {
const errorMsg = `Error invoking ${dotnetExecutable} ${ListRuntimesArg}: ${error}`;
console.error(errorMsg);
Expand Down
6 changes: 3 additions & 3 deletions src/ui/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export namespace Messages {

export namespace Dotnet {
export const IsNotAnExecutableFile = ' is not an executable dotnet file.';
export const NotASupportedDotnetInstallation = ' is not a compatible dotnet file. Dafny requires the ASP.NET Core Runtime 5.0 or 6.0, got ';
export const FailedDotnetExecution = 'Failed to execute dotnet. Dafny requires the ASP.NET Core Runtime 5.0 or 6.0.';
export const NoCompatibleInstallation = 'No compatible dotnet runtime found. Dafny requires the ASP.NET Core Runtime 5.0 or 6.0.';
export const NotASupportedDotnetInstallation = ' is not a compatible dotnet file. Dafny requires the .NET Runtime 5.0 or greater, found ';
export const FailedDotnetExecution = 'Failed to execute dotnet. Dafny requires the .NET Runtime 5.0 or greater.';
export const NoCompatibleInstallation = 'No compatible dotnet runtime found. Dafny requires the .NET Runtime 5.0 or greater.';
Comment on lines +32 to +34
Copy link
Member

Choose a reason for hiding this comment

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

Side note, I'm a bit surprised we need three different error messages, implying there are three different places we check this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, it's possible that the "Dafny requires the .NET Runtime 5.0 or greater" part is redundant, but indeed the three messages are used in three distinct failure modes (successfully executed dotnet --list-runtimes but found no compatible version; failed to execute dotnet with a manually-specified executable; and failed to execute dotnet using $PATH).

export const ChangeConfiguration = 'Configure the absolute path to dotnet';
export const VisitDownload = 'Get .NET SDK';
export const DownloadUri = 'https://dotnet.microsoft.com/download/dotnet/6.0';
Expand Down
Loading