Skip to content

Commit aaa2caa

Browse files
forkibaronfel
authored andcommitted
Allow to set PreferredUILang from tests (#7102)
1 parent 471940d commit aaa2caa

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/fsharp/service/Reactor.fs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type Reactor() =
3535

3636
// We need to store the culture for the VS thread that is executing now,
3737
// so that when the reactor picks up a thread from the threadpool we can set the culture
38-
let culture = new CultureInfo(CultureInfo.CurrentUICulture.Name)
38+
let mutable culture = CultureInfo(CultureInfo.CurrentUICulture.Name)
3939

4040
let mutable bgOpCts = new CancellationTokenSource()
4141
/// Mailbox dispatch function.
@@ -135,6 +135,17 @@ type Reactor() =
135135
Debug.Assert(false, String.Format("unexpected failure in reactor loop {0}, restarting", e))
136136
}
137137

138+
member __.SetPreferredUILang(preferredUiLang: string option) =
139+
match preferredUiLang with
140+
| Some s ->
141+
culture <- CultureInfo s
142+
#if FX_RESHAPED_GLOBALIZATION
143+
CultureInfo.CurrentUICulture <- culture
144+
#else
145+
Thread.CurrentThread.CurrentUICulture <- culture
146+
#endif
147+
| None -> ()
148+
138149
// [Foreground Mailbox Accessors] -----------------------------------------------------------
139150
member r.SetBackgroundOp(bgOpOpt) =
140151
Trace.TraceInformation("Reactor: {0:n3} enqueue start background, length {1}", DateTime.Now.TimeOfDay.TotalSeconds, builder.CurrentQueueLength)

src/fsharp/service/Reactor.fsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ type internal IReactorOperations =
2323
[<Sealed>]
2424
type internal Reactor =
2525

26+
/// Allows to specify the language for error messages
27+
member SetPreferredUILang : string option -> unit
28+
2629
/// Set the background building function, which is called repeatedly
2730
/// until it returns 'false'. If None then no background operation is used.
2831
member SetBackgroundOp : ( (* userOpName:*) string * (* opName: *) string * (* opArg: *) string * (CompilationThreadToken -> CancellationToken -> bool)) option -> unit

src/fsharp/service/service.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
518518
keepAssemblyContents,
519519
suggestNamesForErrors)
520520
let parsingOptions = FSharpParsingOptions.FromTcConfig(tcPrior.TcConfig, Array.ofList builder.SourceFiles, options.UseScriptResolutionRules)
521+
reactor.SetPreferredUILang tcPrior.TcConfig.preferredUiLang
521522
bc.RecordTypeCheckFileInProjectResults(fileName, options, parsingOptions, parseResults, fileVersion, tcPrior.TimeStamp, Some checkAnswer, sourceText.GetHashCode())
522523
return checkAnswer
523524
finally
@@ -635,6 +636,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
635636

636637
// Do the parsing.
637638
let parsingOptions = FSharpParsingOptions.FromTcConfig(builder.TcConfig, Array.ofList (builder.SourceFiles), options.UseScriptResolutionRules)
639+
reactor.SetPreferredUILang tcPrior.TcConfig.preferredUiLang
638640
let parseErrors, parseTreeOpt, anyErrors = ParseAndCheckFile.parseFile (sourceText, filename, parsingOptions, userOpName, suggestNamesForErrors)
639641
let parseResults = FSharpParseFileResults(parseErrors, parseTreeOpt, anyErrors, builder.AllDependenciesDeprecated)
640642
let! checkResults = bc.CheckOneFileImpl(parseResults, sourceText, filename, options, textSnapshotInfo, fileVersion, builder, tcPrior, creationErrors, userOpName)

0 commit comments

Comments
 (0)