Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
fsharp
提交
0dabe8da
F
fsharp
项目概览
dotNET Platform
/
fsharp
11 个月 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
fsharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
0dabe8da
编写于
11月 21, 2019
作者:
B
Brett V. Forsgren
提交者:
GitHub
11月 21, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enable symbol completion for scripting (#7893)
上级
e52675ac
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
110 addition
and
10 deletion
+110
-10
src/fsharp/FSharp.Compiler.Private.Scripting/FSharpScript.fs
src/fsharp/FSharp.Compiler.Private.Scripting/FSharpScript.fs
+18
-0
tests/FSharp.Compiler.Private.Scripting.UnitTests/CompletionTests.fs
...p.Compiler.Private.Scripting.UnitTests/CompletionTests.fs
+71
-0
tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharp.Compiler.Private.Scripting.UnitTests.fsproj
...tTests/FSharp.Compiler.Private.Scripting.UnitTests.fsproj
+2
-0
tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs
...Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs
+0
-10
tests/FSharp.Compiler.Private.Scripting.UnitTests/TestHelpers.fs
...Sharp.Compiler.Private.Scripting.UnitTests/TestHelpers.fs
+19
-0
未找到文件。
src/fsharp/FSharp.Compiler.Private.Scripting/FSharpScript.fs
浏览文件 @
0dabe8da
...
...
@@ -4,6 +4,7 @@ namespace FSharp.Compiler.Scripting
open
System
open
System
.
Threading
open
FSharp
.
Compiler
open
FSharp
.
Compiler
.
Interactive
.
Shell
type
FSharpScript
(?
captureInput
:
bool
,
?
captureOutput
:
bool
,
?
additionalArgs
:
string
[]
)
as
this
=
...
...
@@ -50,6 +51,23 @@ type FSharpScript(?captureInput: bool, ?captureOutput: bool, ?additionalArgs: st
|
Choice1Of2
v
->
Ok
(
v
),
errors
|
Choice2Of2
ex
->
Error
(
ex
),
errors
/// Get the available completion symbols from the code at the specified location.
///
/// <param name="text">The input text on which completions will be calculated</param>
/// <param name="line">The 1-based line index</param>
/// <param name="column">The 0-based column index</param>
member
__.
GetCompletionSymbols
(
text
:
string
,
line
:
int
,
column
:
int
)
=
async
{
let
!
parseResults
,
checkResults
,
_
projectResults
=
fsi
.
ParseAndCheckInteraction
(
text
)
let
lineText
=
text
.
Split
(
'\n'
).[
line
-
1
]
let
partialName
=
QuickParse
.
GetPartialLongNameEx
(
lineText
,
column
-
1
)
let
!
symbolUses
=
checkResults
.
GetDeclarationListSymbols
(
Some
parseResults
,
line
,
lineText
,
partialName
)
let
symbols
=
symbolUses
|>
List
.
concat
|>
List
.
map
(
fun
s
->
s
.
Symbol
)
return
symbols
}
interface
IDisposable
with
member
__.
Dispose
()
=
if
captureInput
then
...
...
tests/FSharp.Compiler.Private.Scripting.UnitTests/CompletionTests.fs
0 → 100644
浏览文件 @
0dabe8da
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace
FSharp
.
Compiler
.
Scripting
.
UnitTests
open
System
open
System
.
Threading
.
Tasks
open
FSharp
.
Compiler
.
Scripting
open
NUnit
.
Framework
[<
TestFixture
>]
type
CompletionTests
()
=
[<
Test
>]
member
_.
``Instance completions in the same submission``
()
=
async
{
use
script
=
new
FSharpScript
()
let
lines
=
[
"let x = 1"
"x."
]
let
!
completions
=
script
.
GetCompletionSymbols
(
String
.
Join
(
"
\n
"
,
lines
),
2
,
2
)
let
matchingCompletions
=
completions
|>
List
.
filter
(
fun
s
->
s
.
DisplayName
=
"CompareTo"
)
Assert
.
AreEqual
(
1
,
List
.
length
matchingCompletions
)
}
|>
Async
.
StartAsTask
:>
Task
[<
Test
>]
member
_.
``Instance completions from a previous submission``
()
=
async
{
use
script
=
new
FSharpScript
()
script
.
Eval
(
"let x = 1"
)
|>
ignoreValue
let
!
completions
=
script
.
GetCompletionSymbols
(
"x."
,
1
,
2
)
let
matchingCompletions
=
completions
|>
List
.
filter
(
fun
s
->
s
.
DisplayName
=
"CompareTo"
)
Assert
.
AreEqual
(
1
,
List
.
length
matchingCompletions
)
}
|>
Async
.
StartAsTask
:>
Task
[<
Test
>]
member
_.
``Static member completions``
()
=
async
{
use
script
=
new
FSharpScript
()
let
!
completions
=
script
.
GetCompletionSymbols
(
"System.String."
,
1
,
14
)
let
matchingCompletions
=
completions
|>
List
.
filter
(
fun
s
->
s
.
DisplayName
=
"Join"
)
Assert
.
GreaterOrEqual
(
List
.
length
matchingCompletions
,
1
)
}
|>
Async
.
StartAsTask
:>
Task
[<
Test
>]
member
_.
``Type completions from namespace``
()
=
async
{
use
script
=
new
FSharpScript
()
let
!
completions
=
script
.
GetCompletionSymbols
(
"System."
,
1
,
7
)
let
matchingCompletions
=
completions
|>
List
.
filter
(
fun
s
->
s
.
DisplayName
=
"String"
)
Assert
.
GreaterOrEqual
(
List
.
length
matchingCompletions
,
1
)
}
|>
Async
.
StartAsTask
:>
Task
[<
Test
>]
member
_.
``Namespace completions``
()
=
async
{
use
script
=
new
FSharpScript
()
let
!
completions
=
script
.
GetCompletionSymbols
(
"System."
,
1
,
7
)
let
matchingCompletions
=
completions
|>
List
.
filter
(
fun
s
->
s
.
DisplayName
=
"Collections"
)
Assert
.
AreEqual
(
1
,
List
.
length
matchingCompletions
)
}
|>
Async
.
StartAsTask
:>
Task
[<
Test
>]
member
_.
``Extension method completions``
()
=
async
{
use
script
=
new
FSharpScript
()
let
lines
=
[
"open System.Linq"
"let list = new System.Collections.Generic.List<int>()"
"list."
]
let
!
completions
=
script
.
GetCompletionSymbols
(
String
.
Join
(
"
\n
"
,
lines
),
3
,
5
)
let
matchingCompletions
=
completions
|>
List
.
filter
(
fun
s
->
s
.
DisplayName
=
"Select"
)
Assert
.
AreEqual
(
1
,
List
.
length
matchingCompletions
)
}
|>
Async
.
StartAsTask
:>
Task
tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharp.Compiler.Private.Scripting.UnitTests.fsproj
浏览文件 @
0dabe8da
...
...
@@ -11,7 +11,9 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="TestHelpers.fs" />
<Compile Include="FSharpScriptTests.fs" />
<Compile Include="CompletionTests.fs" />
</ItemGroup>
<ItemGroup>
...
...
tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs
浏览文件 @
0dabe8da
...
...
@@ -9,21 +9,11 @@ open System.Threading
open
System
.
Threading
.
Tasks
open
FSharp
.
Compiler
.
Interactive
.
Shell
open
FSharp
.
Compiler
.
Scripting
open
FSharp
.
Compiler
.
SourceCodeServices
open
NUnit
.
Framework
[<
TestFixture
>]
type
InteractiveTests
()
=
let
getValue
((
value
:
Result
<
FsiValue
option
,
exn
>),
(
errors
:
FSharpErrorInfo
[]
))
=
if
errors
.
Length
>
0
then
failwith
<|
sprintf
"Evaluation returned %d errors:
\r\n\t
%s"
errors
.
Length
(
String
.
Join
(
"
\r\n\t
"
,
errors
))
match
value
with
|
Ok
(
value
)
->
value
|
Error
ex
->
raise
ex
let
ignoreValue
=
getValue
>>
ignore
[<
Test
>]
member
__.
``Eval object value``
()
=
use
script
=
new
FSharpScript
()
...
...
tests/FSharp.Compiler.Private.Scripting.UnitTests/TestHelpers.fs
0 → 100644
浏览文件 @
0dabe8da
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace
FSharp
.
Compiler
.
Scripting
.
UnitTests
open
System
open
FSharp
.
Compiler
.
Interactive
.
Shell
open
FSharp
.
Compiler
.
SourceCodeServices
[<
AutoOpen
>]
module
TestHelpers
=
let
getValue
((
value
:
Result
<
FsiValue
option
,
exn
>),
(
errors
:
FSharpErrorInfo
[]
))
=
if
errors
.
Length
>
0
then
failwith
<|
sprintf
"Evaluation returned %d errors:
\r\n\t
%s"
errors
.
Length
(
String
.
Join
(
"
\r\n\t
"
,
errors
))
match
value
with
|
Ok
(
value
)
->
value
|
Error
ex
->
raise
ex
let
ignoreValue
=
getValue
>>
ignore
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录