Skip to content

Commit

Permalink
Merge pull request #324 from waf/set-default-culture-for-compile-errors
Browse files Browse the repository at this point in the history
Set default culture for compile error messages
  • Loading branch information
waf authored Nov 24, 2023
2 parents 884985f + 081c7fa commit e41f024
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CSharpRepl.Services/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public Configuration(
submitPrompt,
triggerOverloadList: new(new KeyPressPattern('('), new KeyPressPattern('['), new KeyPressPattern(','), new KeyPressPattern('<')));

Culture = string.IsNullOrWhiteSpace(cultureName) ? CultureInfo.CurrentCulture : CultureInfo.GetCultureInfo(cultureName, true);
Culture = string.IsNullOrWhiteSpace(cultureName) ? CultureInfo.CurrentUICulture : CultureInfo.GetCultureInfo(cultureName, true);
}

public CultureInfo Culture { get; }
Expand Down
30 changes: 17 additions & 13 deletions CSharpRepl/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -35,6 +36,8 @@ internal static async Task<int> Main(string[] args)
if (!TryParseArguments(args, configFile, out var config))
return ExitCodes.ErrorParseArguments;

SetDefaultCulture(config);

if (config.OutputForEarlyExit.Text is not null)
{
console.WriteLine(config.OutputForEarlyExit);
Expand All @@ -46,14 +49,14 @@ internal static async Task<int> Main(string[] args)
var roslyn = new RoslynServices(console, config, logger);

// we're getting piped input, just evaluate the input and exit.
if(Console.IsInputRedirected)
if (Console.IsInputRedirected)
{
var evaluator = new PipedInputEvaluator(console, roslyn);
return config.StreamPipedInput
? await evaluator.EvaluateStreamingPipeInputAsync()
: await evaluator.EvaluateCollectedPipeInputAsync();
? await evaluator.EvaluateStreamingPipeInputAsync().ConfigureAwait(false)
: await evaluator.EvaluateCollectedPipeInputAsync().ConfigureAwait(false);
}
else if(config.StreamPipedInput)
else if (config.StreamPipedInput)
{
console.WriteErrorLine("--streamPipedInput specified but no redirected input received. This configuration option should be used with redirected standard input.");
return ExitCodes.ErrorParseArguments;
Expand Down Expand Up @@ -107,18 +110,19 @@ private static string CreateApplicationStorageDirectory()
return appStorage;
}

private static void SetDefaultCulture(Configuration config)
{
CultureInfo.DefaultThreadCurrentUICulture = config.Culture;
// theoretically we shouldn't need to do the following, but in practice we need it in order to
// get compiler errors emitted by CSharpScript in the right language (see https://github.com/waf/CSharpRepl/issues/312)
CultureInfo.DefaultThreadCurrentCulture = config.Culture;
}

/// <summary>
/// Initialize logging. It's off by default, unless the user passes the --trace flag.
/// </summary>
private static ITraceLogger InitializeLogging(bool trace)
{
if (!trace)
{
return new NullLogger();
}

return TraceLogger.Create($"csharprepl-tracelog-{DateTime.UtcNow:yyyy-MM-dd}.txt");
}
private static ITraceLogger InitializeLogging(bool trace) =>
!trace ? new NullLogger() : TraceLogger.Create($"csharprepl-tracelog-{DateTime.UtcNow:yyyy-MM-dd}.txt");

private static (Prompt? prompt, int exitCode) InitializePrompt(IConsoleEx console, string appStorage, RoslynServices roslyn, Configuration config)
{
Expand Down

0 comments on commit e41f024

Please sign in to comment.