Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
39fb7809
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
39fb7809
编写于
10月 09, 2015
作者:
G
Gen Lu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add `#help` command to csi/vbi
上级
6ac25776
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
86 addition
and
2 deletion
+86
-2
src/Scripting/CSharpTest/CommandLineRunnerTests.cs
src/Scripting/CSharpTest/CommandLineRunnerTests.cs
+27
-0
src/Scripting/Core/Hosting/CommandLine/CommandLineRunner.cs
src/Scripting/Core/Hosting/CommandLine/CommandLineRunner.cs
+21
-0
src/Scripting/Core/ScriptingResources.Designer.cs
src/Scripting/Core/ScriptingResources.Designer.cs
+26
-2
src/Scripting/Core/ScriptingResources.resx
src/Scripting/Core/ScriptingResources.resx
+12
-0
未找到文件。
src/Scripting/CSharpTest/CommandLineRunnerTests.cs
浏览文件 @
39fb7809
...
...
@@ -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
());
}
}
}
src/Scripting/Core/Hosting/CommandLine/CommandLineRunner.cs
浏览文件 @
39fb7809
...
...
@@ -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
;
...
...
src/Scripting/Core/ScriptingResources.Designer.cs
浏览文件 @
39fb7809
...
...
@@ -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 "#help" 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>
...
...
src/Scripting/Core/ScriptingResources.resx
浏览文件 @
39fb7809
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录