From 1ee5705f10689448636d3a6a0d78d12b43d4e6da Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Fri, 20 Feb 2026 12:27:13 +0200 Subject: [PATCH] Add #version;; directive to F# Interactive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prints version, language version, FSharp.Core version, .NET runtime, and OS/architecture info on demand — useful for debugging and bug reporting when the startup banner has scrolled away. Closes #13307. --- .../.FSharp.Compiler.Service/10.0.300.md | 2 ++ src/Compiler/Interactive/FSIstrings.txt | 1 + src/Compiler/Interactive/fsi.fs | 24 +++++++++++++++++++ .../Interactive/xlf/FSIstrings.txt.cs.xlf | 5 ++++ .../Interactive/xlf/FSIstrings.txt.de.xlf | 5 ++++ .../Interactive/xlf/FSIstrings.txt.es.xlf | 5 ++++ .../Interactive/xlf/FSIstrings.txt.fr.xlf | 5 ++++ .../Interactive/xlf/FSIstrings.txt.it.xlf | 5 ++++ .../Interactive/xlf/FSIstrings.txt.ja.xlf | 5 ++++ .../Interactive/xlf/FSIstrings.txt.ko.xlf | 5 ++++ .../Interactive/xlf/FSIstrings.txt.pl.xlf | 5 ++++ .../Interactive/xlf/FSIstrings.txt.pt-BR.xlf | 5 ++++ .../Interactive/xlf/FSIstrings.txt.ru.xlf | 5 ++++ .../Interactive/xlf/FSIstrings.txt.tr.xlf | 5 ++++ .../xlf/FSIstrings.txt.zh-Hans.xlf | 5 ++++ .../xlf/FSIstrings.txt.zh-Hant.xlf | 5 ++++ .../Scripting/Interactive.fs | 16 +++++++++++++ .../DependencyManagerInteractiveTests.fs | 2 ++ .../core/printing/output.1000.stdout.bsl | 1 + .../core/printing/output.200.stdout.bsl | 1 + .../fsharp/core/printing/output.47.stdout.bsl | 1 + .../core/printing/output.multiemit.stdout.bsl | 1 + .../core/printing/output.off.stdout.bsl | 1 + tests/fsharp/core/printing/output.stdout.bsl | 1 + 24 files changed, 116 insertions(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md index c247da5870b..3e9ff3c7e47 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md @@ -2,6 +2,8 @@ ### Added +* Add `#version;;` directive to F# Interactive to display version and environment information. ([Issue #13307](https://github.com/dotnet/fsharp/issues/13307), [PR #19332](https://github.com/dotnet/fsharp/pull/19332)) + ### Changed ### Breaking Changes diff --git a/src/Compiler/Interactive/FSIstrings.txt b/src/Compiler/Interactive/FSIstrings.txt index a40f6fffaab..bbf2177c7d2 100644 --- a/src/Compiler/Interactive/FSIstrings.txt +++ b/src/Compiler/Interactive/FSIstrings.txt @@ -35,6 +35,7 @@ fsiIntroTextHashhelpInfo,"Display help" fsiIntroTextHashhelpdocInfo,"Display documentation for an identifier, e.g. #help \"List.map\";;" fsiIntroTextHashquitInfo,"Exit" fsiIntroTextHashclearInfo,"Clear screen" +fsiIntroTextHashversionInfo,"Display F# Interactive version and environment information" fsiIntroTextHeader2commandLine," F# Interactive command line options:" fsiIntroTextHeader3," See '%s' for options" fsiLoadingFilesPrefixText,"Loading" diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 5f4d9295bec..1354402ec09 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -1263,6 +1263,21 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig, argv: s fsiConsoleOutput.uprintfnn "%s" (FSComp.SR.optsCopyright ()) fsiConsoleOutput.uprintfn "%s" (FSIstrings.SR.fsiBanner3 ()) + member _.ShowVersion() = + fsiConsoleOutput.uprintnfn "%s" tcConfigB.productNameForBannerText + fsiConsoleOutput.uprintnfn "Language Version: %s" tcConfigB.langVersion.SpecifiedVersionString + + let fsharpCoreVersion = typeof.Assembly.GetName().Version |> string + + fsiConsoleOutput.uprintnfn "FSharp.Core: %s" fsharpCoreVersion + + fsiConsoleOutput.uprintnfn ".NET: %s" System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription + + fsiConsoleOutput.uprintnfn + "OS: %s (%O)" + System.Runtime.InteropServices.RuntimeInformation.OSDescription + System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture + member _.ShowHelp(m) = let helpLine = sprintf "%s --help" executableFileNameWithoutExtension.Value @@ -1294,6 +1309,11 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig, argv: s fsiConsoleOutput.uprintfn "%s" msg fsiConsoleOutput.uprintfn """ #clear;; // %s""" (FSIstrings.SR.fsiIntroTextHashclearInfo ()) + + fsiConsoleOutput.uprintfn + """ #version;; // %s""" + (FSIstrings.SR.fsiIntroTextHashversionInfo ()) + fsiConsoleOutput.uprintfn """ #quit;; // %s""" (FSIstrings.SR.fsiIntroTextHashquitInfo ()) fsiConsoleOutput.uprintfn "" fsiConsoleOutput.uprintfnn "%s" (FSIstrings.SR.fsiIntroTextHeader2commandLine ()) @@ -3885,6 +3905,10 @@ type FsiInteractionProcessor fsiOptions.ClearScreen() istate, Completed None + | ParsedHashDirective("version", [], _) -> + fsiOptions.ShowVersion() + istate, Completed None + | ParsedHashDirective(("q" | "quit"), [], _) -> fsiInterruptController.Exit() | ParsedHashDirective("help", hashArguments, m) -> diff --git a/src/Compiler/Interactive/xlf/FSIstrings.txt.cs.xlf b/src/Compiler/Interactive/xlf/FSIstrings.txt.cs.xlf index afcff9f805d..a82ae7ec44e 100644 --- a/src/Compiler/Interactive/xlf/FSIstrings.txt.cs.xlf +++ b/src/Compiler/Interactive/xlf/FSIstrings.txt.cs.xlf @@ -27,6 +27,11 @@ Zobrazit dokumentaci k identifikátoru, např. #help \"List.map\";; + + Display F# Interactive version and environment information + Display F# Interactive version and environment information + + Operation could not be completed due to earlier error Operaci nešlo dokončit z důvodu dřívější chyby. diff --git a/src/Compiler/Interactive/xlf/FSIstrings.txt.de.xlf b/src/Compiler/Interactive/xlf/FSIstrings.txt.de.xlf index 3eb197a047d..88109028661 100644 --- a/src/Compiler/Interactive/xlf/FSIstrings.txt.de.xlf +++ b/src/Compiler/Interactive/xlf/FSIstrings.txt.de.xlf @@ -27,6 +27,11 @@ Dokumentation für einen Bezeichner anzeigen, z. B. #help \"List.map\";; + + Display F# Interactive version and environment information + Display F# Interactive version and environment information + + Operation could not be completed due to earlier error Der Vorgang konnte aufgrund eines vorherigen Fehlers nicht abgeschlossen werden. diff --git a/src/Compiler/Interactive/xlf/FSIstrings.txt.es.xlf b/src/Compiler/Interactive/xlf/FSIstrings.txt.es.xlf index 0ad15542bb1..fee036840a0 100644 --- a/src/Compiler/Interactive/xlf/FSIstrings.txt.es.xlf +++ b/src/Compiler/Interactive/xlf/FSIstrings.txt.es.xlf @@ -27,6 +27,11 @@ Mostrar documentación para un identificador, por ejemplo, #help \"List.map\";; + + Display F# Interactive version and environment information + Display F# Interactive version and environment information + + Operation could not be completed due to earlier error La operación no se pudo completar debido a un error anterior diff --git a/src/Compiler/Interactive/xlf/FSIstrings.txt.fr.xlf b/src/Compiler/Interactive/xlf/FSIstrings.txt.fr.xlf index 270a902e005..8e1beb46a98 100644 --- a/src/Compiler/Interactive/xlf/FSIstrings.txt.fr.xlf +++ b/src/Compiler/Interactive/xlf/FSIstrings.txt.fr.xlf @@ -27,6 +27,11 @@ Afficher la documentation pour un identifiant, par ex. #help \"List.map\ » ;; + + Display F# Interactive version and environment information + Display F# Interactive version and environment information + + Operation could not be completed due to earlier error Impossible d'exécuter l'opération en raison d'une erreur antérieure diff --git a/src/Compiler/Interactive/xlf/FSIstrings.txt.it.xlf b/src/Compiler/Interactive/xlf/FSIstrings.txt.it.xlf index c4f58ffb2e4..00ecedc0d2c 100644 --- a/src/Compiler/Interactive/xlf/FSIstrings.txt.it.xlf +++ b/src/Compiler/Interactive/xlf/FSIstrings.txt.it.xlf @@ -27,6 +27,11 @@ Visualizzare la documentazione per un identificatore, ad esempio #help \"List.map\";; + + Display F# Interactive version and environment information + Display F# Interactive version and environment information + + Operation could not be completed due to earlier error Non è stato possibile completare l'operazione a causa di un errore precedente diff --git a/src/Compiler/Interactive/xlf/FSIstrings.txt.ja.xlf b/src/Compiler/Interactive/xlf/FSIstrings.txt.ja.xlf index 2fa2f345369..e103212b70b 100644 --- a/src/Compiler/Interactive/xlf/FSIstrings.txt.ja.xlf +++ b/src/Compiler/Interactive/xlf/FSIstrings.txt.ja.xlf @@ -27,6 +27,11 @@ 識別子のドキュメントを表示する (例:#help \"List.map\";; + + Display F# Interactive version and environment information + Display F# Interactive version and environment information + + Operation could not be completed due to earlier error 以前のエラーが原因で操作を完了できませんでした diff --git a/src/Compiler/Interactive/xlf/FSIstrings.txt.ko.xlf b/src/Compiler/Interactive/xlf/FSIstrings.txt.ko.xlf index 1bc10708ee6..b4839366965 100644 --- a/src/Compiler/Interactive/xlf/FSIstrings.txt.ko.xlf +++ b/src/Compiler/Interactive/xlf/FSIstrings.txt.ko.xlf @@ -27,6 +27,11 @@ 식별자에 대한 설명서 표시(예: #help \"List.map\";;) + + Display F# Interactive version and environment information + Display F# Interactive version and environment information + + Operation could not be completed due to earlier error 이전 오류로 인해 작업을 완료할 수 없습니다. diff --git a/src/Compiler/Interactive/xlf/FSIstrings.txt.pl.xlf b/src/Compiler/Interactive/xlf/FSIstrings.txt.pl.xlf index 63e8a54937d..402a479418a 100644 --- a/src/Compiler/Interactive/xlf/FSIstrings.txt.pl.xlf +++ b/src/Compiler/Interactive/xlf/FSIstrings.txt.pl.xlf @@ -27,6 +27,11 @@ Wyświetl dokumentację identyfikatora, np. #help \"List.map\";; + + Display F# Interactive version and environment information + Display F# Interactive version and environment information + + Operation could not be completed due to earlier error Nie udało się ukończyć operacji z powodu wcześniejszego błędu diff --git a/src/Compiler/Interactive/xlf/FSIstrings.txt.pt-BR.xlf b/src/Compiler/Interactive/xlf/FSIstrings.txt.pt-BR.xlf index 29b3d014cbd..ded6aa4b2a6 100644 --- a/src/Compiler/Interactive/xlf/FSIstrings.txt.pt-BR.xlf +++ b/src/Compiler/Interactive/xlf/FSIstrings.txt.pt-BR.xlf @@ -27,6 +27,11 @@ Exibir documentação para um identificador, por exemplo, #help \"List.map\";; + + Display F# Interactive version and environment information + Display F# Interactive version and environment information + + Operation could not be completed due to earlier error Não foi possível concluir a operação devido a um erro anterior diff --git a/src/Compiler/Interactive/xlf/FSIstrings.txt.ru.xlf b/src/Compiler/Interactive/xlf/FSIstrings.txt.ru.xlf index a00fdf36c9e..5d96fb0cfa7 100644 --- a/src/Compiler/Interactive/xlf/FSIstrings.txt.ru.xlf +++ b/src/Compiler/Interactive/xlf/FSIstrings.txt.ru.xlf @@ -27,6 +27,11 @@ Отобразить документацию для идентификатора, например #help \"List.map\";; + + Display F# Interactive version and environment information + Display F# Interactive version and environment information + + Operation could not be completed due to earlier error Операция не может быть завершена из-за предыдущей ошибки diff --git a/src/Compiler/Interactive/xlf/FSIstrings.txt.tr.xlf b/src/Compiler/Interactive/xlf/FSIstrings.txt.tr.xlf index 15a485e8909..26e326781db 100644 --- a/src/Compiler/Interactive/xlf/FSIstrings.txt.tr.xlf +++ b/src/Compiler/Interactive/xlf/FSIstrings.txt.tr.xlf @@ -27,6 +27,11 @@ Tanımlayıcı ile ilgili belgeleri görüntüle, ör. #help \"List.map\";; + + Display F# Interactive version and environment information + Display F# Interactive version and environment information + + Operation could not be completed due to earlier error Önceki hata nedeniyle işlem tamamlanamadı diff --git a/src/Compiler/Interactive/xlf/FSIstrings.txt.zh-Hans.xlf b/src/Compiler/Interactive/xlf/FSIstrings.txt.zh-Hans.xlf index a8342a21e03..ddbce5edac3 100644 --- a/src/Compiler/Interactive/xlf/FSIstrings.txt.zh-Hans.xlf +++ b/src/Compiler/Interactive/xlf/FSIstrings.txt.zh-Hans.xlf @@ -27,6 +27,11 @@ 显示标识符的文档,例如#help \"List.map\";; + + Display F# Interactive version and environment information + Display F# Interactive version and environment information + + Operation could not be completed due to earlier error 由于早期错误,无法完成操作 diff --git a/src/Compiler/Interactive/xlf/FSIstrings.txt.zh-Hant.xlf b/src/Compiler/Interactive/xlf/FSIstrings.txt.zh-Hant.xlf index 9df8f03da70..208f2f4bc06 100644 --- a/src/Compiler/Interactive/xlf/FSIstrings.txt.zh-Hant.xlf +++ b/src/Compiler/Interactive/xlf/FSIstrings.txt.zh-Hant.xlf @@ -27,6 +27,11 @@ 顯示識別碼的文件,例如#help \"List.map\";; + + Display F# Interactive version and environment information + Display F# Interactive version and environment information + + Operation could not be completed due to earlier error 因為先前發生錯誤,所以無法完成作業 diff --git a/tests/FSharp.Compiler.ComponentTests/Scripting/Interactive.fs b/tests/FSharp.Compiler.ComponentTests/Scripting/Interactive.fs index 7580dae0925..dfded2c01df 100644 --- a/tests/FSharp.Compiler.ComponentTests/Scripting/Interactive.fs +++ b/tests/FSharp.Compiler.ComponentTests/Scripting/Interactive.fs @@ -141,3 +141,19 @@ module MultiEmit = """if A.v <> 7.2 then failwith $"8: Failed {A.v} <> 7.2" """ """if B.v <> 9.3 then failwith $"9: Failed {A.v} <> 9.3" """ |] |> Seq.iter(fun item -> item |> scriptIt) + + [] + let ``Version directive displays version and environment info``() = + Fsx """ +#version;; +() +""" + |> withOptions ["--nologo"] + |> runFsi + |> shouldSucceed + |> withStdOutContains "F#" + |> withStdOutContains "Language Version:" + |> withStdOutContains "FSharp.Core:" + |> withStdOutContains ".NET:" + |> withStdOutContains "OS:" + |> ignore diff --git a/tests/FSharp.Compiler.Private.Scripting.UnitTests/DependencyManagerInteractiveTests.fs b/tests/FSharp.Compiler.Private.Scripting.UnitTests/DependencyManagerInteractiveTests.fs index 95ee4c8f24f..34aeb5f25e8 100644 --- a/tests/FSharp.Compiler.Private.Scripting.UnitTests/DependencyManagerInteractiveTests.fs +++ b/tests/FSharp.Compiler.Private.Scripting.UnitTests/DependencyManagerInteractiveTests.fs @@ -733,6 +733,7 @@ x |> Seq.iter(fun r -> #r "nuget:FSharp.Data, 3.1.2";; // Load Nuget Package 'FSharp.Data' version '3.1.2' #r "nuget:FSharp.Data";; // Load Nuget Package 'FSharp.Data' with the highest version #clear;; // Clear screen + #version;; // Display F# Interactive version and environment information #quit;; // Exit F# Interactive command line options:""" @@ -765,6 +766,7 @@ x |> Seq.iter(fun r -> #r "nuget:FSharp.Data, 3.1.2";; // Load Nuget Package 'FSharp.Data' version '3.1.2' #r "nuget:FSharp.Data";; // Load Nuget Package 'FSharp.Data' with the highest version #clear;; // Clear screen + #version;; // Display F# Interactive version and environment information #quit;; // Exit F# Interactive command line options:""" diff --git a/tests/fsharp/core/printing/output.1000.stdout.bsl b/tests/fsharp/core/printing/output.1000.stdout.bsl index bafd9bb25a2..6b8d9557c78 100644 --- a/tests/fsharp/core/printing/output.1000.stdout.bsl +++ b/tests/fsharp/core/printing/output.1000.stdout.bsl @@ -1105,6 +1105,7 @@ type 'a T4063 = | AT4063 of 'a #r "nuget:FSharp.Data, 3.1.2";; // Load Nuget Package 'FSharp.Data' version '3.1.2' #r "nuget:FSharp.Data";; // Load Nuget Package 'FSharp.Data' with the highest version #clear;; // Clear screen + #version;; // Display F# Interactive version and environment information #quit;; // Exit F# Interactive command line options: diff --git a/tests/fsharp/core/printing/output.200.stdout.bsl b/tests/fsharp/core/printing/output.200.stdout.bsl index b2f769d0b83..43efac1ba14 100644 --- a/tests/fsharp/core/printing/output.200.stdout.bsl +++ b/tests/fsharp/core/printing/output.200.stdout.bsl @@ -425,6 +425,7 @@ type 'a T4063 = | AT4063 of 'a #r "nuget:FSharp.Data, 3.1.2";; // Load Nuget Package 'FSharp.Data' version '3.1.2' #r "nuget:FSharp.Data";; // Load Nuget Package 'FSharp.Data' with the highest version #clear;; // Clear screen + #version;; // Display F# Interactive version and environment information #quit;; // Exit F# Interactive command line options: diff --git a/tests/fsharp/core/printing/output.47.stdout.bsl b/tests/fsharp/core/printing/output.47.stdout.bsl index a6b19a1ab53..019a77c641c 100644 --- a/tests/fsharp/core/printing/output.47.stdout.bsl +++ b/tests/fsharp/core/printing/output.47.stdout.bsl @@ -4062,6 +4062,7 @@ type 'a T4063 = | AT4063 of 'a #help;; // Display help #help "idn";; // Display documentation for an identifier, e.g. #help "List.map";; #clear;; // Clear screen + #version;; // Display F# Interactive version and environment information #quit;; // Exit F# Interactive command line options: diff --git a/tests/fsharp/core/printing/output.multiemit.stdout.bsl b/tests/fsharp/core/printing/output.multiemit.stdout.bsl index 8a7c1ed3e4b..7aa141b7ac9 100644 --- a/tests/fsharp/core/printing/output.multiemit.stdout.bsl +++ b/tests/fsharp/core/printing/output.multiemit.stdout.bsl @@ -4064,6 +4064,7 @@ type 'a T4063 = | AT4063 of 'a #r "nuget:FSharp.Data, 3.1.2";; // Load Nuget Package 'FSharp.Data' version '3.1.2' #r "nuget:FSharp.Data";; // Load Nuget Package 'FSharp.Data' with the highest version #clear;; // Clear screen + #version;; // Display F# Interactive version and environment information #quit;; // Exit F# Interactive command line options: diff --git a/tests/fsharp/core/printing/output.off.stdout.bsl b/tests/fsharp/core/printing/output.off.stdout.bsl index 17a3f6aca61..7ea556425e4 100644 --- a/tests/fsharp/core/printing/output.off.stdout.bsl +++ b/tests/fsharp/core/printing/output.off.stdout.bsl @@ -252,6 +252,7 @@ type 'a T4063 = | AT4063 of 'a #r "nuget:FSharp.Data, 3.1.2";; // Load Nuget Package 'FSharp.Data' version '3.1.2' #r "nuget:FSharp.Data";; // Load Nuget Package 'FSharp.Data' with the highest version #clear;; // Clear screen + #version;; // Display F# Interactive version and environment information #quit;; // Exit F# Interactive command line options: diff --git a/tests/fsharp/core/printing/output.stdout.bsl b/tests/fsharp/core/printing/output.stdout.bsl index 8a7c1ed3e4b..7aa141b7ac9 100644 --- a/tests/fsharp/core/printing/output.stdout.bsl +++ b/tests/fsharp/core/printing/output.stdout.bsl @@ -4064,6 +4064,7 @@ type 'a T4063 = | AT4063 of 'a #r "nuget:FSharp.Data, 3.1.2";; // Load Nuget Package 'FSharp.Data' version '3.1.2' #r "nuget:FSharp.Data";; // Load Nuget Package 'FSharp.Data' with the highest version #clear;; // Clear screen + #version;; // Display F# Interactive version and environment information #quit;; // Exit F# Interactive command line options: