提交 4cbca845 编写于 作者: G Gen Lu

Add check for displaying script directive help to avoid interfere with other interactive window

上级 1170212b
......@@ -53,7 +53,8 @@ internal Commands(IInteractiveWindow window, string prefix, IEnumerable<IInterac
{
length += _commandSeparator.Length;
}
length += name.Length;
// plus the length of `#` for display purpose
length += name.Length + 1;
commandsDict[name] = command;
}
......@@ -167,7 +168,7 @@ internal IEnumerable<string> Help()
{
string format = "{0,-" + _maxCommandNameLength + "} {1}";
return _commands.GroupBy(entry => entry.Value).
Select(group => string.Format(format, string.Join(_commandSeparator, group.Key.Names), group.Key.Description)).
Select(group => string.Format(format, string.Join(_commandSeparator, group.Key.Names.Select(s => "#" + s)), group.Key.Description)).
OrderBy(line => line);
}
......@@ -256,10 +257,10 @@ private async Task<ExecutionResult> ExecuteCommandAsync(IInteractiveWindowComman
"Ctrl-A " + InteractiveWindowResources.CtrlAHelp,
};
private static readonly string[] s_scriptDirectives = new[]
private static readonly string[] s_CSVBScriptDirectives = new[]
{
"r " + InteractiveWindowResources.RefHelp,
"load " + InteractiveWindowResources.LoadHelp
"#r " + InteractiveWindowResources.RefHelp,
"#load " + InteractiveWindowResources.LoadHelp
};
public void DisplayHelp()
......@@ -278,11 +279,18 @@ public void DisplayHelp()
_window.WriteLine(line);
}
_window.WriteLine(InteractiveWindowResources.ScriptDirectives);
foreach (var line in s_scriptDirectives)
// Hack: Display script directives only in CS/VB interactive window
// TODO: https://github.com/dotnet/roslyn/issues/6441
var evaluatorTypeName = _window.Evaluator.GetType().Name;
if (evaluatorTypeName == "CSharpInteractiveEvaluator" ||
evaluatorTypeName == "VisualBasicInteractiveEvaluator")
{
_window.Write(HelpIndent);
_window.WriteLine(line);
_window.WriteLine(InteractiveWindowResources.CSVBScriptDirectives);
foreach (var line in s_CSVBScriptDirectives)
{
_window.Write(HelpIndent);
_window.WriteLine(line);
}
}
}
......
......@@ -10,6 +10,7 @@
namespace Microsoft.VisualStudio.InteractiveWindow {
using System;
using System.Reflection;
/// <summary>
......@@ -39,7 +40,7 @@ internal class InteractiveWindowResources {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.VisualStudio.InteractiveWindow.InteractiveWindowResources", typeof(InteractiveWindowResources).Assembly);
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.VisualStudio.InteractiveWindow.InteractiveWindowResources", typeof(InteractiveWindowResources).GetTypeInfo().Assembly);
resourceMan = temp;
}
return resourceMan;
......@@ -114,6 +115,15 @@ internal class InteractiveWindowResources {
}
}
/// <summary>
/// Looks up a localized string similar to Script directives:.
/// </summary>
internal static string CSVBScriptDirectives {
get {
return ResourceManager.GetString("CSVBScriptDirectives", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to First press, select the submission containing the cursor. Second press, select all text in the window..
/// </summary>
......@@ -295,7 +305,7 @@ internal class InteractiveWindowResources {
}
/// <summary>
/// Looks up a localized string similar to Add a metadata reference to specified assembly, e.g. #r &quot;myLib.dll&quot;..
/// Looks up a localized string similar to Add a metadata reference to specified assembly and all its dependencies, e.g. #r &quot;myLib.dll&quot;..
/// </summary>
internal static string RefHelp {
get {
......@@ -348,15 +358,6 @@ internal class InteractiveWindowResources {
}
}
/// <summary>
/// Looks up a localized string similar to Script directives:.
/// </summary>
internal static string ScriptDirectives {
get {
return ResourceManager.GetString("ScriptDirectives", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Insert a new line..
/// </summary>
......
......@@ -228,11 +228,11 @@
<data name="Paste" xml:space="preserve">
<value>Paste</value>
</data>
<data name="ScriptDirectives" xml:space="preserve">
<data name="CSVBScriptDirectives" xml:space="preserve">
<value>Script directives:</value>
</data>
<data name="RefHelp" xml:space="preserve">
<value>Add a metadata reference to specified assembly, e.g. #r "myLib.dll".</value>
<value>Add a metadata reference to specified assembly and all its dependencies, e.g. #r "myLib.dll".</value>
</data>
<data name="LoadHelp" xml:space="preserve">
<value>Load specified script file and execute it, e.g. #load "myScript.csx".</value>
......
......@@ -175,10 +175,10 @@ public void InteractiveWindow_GetCommands()
var commands = interactiveCommands.GetCommands();
Assert.NotEmpty(commands);
Assert.Equal(2, commands.Where(n => n.Names.First() == "cls").Count());
Assert.Equal(2, commands.Where(n => n.Names.Last() == "clear").Count());
Assert.NotNull(commands.Where(n => n.Names.First() == "help").SingleOrDefault());
Assert.NotNull(commands.Where(n => n.Names.First() == "reset").SingleOrDefault());
Assert.Equal(2, commands.Where(n => n.Names.First() == "#cls").Count());
Assert.Equal(2, commands.Where(n => n.Names.Last() == "#clear").Count());
Assert.NotNull(commands.Where(n => n.Names.First() == "#help").SingleOrDefault());
Assert.NotNull(commands.Where(n => n.Names.First() == "#reset").SingleOrDefault());
}
[WorkItem(3970, "https://github.com/dotnet/roslyn/issues/3970")]
......
......@@ -504,6 +504,9 @@ public void HelpCommand()
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.
Script directives:
#r Add a metadata reference to specified assembly and all its dependencies, e.g. #r ""myLib.dll"".
#load Load specified script file and execute it, e.g. #load ""myScript.csx"".
> ", runner.Console.Out.ToString());
}
}
......
......@@ -158,9 +158,9 @@ internal class ScriptingResources {
/// 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.
/// #help Display help on available commands and key bindings.
///Script directives:
/// r Add a metad [rest of string was truncated]&quot;;.
/// #r Add a metad [rest of string was truncated]&quot;;.
/// </summary>
internal static string HelpText {
get {
......
......@@ -156,9 +156,9 @@
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.
#help Display help on available commands and key bindings.
Script directives:
r Add a metadata reference to specified assembly, e.g. #r "myLib.dll".
load Load specified script file and execute it, e.g. #load "myScript.csx".</value>
#r Add a metadata reference to specified assembly and all its dependencies, e.g. #r "myLib.dll".
#load Load specified script file and execute it, e.g. #load "myScript.csx".</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.
先完成此消息的编辑!
想要评论请 注册