Skip to content

Commit f40ffbb

Browse files
CopilotT-Gro
andcommitted
Fix preferreduilang switch leaking into fsi.CommandLineArgs
Co-authored-by: T-Gro <[email protected]>
1 parent 47d5e89 commit f40ffbb

File tree

1 file changed

+18
-12
lines changed
  • src/Compiler/Interactive

1 file changed

+18
-12
lines changed

src/Compiler/Interactive/fsi.fs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,22 +1070,28 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig, argv: s
10701070
let scriptArgs = List.tail args
10711071

10721072
// Filter out and process preferreduilang from script args
1073+
let isPreferredUiLangArg (arg: string) =
1074+
arg.StartsWith("--preferreduilang:", StringComparison.OrdinalIgnoreCase)
1075+
|| arg.StartsWith("/preferreduilang:", StringComparison.OrdinalIgnoreCase)
1076+
10731077
let rec filterScriptArgs (args: string list) =
10741078
match args with
10751079
| [] -> []
1076-
| (arg: string) :: rest when
1077-
arg.StartsWith("--preferreduilang:", StringComparison.OrdinalIgnoreCase)
1078-
|| arg.StartsWith("/preferreduilang:", StringComparison.OrdinalIgnoreCase)
1079-
->
1080+
| (arg: string) :: rest when isPreferredUiLangArg arg ->
10801081
// Extract culture and set it
1081-
let culture = arg.Substring(arg.IndexOf(':') + 1)
1082-
1083-
try
1084-
tcConfigB.preferredUiLang <- Some culture
1085-
Thread.CurrentThread.CurrentUICulture <- CultureInfo(culture)
1086-
with _ ->
1087-
// Ignore invalid culture, just don't set it
1088-
()
1082+
let colonIndex = arg.IndexOf(':')
1083+
1084+
if colonIndex >= 0 && colonIndex < arg.Length - 1 then
1085+
let culture = arg.Substring(colonIndex + 1)
1086+
1087+
try
1088+
tcConfigB.preferredUiLang <- Some culture
1089+
Thread.CurrentThread.CurrentUICulture <- CultureInfo(culture)
1090+
with
1091+
| :? CultureNotFoundException
1092+
| :? ArgumentException ->
1093+
// Ignore invalid culture, just don't set it
1094+
()
10891095

10901096
filterScriptArgs rest
10911097
| arg :: rest -> arg :: filterScriptArgs rest

0 commit comments

Comments
 (0)