Skip to content

Commit

Permalink
Merge branch 'waf:main' into custom-culture
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyros committed Sep 4, 2023
2 parents 46fd47a + af2ac23 commit d28fc6c
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 27 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## Release 0.6.5

- Upgrade PrettyPrompt library to get the following fixes:
- Handle invalid history entries / history log corruption ([#267](https://github.com/waf/PrettyPrompt/pull/267)).

## Release 0.6.4

- Make help command show dynamic keybindings ([#289](https://github.com/waf/CSharpRepl/pull/289))
- Fix annoying completion commit triggers for dynamic variables and C# Range syntax ([#290](https://github.com/waf/CSharpRepl/pull/290))
- Minor NuGet upgrades and code cleanup ([#285](https://github.com/waf/CSharpRepl/pull/285) and [#291](https://github.com/waf/CSharpRepl/pull/291))
- Upgrade PrettyPrompt library to get the following fixes:
- Better error messages on Linux when xsel is not installed ([#264](https://github.com/waf/PrettyPrompt/pull/264)).
- Fix crash when Shift-Delete is pressed under certain conditions ([#263](https://github.com/waf/PrettyPrompt/pull/263)).
- Add workaround for garbled utf-8 characters on Linux ([#261](https://github.com/waf/PrettyPrompt/pull/261)).

## Release 0.6.3

- If msbuild cannot be located, still allow basic REPL usage.
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Thanks to everyone who contributes! The following contributors have helped out w
- Marlon Regenhardt ([Regenhardt](https://github.com/Regenhardt))
- Luiz-Ossinho ([Luiz-Ossinho](https://github.com/Luiz-Ossinho))
- Vinod Pal ([VNDPAL](https://github.com/VNDPAL))
- Rasim Keita ([Keyros](https://github.com/Keyros))

## PrettyPrompt Contributors

Expand Down
2 changes: 1 addition & 1 deletion CSharpRepl.Services/CSharpRepl.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
<PackageReference Include="Microsoft.SymbolStore" Version="1.0.431901" />
<PackageReference Include="PrettyPrompt" Version="4.0.9" />
<PackageReference Include="PrettyPrompt" Version="4.1.0" />
<PackageReference Include="Spectre.Console.Cli" Version="0.47.0" />
<PackageReference Include="System.IO.Abstractions" Version="19.2.29" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
Expand Down
32 changes: 32 additions & 0 deletions CSharpRepl.Services/Extensions/KeyExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Linq;
using PrettyPrompt.Consoles;

namespace CSharpRepl.Services.Extensions;

public static class KeyExtensions
{
private static string GetStringValue(this KeyPressPattern pattern)
{
if (pattern.Key != default)
{
return pattern.Modifiers == default
? $"{pattern.Key}"
: $"{pattern.Modifiers.GetStringValue()}+{pattern.Key}";
}

return $"{pattern.Character}";
}

private static string GetStringValue(this ConsoleModifiers modifiers)
{
var values = Enum.GetValues<ConsoleModifiers>()
.Where(x => modifiers.HasFlag(x))
.OrderByDescending(x => x)
.Select(x => x.ToString());
return string.Join("+", values);
}

public static string GetStringValue(this KeyPressPatterns patterns)
=> patterns.DefinedPatterns!.First().GetStringValue();
}
18 changes: 15 additions & 3 deletions CSharpRepl.Services/Roslyn/RoslynServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,27 @@ public async Task<bool> ConfirmCompletionCommit(string text, int caret, KeyPress
{
var node = await GetNode().ConfigureAwait(false);
if (node is
ArgumentSyntax or //https://github.com/waf/CSharpRepl/issues/145
ArgumentListSyntax or //https://github.com/waf/CSharpRepl/issues/200
AnonymousObjectMemberDeclaratorSyntax) //https://github.com/waf/CSharpRepl/issues/157
ArgumentSyntax //https://github.com/waf/CSharpRepl/issues/145
or ArgumentListSyntax //https://github.com/waf/CSharpRepl/issues/200
or AnonymousObjectMemberDeclaratorSyntax //https://github.com/waf/CSharpRepl/issues/157
or VariableDeclaratorSyntax) // dynamic declarator https://github.com/waf/CSharpRepl/issues/231
{

return false;
}
}

if (keyChar is '.')
{
var node = await GetNode().ConfigureAwait(false);
// entering range syntax arr[1..2] https://github.com/waf/CSharpRepl/issues/279
if (node is ArgumentSyntax { Parent: BracketedArgumentListSyntax, Expression: MemberAccessExpressionSyntax }
or BracketedArgumentListSyntax { Parent: ElementAccessExpressionSyntax })
{
return false;
}
}

if (keyChar is ',' or ')')
{
var node = await GetNode().ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion CSharpRepl.Tests/CSharpRepl.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="PrettyPrompt" Version="4.0.9" />
<PackageReference Include="PrettyPrompt" Version="4.1.0" />
<PackageReference Include="Spectre.Console.Testing" Version="0.47.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="19.2.29" />
<PackageReference Include="xunit" Version="2.5.0" />
Expand Down
28 changes: 25 additions & 3 deletions CSharpRepl.Tests/ReadEvalPrintLoopTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ public async Task RunAsync_HelpCommand_ShowsHelp(string help)
Assert.Contains("Type C# at the prompt", console.AnsiConsole.Output);
}

[Theory]
[InlineData("Control+Tab", "Control+Enter", "Control+Shift+Enter")]
[InlineData("Enter", "Control+A", "Control+Shift+A")]
[InlineData("º", "", "ç")]
public async Task RunAsync_HelpCommand_ShowsPassedKeyBindings(string submitKeyPattern, string submitDetailedKeyPattern, string newLineKeyPattern)
{
prompt
.ReadLineAsync()
.Returns(
new PromptResult(true, "help", default),
new PromptResult(true, "exit", default)
);

await repl.RunAsync(new Configuration(submitPromptKeyPatterns: new[] {submitKeyPattern},
submitPromptDetailedKeyPatterns: new[] {submitDetailedKeyPattern}, newLineKeyPatterns: new[] {newLineKeyPattern}));

Assert.Contains(submitKeyPattern, console.AnsiConsole.Output);
Assert.Contains(submitDetailedKeyPattern, console.AnsiConsole.Output);
Assert.Contains(newLineKeyPattern, console.AnsiConsole.Output);
}


[Fact]
public async Task RunAsync_ClearCommand_ClearsScreen()
{
Expand All @@ -62,7 +84,7 @@ public async Task RunAsync_ClearCommand_ClearsScreen()

await repl.RunAsync(new Configuration());

((IConsoleEx)console.Received()).Clear(true);
((IConsoleEx) console.Received()).Clear(true);
}

[Fact]
Expand Down Expand Up @@ -108,7 +130,7 @@ public async Task RunAsync_Reference_AddsReference()
);

await repl.RunAsync(new Configuration(
references: new[] { "Data/DemoLibrary.dll" }
references: new[] {"Data/DemoLibrary.dll"}
));

Assert.Contains("30", console.AnsiConsole.Output);
Expand Down Expand Up @@ -170,4 +192,4 @@ public async Task RunAsync_ExitCommand_ExitsRepl()

// by reaching here, the application correctly exited.
}
}
}
4 changes: 2 additions & 2 deletions CSharpRepl.Tests/RoslynServicesTests.Overloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public async Task Complete_RecursiveGenerics(string code)
Assert.True(result.Overloads.Count == 1);
Assert.Equal(0, result.ArgumentIndex);
Assert.Contains("List", result.Overloads[0].Signature.Text);
Assert.Equal(1, result.Overloads[0].Parameters.Count);
Assert.Single(result.Overloads[0].Parameters);
Assert.Equal("T", result.Overloads[0].Parameters[0].Name);
}

Expand Down Expand Up @@ -301,7 +301,7 @@ public async Task Complete_ParamWithoutXmlDoc()
Assert.Equal(0, result.ArgumentIndex);
var overload = result.Overloads[0];
Assert.Contains("M", overload.Signature.Text);
Assert.Equal(1, overload.Parameters.Count);
Assert.Single(overload.Parameters);
Assert.Equal("i", overload.Parameters[0].Name);
}

Expand Down
22 changes: 22 additions & 0 deletions CSharpRepl.Tests/RoslynServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,28 @@ yield return
@"new int[] { 1, 2, 3 }.Select((i,v)=>i).Count()",
"3"
);

// https://github.com/waf/CSharpRepl/issues/231 - dynamic variable declaration
yield return
(
$@"dynamic d{Spacebar} = 1; d{Enter}{Enter}exit{Enter}",
@"dynamic d = 1; d",
"1"
);

// https://github.com/waf/CSharpRepl/issues/279 - range syntax
yield return
(
$@"int[] a = {{ 1, 2, 3, 4 }}; a[1..2][0]{Enter}exit{Enter}",
@"int[] a = { 1, 2, 3, 4 }; a[1..2][0]",
"2"
);
yield return
(
$@"int[] a = {{ 1, 2, 3, 4 }}; a[(2-1)..(3-1)][0]{Enter}exit{Enter}",
@"int[] a = { 1, 2, 3, 4 }; a[(2-1)..(3-1)][0]",
"2"
);
}
}

Expand Down
18 changes: 9 additions & 9 deletions CSharpRepl.Tests/StyledStringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ public void SubstringSimple()

var subtext = text.Substring(0, 4);
Assert.Equal("abcd", subtext.ToString());
Assert.Equal(1, subtext.Parts.Count);
Assert.Single(subtext.Parts);
Assert.Equal(style, subtext.Parts[0].Style);

subtext = text.Substring(0, 2);
Assert.Equal("ab", subtext.ToString());
Assert.Equal(1, subtext.Parts.Count);
Assert.Single(subtext.Parts);
Assert.Equal(style, subtext.Parts[0].Style);

subtext = text.Substring(1, 2);
Assert.Equal("bc", subtext.ToString());
Assert.Equal(1, subtext.Parts.Count);
Assert.Single(subtext.Parts);
Assert.Equal(style, subtext.Parts[0].Style);

subtext = text.Substring(2, 2);
Assert.Equal("cd", subtext.ToString());
Assert.Equal(1, subtext.Parts.Count);
Assert.Single(subtext.Parts);
Assert.Equal(style, subtext.Parts[0].Style);

subtext = text.Substring(2, 0);
Assert.Equal("", subtext.ToString());
Assert.Equal(0, subtext.Parts.Count);
Assert.Empty(subtext.Parts);
}
}

Expand Down Expand Up @@ -79,12 +79,12 @@ public void SubstringComplex()

subtext = text.Substring(0, 2);
Assert.Equal("ab", subtext.ToString());
Assert.Equal(1, subtext.Parts.Count);
Assert.Single(subtext.Parts);
Assert.Equal(redStyle, subtext.Parts[0].Style);

subtext = text.Substring(0, 1);
Assert.Equal("a", subtext.ToString());
Assert.Equal(1, subtext.Parts.Count);
Assert.Single(subtext.Parts);
Assert.Equal(redStyle, subtext.Parts[0].Style);

///////////////////////////////////////////////////////////////////////
Expand All @@ -110,12 +110,12 @@ public void SubstringComplex()

subtext = text.Substring(4, 2);
Assert.Equal("ef", subtext.ToString());
Assert.Equal(1, subtext.Parts.Count);
Assert.Single(subtext.Parts);
Assert.Equal(blueStyle, subtext.Parts[0].Style);

subtext = text.Substring(5, 1);
Assert.Equal("f", subtext.ToString());
Assert.Equal(1, subtext.Parts.Count);
Assert.Single(subtext.Parts);
Assert.Equal(blueStyle, subtext.Parts[0].Style);

///////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions CSharpRepl/CSharpRepl.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>0.6.3</Version>
<Version>0.6.5</Version>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RollForward>LatestMajor</RollForward>
Expand All @@ -25,7 +25,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PrettyPrompt" Version="4.0.9" />
<PackageReference Include="PrettyPrompt" Version="4.1.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="7.0.0" />
</ItemGroup>
Expand Down
18 changes: 12 additions & 6 deletions CSharpRepl/ReadEvalPrintLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using CSharpRepl.PrettyPromptConfig;
using CSharpRepl.Services;
using CSharpRepl.Services.Extensions;
using CSharpRepl.Services.Roslyn;
using CSharpRepl.Services.Roslyn.Formatting;
using CSharpRepl.Services.Roslyn.Scripting;
Expand Down Expand Up @@ -61,7 +62,7 @@ public async Task RunAsync(Configuration config)
if (commandText == "clear") { console.Clear(); continue; }
if (new[] { "help", "#help", "?" }.Contains(commandText))
{
PrintHelp();
PrintHelp(config.KeyBindings, config.SubmitPromptDetailedKeys);
continue;
}

Expand Down Expand Up @@ -142,18 +143,23 @@ private static async Task PrintAsync(RoslynServices roslyn, IConsoleEx console,
}
}

private void PrintHelp()

private void PrintHelp(KeyBindings keyBindings, KeyPressPatterns submitPromptDetailedKeys)
{
var newLineBindingName = keyBindings.NewLine.GetStringValue();
var submitPromptName = keyBindings.SubmitPrompt.GetStringValue();
var submitPromptDetailedName = submitPromptDetailedKeys.GetStringValue();

console.WriteLine(
$@"
$@"
More details and screenshots are available at
https://github.com/waf/CSharpRepl/blob/main/README.md
Evaluating Code
===============
Type C# at the prompt and press {Underline("Enter")} to run it. The result will be printed.
{Underline("Ctrl+Enter")} will also run the code, but show detailed member info / stack traces.
{Underline("Shift+Enter")} will insert a newline, to support multiple lines of input.
Type C# at the prompt and press {Underline(submitPromptName)} to run it. The result will be printed.
{Underline(submitPromptDetailedName)} will also run the code, but show detailed member info / stack traces.
{Underline(newLineBindingName)} will insert a newline, to support multiple lines of input.
If the code isn't a complete statement, pressing Enter will insert a newline.
Adding References
Expand Down

0 comments on commit d28fc6c

Please sign in to comment.