From 8b231a611b88348da664281814ddd72ea2a1adcf Mon Sep 17 00:00:00 2001 From: Alex Chew Date: Tue, 10 Oct 2023 14:17:15 -0700 Subject: [PATCH 1/2] fix: relax dotnet version check --- src/constants.ts | 3 ++- src/dotnet.ts | 15 +++++++++++++-- src/ui/messages.ts | 6 +++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index ae40eaed..a44c3c6b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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 { diff --git a/src/dotnet.ts b/src/dotnet.ts index 6a46e60d..38e9cebc 100644 --- a/src/dotnet.ts +++ b/src/dotnet.ts @@ -20,8 +20,19 @@ export async function checkSupportedDotnetVersion(): Promise 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 version = match[1]; + const major = parseInt(match[2], 10); + return [major, version] as [number, string]; + }); + if (runtimeVersions.find(([major, _]) => major >= DotnetConstants.SupportedRuntimesMinVersion) !== undefined) { + return undefined; + } + const runtimeVersionsStr = runtimeVersions.length === 0 + ? " no installed versions" + : runtimeVersions.map(([_, version]) => version).join(", "); + return dotnetExecutable + Messages.Dotnet.NotASupportedDotnetInstallation + runtimeVersionsStr; } catch(error: unknown) { const errorMsg = `Error invoking ${dotnetExecutable} ${ListRuntimesArg}: ${error}`; console.error(errorMsg); diff --git a/src/ui/messages.ts b/src/ui/messages.ts index dab3be5c..7c69e021 100644 --- a/src/ui/messages.ts +++ b/src/ui/messages.ts @@ -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.'; 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'; From 221077f72f3ad2eab822e64c96edfd031ac9c817 Mon Sep 17 00:00:00 2001 From: Alex Chew Date: Tue, 10 Oct 2023 14:25:44 -0700 Subject: [PATCH 2/2] fix lint errors --- src/dotnet.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dotnet.ts b/src/dotnet.ts index 38e9cebc..cacea78d 100644 --- a/src/dotnet.ts +++ b/src/dotnet.ts @@ -20,18 +20,18 @@ export async function checkSupportedDotnetVersion(): Promise return dotnetExecutable + Messages.Dotnet.IsNotAnExecutableFile; } const { stdout } = await execFileAsync(dotnetExecutable, [ ListRuntimesArg ]); - const runtimeVersions = [...stdout.matchAll(DotnetConstants.SupportedRuntimesPattern)] + const runtimeVersions = [ ...stdout.matchAll(DotnetConstants.SupportedRuntimesPattern) ] .map(match => { - const version = match[1]; + const full = match[1]; const major = parseInt(match[2], 10); - return [major, version] as [number, string]; + return { full, major }; }); - if (runtimeVersions.find(([major, _]) => major >= DotnetConstants.SupportedRuntimesMinVersion) !== undefined) { + if(runtimeVersions.find(({ major }) => major >= DotnetConstants.SupportedRuntimesMinVersion) !== undefined) { return undefined; } const runtimeVersionsStr = runtimeVersions.length === 0 - ? " no installed versions" - : runtimeVersions.map(([_, version]) => version).join(", "); + ? ' no installed versions' + : runtimeVersions.map(({ full }) => full).join(', '); return dotnetExecutable + Messages.Dotnet.NotASupportedDotnetInstallation + runtimeVersionsStr; } catch(error: unknown) { const errorMsg = `Error invoking ${dotnetExecutable} ${ListRuntimesArg}: ${error}`;