Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
fsharp
提交
81252e06
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,发现更多精彩内容 >>
未验证
提交
81252e06
编写于
12月 21, 2022
作者:
P
Petr
提交者:
GitHub
12月 21, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Correct inline parameter hints for named optional arguments (#14498)
上级
c8acf2ac
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
64 addition
and
7 deletion
+64
-7
vsintegration/src/FSharp.Editor/Hints/InlineParameterNameHints.fs
...ation/src/FSharp.Editor/Hints/InlineParameterNameHints.fs
+22
-7
vsintegration/tests/FSharp.Editor.Tests/Hints/InlineParameterNameHintTests.fs
...FSharp.Editor.Tests/Hints/InlineParameterNameHintTests.fs
+42
-0
未找到文件。
vsintegration/src/FSharp.Editor/Hints/InlineParameterNameHints.fs
浏览文件 @
81252e06
...
...
@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor.Hints
open
Microsoft
.
VisualStudio
.
FSharp
.
Editor
open
FSharp
.
Compiler
.
CodeAnalysis
open
FSharp
.
Compiler
.
EditorServices
open
FSharp
.
Compiler
.
Symbols
open
FSharp
.
Compiler
.
Text
open
Hints
...
...
@@ -30,7 +31,7 @@ module InlineParameterNameHints =
let
private
doesFieldNameExist
(
field
:
FSharpField
)
=
not
field
.
IsNameGenerated
let
private
get
TupleRange
s
let
private
get
ArgumentLocation
s
(
symbolUse
:
FSharpSymbolUse
)
(
parseResults
:
FSharpParseFileResults
)
=
...
...
@@ -40,9 +41,11 @@ module InlineParameterNameHints =
parseResults
.
FindParameterLocations
position
|>
Option
.
map
(
fun
locations
->
locations
.
ArgumentLocations
)
|>
Option
.
map
(
Seq
.
map
(
fun
location
->
location
.
ArgumentRange
))
|>
Option
.
defaultValue
[]
|>
Seq
.
toList
|>
Option
.
defaultValue
[||]
let
private
getTupleRanges
=
Seq
.
map
(
fun
location
->
location
.
ArgumentRange
)
>>
Seq
.
toList
let
private
getCurryRanges
(
symbolUse
:
FSharpSymbolUse
)
...
...
@@ -51,7 +54,15 @@ module InlineParameterNameHints =
parseResults
.
GetAllArgumentsForFunctionApplicationAtPosition
symbolUse
.
Range
.
Start
|>
Option
.
defaultValue
[]
let
isMemberOrFunctionOrValueValidForHint
(
symbol
:
FSharpMemberOrFunctionOrValue
)
(
symbolUse
:
FSharpSymbolUse
)
=
let
private
isNamedArgument
range
=
Seq
.
filter
(
fun
location
->
location
.
IsNamedArgument
)
>>
Seq
.
map
(
fun
location
->
location
.
ArgumentRange
)
>>
Seq
.
contains
range
let
isMemberOrFunctionOrValueValidForHint
(
symbol
:
FSharpMemberOrFunctionOrValue
)
(
symbolUse
:
FSharpSymbolUse
)
=
if
symbolUse
.
IsFromUse
then
let
isNotBuiltInOperator
=
symbol
.
DeclaringEntity
...
...
@@ -73,10 +84,14 @@ module InlineParameterNameHints =
(
symbolUse
:
FSharpSymbolUse
)
=
let
parameters
=
symbol
.
CurriedParameterGroups
|>
Seq
.
concat
let
argumentLocations
=
getArgumentLocations
symbolUse
parseResults
let
tupleRanges
=
parseResults
|>
getTupleRanges
symbolUse
let
tupleRanges
=
argumentLocations
|>
getTupleRanges
let
curryRanges
=
parseResults
|>
getCurryRanges
symbolUse
let
ranges
=
if
tupleRanges
|>
(
not
<<
Seq
.
isEmpty
)
then
tupleRanges
else
curryRanges
let
ranges
=
if
tupleRanges
|>
(
not
<<
Seq
.
isEmpty
)
then
tupleRanges
else
curryRanges
|>
Seq
.
filter
(
fun
range
->
argumentLocations
|>
(
not
<<
isNamedArgument
range
))
parameters
|>
Seq
.
zip
ranges
// Seq.zip is important as List.zip requires equal lengths
...
...
vsintegration/tests/FSharp.Editor.Tests/Hints/InlineParameterNameHintTests.fs
浏览文件 @
81252e06
...
...
@@ -406,3 +406,45 @@ let x = "test".Split("").[0].Split("");
let
actual
=
getParameterNameHints
document
Assert
.
AreEqual
(
expected
,
actual
)
[<
Test
>]
let
``Hints are not shown for optional parameters with specified names``
()
=
let
code
=
"""
type MyType() =
member _.MyMethod(?beep: int, ?bap: int, ?boop: int) = ()
member this.Foo = this.MyMethod(3, boop = 4)
"""
let
document
=
getFsDocument
code
let
expected
=
[
{
Content
=
"beep = "
Location
=
(
5
,
37
)
}
]
let
actual
=
getParameterNameHints
document
Assert
.
AreEqual
(
expected
,
actual
)
[<
Test
>]
let
``Hints are not shown when all optional parameters are named``
()
=
let
code
=
"""
type MyType() =
member _.MyMethod(?beep: int, ?bap : int, ?boop : int) = ()
member this.Foo = this.MyMethod(bap = 3, beep = 4)
"""
let
document
=
getFsDocument
code
let
actual
=
getParameterNameHints
document
Assert
.
IsEmpty
(
actual
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录