Skip to content

Commit

Permalink
Merge pull request #628 from DustinCampbell/fix-encoding
Browse files Browse the repository at this point in the history
Fix OmniSharp --encoding switch to apply to both stdin and stdout
  • Loading branch information
DustinCampbell authored Aug 27, 2016
2 parents 36f4a96 + 982d980 commit 9c835ea
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/OmniSharp.Host/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ public static void Main(string[] args)
var config = new ConfigurationBuilder()
.AddCommandLine(new[] { "--server.urls", $"http://{serverInterface}:{serverPort}" });

// If the --encoding switch was specified, we need to set the InputEncoding and OutputEncoding before
// constructing the SharedConsoleWriter. Otherwise, it might be created with the wrong encoding since
// it wraps around Console.Out, which gets recreated when OutputEncoding is set.
if (transportType == TransportType.Stdio && encoding != null)
{
Console.InputEncoding = encoding;
Console.OutputEncoding = encoding;
}

var writer = new SharedConsoleWriter();

var builder = new WebHostBuilder()
Expand All @@ -107,11 +116,6 @@ public static void Main(string[] args)

if (transportType == TransportType.Stdio)
{
if (encoding != null)
{
Console.InputEncoding = encoding;
Console.OutputEncoding = encoding;
}
builder.UseServer(new StdioServer(Console.In, writer));
}
else
Expand Down

0 comments on commit 9c835ea

Please sign in to comment.