提交 39fb7809 编写于 作者: G Gen Lu

Add `#help` command to csi/vbi

上级 6ac25776
......@@ -48,6 +48,7 @@ public void Await()
$@"Microsoft (R) Visual C# Interactive Compiler version {CompilerVersion}
Copyright (C) Microsoft Corporation. All rights reserved.
Type ""#help"" for more information.
> async Task<int[]> GetStuffAsync()
. {{
. return new int[] {{ 1, 2, 3, 4, 5 }};
......@@ -76,6 +77,7 @@ public void Exception()
$@"Microsoft (R) Visual C# Interactive Compiler version {CompilerVersion}
Copyright (C) Microsoft Corporation. All rights reserved.
Type ""#help"" for more information.
> int div(int a, int b) => a/b;
> div(10, 2)
5
......@@ -101,6 +103,7 @@ public void Args()
$@"Microsoft (R) Visual C# Interactive Compiler version {CompilerVersion}
Copyright (C) Microsoft Corporation. All rights reserved.
Type ""#help"" for more information.
> foreach (var arg in Args) Print(arg);
""arg1""
""arg2""
......@@ -200,5 +203,29 @@ public void ResponseFile()
"System.Text",
}, arguments.CompilationOptions.Usings.AsEnumerable());
}
[Fact]
public void HelpCommand()
{
var runner = CreateRunner(input:
@"#help
");
runner.RunInteractive();
Assert.Equal(
$@"Microsoft (R) Visual C# Interactive Compiler version {CompilerVersion}
Copyright (C) Microsoft Corporation. All rights reserved.
Type ""#help"" for more information.
> #help
Keyboard shortcuts:
Enter If the current submission appears to be complete, evaluate it. Otherwise, insert a new line.
Escape Clear the current submission.
UpArrow Replace the current submission with a previous submission.
DownArrow Replace the current submission with a subsequent submission (after having previously navigated backwards).
REPL commands:
#help Display help on available commands and key bindings.
> ", runner.Console.Out.ToString());
}
}
}
......@@ -163,6 +163,8 @@ private int RunScript(ScriptOptions options, string code, string scriptPath, Err
private void RunInteractiveLoop(ScriptOptions options, CancellationToken cancellationToken)
{
_console.Out.WriteLine(ScriptingResources.HelpPrompt);
var globals = new InteractiveScriptGlobals(_console.Out, _objectFormatter);
globals.Args.AddRange(_compiler.Arguments.ScriptArguments);
......@@ -207,6 +209,12 @@ private void RunInteractiveLoop(ScriptOptions options, CancellationToken cancell
string code = input.ToString();
if (IsHelpCommand(code))
{
DisplayHelpText();
continue;
}
Script<object> newScript;
if (state == null)
{
......@@ -329,6 +337,19 @@ private static bool IsTaskAwaiter(Type type)
return false;
}
private static bool IsHelpCommand(string text)
{
const string helpCommand = "#help";
return text != null &&
text.TrimStart().TrimEnd() == helpCommand;
}
private void DisplayHelpText()
{
_console.Out.Write(ScriptingResources.HelpText);
_console.Out.WriteLine();
}
private void DisplayDiagnostics(IEnumerable<Diagnostic> diagnostics)
{
const int MaxDisplayCount = 5;
......
......@@ -11,8 +11,8 @@
namespace Microsoft.CodeAnalysis.Scripting {
using System;
using System.Reflection;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
......@@ -142,6 +142,30 @@ internal class ScriptingResources {
}
}
/// <summary>
/// Looks up a localized string similar to Type &quot;#help&quot; for more information..
/// </summary>
internal static string HelpPrompt {
get {
return ResourceManager.GetString("HelpPrompt", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Keyboard shortcuts:
/// Enter If the current submission appears to be complete, evaluate it. Otherwise, insert a new line.
/// Escape Clear the current submission.
/// UpArrow Replace the current submission with a previous submission.
/// DownArrow Replace the current submission with a subsequent submission (after having previously navigated backwards).
///REPL commands:
/// #help Display help on available commands and key bindings..
/// </summary>
internal static string HelpText {
get {
return ResourceManager.GetString("HelpText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Invalid assembly name.
/// </summary>
......
......@@ -146,4 +146,16 @@
<data name="CannotSetConstantVariable" xml:space="preserve">
<value>Cannot set a constant variable</value>
</data>
<data name="HelpPrompt" xml:space="preserve">
<value>Type "#help" for more information.</value>
</data>
<data name="HelpText" xml:space="preserve">
<value>Keyboard shortcuts:
Enter If the current submission appears to be complete, evaluate it. Otherwise, insert a new line.
Escape Clear the current submission.
UpArrow Replace the current submission with a previous submission.
DownArrow Replace the current submission with a subsequent submission (after having previously navigated backwards).
REPL commands:
#help Display help on available commands and key bindings.</value>
</data>
</root>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册