Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix analyzer [RCS1196](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1196) ([PR](https://github.com/dotnet/roslynator/pull/1235))
- Fix analyzer [RCS1257](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1257) ([PR](https://github.com/dotnet/roslynator/pull/1264))
- Fix analyzer [RCS1259](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1259) ([PR](https://github.com/dotnet/roslynator/pull/1268))
- [CLI] Fix reading of non-existent redirected input on git bash ([PR](https://github.com/dotnet/roslynator/pull/1265))
- [CLI] Fix reading of non-existent redirected input on git bash ([PR](https://github.com/dotnet/roslynator/pull/1265), [PR](https://github.com/dotnet/roslynator/pull/1274))
- [CLI] Fix exit code for `roslynator --version` ([PR](https://github.com/dotnet/roslynator/pull/1273))

## [4.6.2] - 2023-11-10
Expand Down
13 changes: 11 additions & 2 deletions src/CommandLine/ConsoleHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Roslynator.CommandLine;

internal static class ConsoleHelpers
{
public static async Task<ImmutableArray<string>> ReadRedirectedInputAsLines()
public static ImmutableArray<string> ReadRedirectedInputAsLines()
{
if (Console.IsInputRedirected)
{
Expand All @@ -18,9 +18,18 @@ public static async Task<ImmutableArray<string>> ReadRedirectedInputAsLines()
using (Stream stream = Console.OpenStandardInput())
using (var streamReader = new StreamReader(stream, Console.InputEncoding))
{
Task<string> readLineTask = streamReader.ReadLineAsync();

// https://github.com/dotnet/runtime/issues/95079
if (!readLineTask.Wait(TimeSpan.FromMilliseconds(500)))
return default;

if (readLineTask.Result is null)
return ImmutableArray<string>.Empty;

string line;

while ((line = await streamReader.ReadLineAsync()) is not null)
while ((line = streamReader.ReadLine()) is not null)
lines.Add(line);
}

Expand Down
17 changes: 8 additions & 9 deletions src/CommandLine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -842,14 +842,17 @@ private static bool TryParsePaths(IEnumerable<string> values, out ImmutableArray

if (Console.IsInputRedirected)
{
Task<ImmutableArray<string>> task = ConsoleHelpers.ReadRedirectedInputAsLines();

WriteLine("Reading redirected input...", Verbosity.Diagnostic);

// https://github.com/dotnet/runtime/issues/95079
if (task.Wait(TimeSpan.FromMilliseconds(500)))
ImmutableArray<string> lines = ConsoleHelpers.ReadRedirectedInputAsLines();

if (lines.IsDefault)
{
WriteLine("Unable to read redirected input", Verbosity.Diagnostic);
}
else
{
IEnumerable<string> paths1 = task.Result.Where(f => !string.IsNullOrEmpty(f));
IEnumerable<string> paths1 = lines.Where(f => !string.IsNullOrEmpty(f));

WriteLine("Successfully read redirected input:" + Environment.NewLine + " " + string.Join(Environment.NewLine + " ", paths1), Verbosity.Diagnostic);

Expand All @@ -858,10 +861,6 @@ private static bool TryParsePaths(IEnumerable<string> values, out ImmutableArray

paths = paths.AddRange(ImmutableArray.CreateRange(paths2, f => new PathInfo(f, PathOrigin.PipedInput)));
}
else
{
WriteLine("Unable to read redirected input", Verbosity.Diagnostic);
}
}

if (!paths.IsEmpty)
Expand Down