Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
fsharp
提交
c2f78593
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,发现更多精彩内容 >>
未验证
提交
c2f78593
编写于
4月 19, 2023
作者:
T
Tomas Grosup
提交者:
GitHub
4月 19, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Codefixes cleanup - cleanup fixableDiagnosticIds, unify more CodeFix registration calls (#15110)
* codefix simplification
上级
74fda07f
变更
25
隐藏空白更改
内联
并排
Showing
25 changed file
with
120 addition
and
210 deletion
+120
-210
vsintegration/src/FSharp.Editor/CodeFix/AddInstanceMemberParameter.fs
...n/src/FSharp.Editor/CodeFix/AddInstanceMemberParameter.fs
+2
-2
vsintegration/src/FSharp.Editor/CodeFix/AddMissingEqualsToTypeDefinition.fs
...FSharp.Editor/CodeFix/AddMissingEqualsToTypeDefinition.fs
+2
-2
vsintegration/src/FSharp.Editor/CodeFix/AddMissingFunKeyword.fs
...gration/src/FSharp.Editor/CodeFix/AddMissingFunKeyword.fs
+2
-3
vsintegration/src/FSharp.Editor/CodeFix/AddMissingRecToMutuallyRecFunctions.fs
...arp.Editor/CodeFix/AddMissingRecToMutuallyRecFunctions.fs
+9
-40
vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs
...ation/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs
+18
-33
vsintegration/src/FSharp.Editor/CodeFix/AddTypeAnnotationToObjectOfIndeterminateType.fs
...r/CodeFix/AddTypeAnnotationToObjectOfIndeterminateType.fs
+15
-30
vsintegration/src/FSharp.Editor/CodeFix/ChangePrefixNegationToInfixSubtraction.fs
....Editor/CodeFix/ChangePrefixNegationToInfixSubtraction.fs
+2
-2
vsintegration/src/FSharp.Editor/CodeFix/ChangeRefCellDerefToNotExpression.fs
...Sharp.Editor/CodeFix/ChangeRefCellDerefToNotExpression.fs
+2
-2
vsintegration/src/FSharp.Editor/CodeFix/ChangeToUpcast.fs
vsintegration/src/FSharp.Editor/CodeFix/ChangeToUpcast.fs
+2
-3
vsintegration/src/FSharp.Editor/CodeFix/ConvertCSharpLambdaToFSharpLambda.fs
...Sharp.Editor/CodeFix/ConvertCSharpLambdaToFSharpLambda.fs
+3
-2
vsintegration/src/FSharp.Editor/CodeFix/ConvertCSharpUsingToFSharpOpen.fs
...c/FSharp.Editor/CodeFix/ConvertCSharpUsingToFSharpOpen.fs
+1
-2
vsintegration/src/FSharp.Editor/CodeFix/ConvertToAnonymousRecord.fs
...ion/src/FSharp.Editor/CodeFix/ConvertToAnonymousRecord.fs
+10
-24
vsintegration/src/FSharp.Editor/CodeFix/ConvertToNotEqualsEqualityExpression.fs
...rp.Editor/CodeFix/ConvertToNotEqualsEqualityExpression.fs
+2
-2
vsintegration/src/FSharp.Editor/CodeFix/ConvertToSingleEqualsEqualityExpression.fs
...Editor/CodeFix/ConvertToSingleEqualsEqualityExpression.fs
+2
-2
vsintegration/src/FSharp.Editor/CodeFix/FixIndexerAccess.fs
vsintegration/src/FSharp.Editor/CodeFix/FixIndexerAccess.fs
+3
-4
vsintegration/src/FSharp.Editor/CodeFix/ImplementInterfaceCodeFixProvider.fs
...Sharp.Editor/CodeFix/ImplementInterfaceCodeFixProvider.fs
+3
-7
vsintegration/src/FSharp.Editor/CodeFix/MakeDeclarationMutable.fs
...ation/src/FSharp.Editor/CodeFix/MakeDeclarationMutable.fs
+2
-2
vsintegration/src/FSharp.Editor/CodeFix/MakeOuterBindingRecursive.fs
...on/src/FSharp.Editor/CodeFix/MakeOuterBindingRecursive.fs
+2
-3
vsintegration/src/FSharp.Editor/CodeFix/ProposeUppercaseLabel.fs
...ration/src/FSharp.Editor/CodeFix/ProposeUppercaseLabel.fs
+5
-8
vsintegration/src/FSharp.Editor/CodeFix/RemoveReturnOrYield.fs
...egration/src/FSharp.Editor/CodeFix/RemoveReturnOrYield.fs
+2
-3
vsintegration/src/FSharp.Editor/CodeFix/ReplaceWithSuggestion.fs
...ration/src/FSharp.Editor/CodeFix/ReplaceWithSuggestion.fs
+2
-3
vsintegration/src/FSharp.Editor/CodeFix/UseMutationWhenValueIsMutable.fs
...rc/FSharp.Editor/CodeFix/UseMutationWhenValueIsMutable.fs
+2
-2
vsintegration/src/FSharp.Editor/CodeFix/UseTripleQuotedInterpolation.fs
...src/FSharp.Editor/CodeFix/UseTripleQuotedInterpolation.fs
+2
-2
vsintegration/src/FSharp.Editor/CodeFix/WrapExpressionInParentheses.fs
.../src/FSharp.Editor/CodeFix/WrapExpressionInParentheses.fs
+12
-27
vsintegration/src/FSharp.Editor/Common/Constants.fs
vsintegration/src/FSharp.Editor/Common/Constants.fs
+13
-0
未找到文件。
vsintegration/src/FSharp.Editor/CodeFix/AddInstanceMemberParameter.fs
浏览文件 @
c2f78593
...
...
@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
.
Composition
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -12,10 +13,9 @@ open Microsoft.CodeAnalysis.CodeFixes
type
internal
FSharpAddInstanceMemberParameterCodeFixProvider
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0673"
]
static
let
title
=
SR
.
AddMissingInstanceMemberParameter
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0673"
)
override
_.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/AddMissingEqualsToTypeDefinition.fs
浏览文件 @
c2f78593
...
...
@@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
open
System
.
Composition
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -13,9 +14,8 @@ open Microsoft.CodeAnalysis.CodeFixes
type
internal
FSharpAddMissingEqualsToTypeDefinitionCodeFixProvider
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS3360"
]
static
let
title
=
SR
.
AddMissingEqualsToTypeDefinition
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS3360"
)
override
_.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/AddMissingFunKeyword.fs
浏览文件 @
c2f78593
...
...
@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
open
System
.
Composition
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -16,9 +17,7 @@ type internal FSharpAddMissingFunKeywordCodeFixProvider [<ImportingConstructor>]
inherit
CodeFixProvider
()
static
let
title
=
SR
.
AddMissingFunKeyword
()
let
fixableDiagnosticIds
=
set
[
"FS0010"
]
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0010"
)
override
_.
RegisterCodeFixesAsync
context
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/AddMissingRecToMutuallyRecFunctions.fs
浏览文件 @
c2f78593
...
...
@@ -16,38 +16,13 @@ open FSharp.Compiler.CodeAnalysis
open
Microsoft
.
CodeAnalysis
open
Microsoft
.
CodeAnalysis
.
CodeActions
[<
ExportCodeFixProvider
(
FSharpConstants
.
FSharpLanguageName
,
Name
=
"AddMissingRecToMutuallyRecFunctions"
);
Shared
>]
[<
ExportCodeFixProvider
(
FSharpConstants
.
FSharpLanguageName
,
Name
=
CodeFix
.
AddMissingRecToMutuallyRecFunctions
);
Shared
>]
type
internal
FSharpAddMissingRecToMutuallyRecFunctionsCodeFixProvider
[<
ImportingConstructor
>]
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0576"
]
static
let
titleFormat
=
SR
.
MakeOuterBindingRecursive
()
let
createCodeFix
(
context
:
CodeFixContext
,
symbolName
:
string
,
titleFormat
:
string
,
textChange
:
TextChange
,
diagnostics
:
ImmutableArray
<
Diagnostic
>
)
=
let
title
=
String
.
Format
(
titleFormat
,
symbolName
)
let
codeAction
=
CodeAction
.
Create
(
title
,
(
fun
(
cancellationToken
:
CancellationToken
)
->
async
{
let
cancellationToken
=
context
.
CancellationToken
let
!
sourceText
=
context
.
Document
.
GetTextAsync
(
cancellationToken
)
|>
Async
.
AwaitTask
return
context
.
Document
.
WithText
(
sourceText
.
WithChanges
(
textChange
))
}
|>
RoslynHelpers
.
StartAsyncAsTask
(
cancellationToken
)),
title
)
context
.
RegisterCodeFix
(
codeAction
,
diagnostics
)
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0576"
)
override
_.
RegisterCodeFixesAsync
context
=
asyncMaybe
{
...
...
@@ -82,18 +57,12 @@ type internal FSharpAddMissingRecToMutuallyRecFunctionsCodeFixProvider [<Importi
let
!
funcNameSpan
=
RoslynHelpers
.
TryFSharpRangeToTextSpan
(
sourceText
,
funcLexerSymbol
.
Range
)
let
funcName
=
sourceText
.
GetSubText
(
funcNameSpan
).
ToString
()
let
diagnostics
=
context
.
Diagnostics
|>
Seq
.
filter
(
fun
x
->
fixableDiagnosticIds
|>
Set
.
contains
x
.
Id
)
|>
Seq
.
toImmutableArray
createCodeFix
(
context
,
funcName
,
SR
.
MakeOuterBindingRecursive
()
,
TextChange
(
TextSpan
(
context
.
Span
.
End
,
0
),
" rec"
),
diagnostics
)
do
context
.
RegisterFsharpFix
(
CodeFix
.
AddMissingRecToMutuallyRecFunctions
,
String
.
Format
(
titleFormat
,
funcName
),
[|
TextChange
(
TextSpan
(
context
.
Span
.
End
,
0
),
" rec"
)
|]
)
}
|>
Async
.
Ignore
|>
RoslynHelpers
.
StartAsyncUnitAsTask
(
context
.
CancellationToken
)
vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs
浏览文件 @
c2f78593
...
...
@@ -6,6 +6,7 @@ open System
open
System
.
Composition
open
System
.
Threading
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
open
Microsoft
.
CodeAnalysis
.
Text
...
...
@@ -21,35 +22,24 @@ open FSharp.Compiler.Text
type
internal
FSharpAddOpenCodeFixProvider
[<
ImportingConstructor
>]
(
assemblyContentProvider
:
AssemblyContentProvider
)
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
[
"FS0039"
;
"FS0043"
]
let
fixUnderscoresInMenuText
(
text
:
string
)
=
text
.
Replace
(
"_"
,
"__"
)
let
qualifySymbolFix
(
context
:
CodeFixContext
)
(
fullName
,
qualifier
)
=
CodeFixHelpers
.
createTextChangeCodeFix
(
CodeFix
.
AddOpen
,
fixUnderscoresInMenuText
fullName
,
context
,
[|
TextChange
(
context
.
Span
,
qualifier
)
|]
)
let
openNamespaceFix
(
context
:
CodeFixContext
)
ctx
name
ns
multipleNames
=
context
.
RegisterFsharpFix
(
CodeFix
.
AddOpen
,
fixUnderscoresInMenuText
fullName
,
[|
TextChange
(
context
.
Span
,
qualifier
)
|])
let
openNamespaceFix
(
context
:
CodeFixContext
)
ctx
name
ns
multipleNames
sourceText
=
let
displayText
=
"open "
+
ns
+
(
if
multipleNames
then
" ("
+
name
+
")"
else
""
)
let
newText
,
_
=
OpenDeclarationHelper
.
insertOpenDeclaration
sourceText
ctx
ns
let
changes
=
newText
.
GetTextChanges
(
sourceText
)
CodeAction
.
Create
(
fixUnderscoresInMenuText
displayText
,
(
fun
(
cancellationToken
:
CancellationToken
)
->
async
{
let
!
sourceText
=
context
.
Document
.
GetTextAsync
(
cancellationToken
)
|>
Async
.
AwaitTask
let
changedText
,
_
=
OpenDeclarationHelper
.
insertOpenDeclaration
sourceText
ctx
ns
return
context
.
Document
.
WithText
(
changedText
)
}
|>
RoslynHelpers
.
StartAsyncAsTask
(
cancellationToken
)),
displayText
)
context
.
RegisterFsharpFix
(
CodeFix
.
AddOpen
,
fixUnderscoresInMenuText
displayText
,
changes
)
let
addSuggestionsAsCodeFixes
(
context
:
CodeFixContext
)
(
candidates
:
(
InsertionContextEntity
*
InsertionContext
)
list
)
=
let
openNamespaceFixes
=
let
addSuggestionsAsCodeFixes
(
context
:
CodeFixContext
)
(
sourceText
:
SourceText
)
(
candidates
:
(
InsertionContextEntity
*
InsertionContext
)
list
)
=
do
candidates
|>
Seq
.
choose
(
fun
(
entity
,
ctx
)
->
entity
.
Namespace
|>
Option
.
map
(
fun
ns
->
ns
,
entity
.
FullDisplayName
,
ctx
))
|>
Seq
.
groupBy
(
fun
(
ns
,
_,
_)
->
ns
)
...
...
@@ -64,22 +54,17 @@ type internal FSharpAddOpenCodeFixProvider [<ImportingConstructor>] (assemblyCon
let
multipleNames
=
names
|>
Array
.
length
>
1
names
|>
Seq
.
map
(
fun
(
name
,
ctx
)
->
ns
,
name
,
ctx
,
multipleNames
))
|>
Seq
.
concat
|>
Seq
.
map
(
fun
(
ns
,
name
,
ctx
,
multipleNames
)
->
openNamespaceFix
context
ctx
name
ns
multipleNames
)
|>
Seq
.
toList
|>
Seq
.
iter
(
fun
(
ns
,
name
,
ctx
,
multipleNames
)
->
openNamespaceFix
context
ctx
name
ns
multipleNames
sourceText
)
let
qualifiedSymbolFixes
=
do
candidates
|>
Seq
.
filter
(
fun
(
entity
,
_)
->
not
(
entity
.
LastIdent
.
StartsWith
"op_"
))
// Don't include qualified operator names. The resultant codefix won't compile because it won't be an infix operator anymore.
|>
Seq
.
map
(
fun
(
entity
,
_)
->
entity
.
FullRelativeName
,
entity
.
Qualifier
)
|>
Seq
.
distinct
|>
Seq
.
sort
|>
Seq
.
map
(
qualifySymbolFix
context
)
|>
Seq
.
toList
for
codeFix
in
openNamespaceFixes
@
qualifiedSymbolFixes
do
context
.
RegisterCodeFix
(
codeFix
,
context
.
Diagnostics
)
|>
Seq
.
iter
(
qualifySymbolFix
context
)
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0039"
,
"FS0043"
)
override
_.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
@@ -186,7 +171,7 @@ type internal FSharpAddOpenCodeFixProvider [<ImportingConstructor>] (assemblyCon
|>
Seq
.
map
createEntity
|>
Seq
.
concat
|>
Seq
.
toList
|>
addSuggestionsAsCodeFixes
context
|>
addSuggestionsAsCodeFixes
context
sourceText
}
|>
Async
.
Ignore
|>
RoslynHelpers
.
StartAsyncUnitAsTask
(
context
.
CancellationToken
)
vsintegration/src/FSharp.Editor/CodeFix/AddTypeAnnotationToObjectOfIndeterminateType.fs
浏览文件 @
c2f78593
...
...
@@ -6,6 +6,7 @@ open System
open
System
.
Composition
open
System
.
Threading
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -16,20 +17,16 @@ open FSharp.Compiler.Text
open
FSharp
.
Compiler
.
Symbols
open
Microsoft
.
CodeAnalysis
.
CodeActions
[<
ExportCodeFixProvider
(
FSharpConstants
.
FSharpLanguageName
,
Name
=
"AddTypeAnnotationToObjectOfIndeterminateType"
);
Shared
>]
[<
ExportCodeFixProvider
(
FSharpConstants
.
FSharpLanguageName
,
Name
=
CodeFix
.
AddTypeAnnotationToObjectOfIndeterminateType
);
Shared
>]
type
internal
FSharpAddTypeAnnotationToObjectOfIndeterminateTypeFixProvider
[<
ImportingConstructor
>]
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0072"
;
"FS3245"
]
static
let
title
=
SR
.
AddTypeAnnotation
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0072"
,
"FS3245"
)
override
_.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
let
diagnostics
=
context
.
Diagnostics
|>
Seq
.
filter
(
fun
x
->
fixableDiagnosticIds
|>
Set
.
contains
x
.
Id
)
|>
Seq
.
toImmutableArray
let
document
=
context
.
Document
let
position
=
context
.
Span
.
Start
...
...
@@ -95,29 +92,17 @@ type internal FSharpAddTypeAnnotationToObjectOfIndeterminateTypeFixProvider [<Im
let
hasRightParen
=
rightLoop
sourceText
.[
declSpan
.
End
]
declSpan
.
End
hasLeftParen
&&
hasRightParen
let
getChangedText
(
sourceText
:
SourceText
)
=
if
alreadyWrappedInParens
then
sourceText
.
WithChanges
(
TextChange
(
TextSpan
(
declSpan
.
End
,
0
),
": "
+
typeString
))
else
sourceText
.
WithChanges
(
TextChange
(
TextSpan
(
declSpan
.
Start
,
0
),
"("
))
.
WithChanges
(
TextChange
(
TextSpan
(
declSpan
.
End
+
1
,
0
),
": "
+
typeString
+
")"
))
let
title
=
SR
.
AddTypeAnnotation
()
let
codeAction
=
CodeAction
.
Create
(
title
,
(
fun
(
cancellationToken
:
CancellationToken
)
->
async
{
let
!
sourceText
=
context
.
Document
.
GetTextAsync
(
cancellationToken
)
|>
Async
.
AwaitTask
return
context
.
Document
.
WithText
(
getChangedText
sourceText
)
}
|>
RoslynHelpers
.
StartAsyncAsTask
(
cancellationToken
)),
title
)
context
.
RegisterCodeFix
(
codeAction
,
diagnostics
)
let
changes
=
[
if
alreadyWrappedInParens
then
TextChange
(
TextSpan
(
declSpan
.
End
,
0
),
": "
+
typeString
)
else
TextChange
(
TextSpan
(
declSpan
.
Start
,
0
),
"("
)
TextChange
(
TextSpan
(
declSpan
.
End
+
1
,
0
),
": "
+
typeString
+
")"
)
]
context
.
RegisterFsharpFix
(
CodeFix
.
AddTypeAnnotationToObjectOfIndeterminateType
,
title
,
changes
)
|
_
->
()
|
_
->
()
}
...
...
vsintegration/src/FSharp.Editor/CodeFix/ChangePrefixNegationToInfixSubtraction.fs
浏览文件 @
c2f78593
...
...
@@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
open
System
.
Composition
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -13,10 +14,9 @@ open Microsoft.CodeAnalysis.CodeFixes
type
internal
FSharpChangePrefixNegationToInfixSubtractionodeFixProvider
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0003"
]
static
let
title
=
SR
.
ChangePrefixNegationToInfixSubtraction
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0003"
)
override
_.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/ChangeRefCellDerefToNotExpression.fs
浏览文件 @
c2f78593
...
...
@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
.
Composition
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -12,10 +13,9 @@ open Microsoft.CodeAnalysis.CodeFixes
type
internal
FSharpChangeRefCellDerefToNotExpressionCodeFixProvider
[<
ImportingConstructor
>]
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0001"
]
static
let
title
=
SR
.
UseNotForNegation
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0001"
)
override
this
.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/ChangeToUpcast.fs
浏览文件 @
c2f78593
...
...
@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
.
Composition
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -12,9 +13,7 @@ open Microsoft.CodeAnalysis.CodeFixes
type
internal
FSharpChangeToUpcastCodeFixProvider
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS3198"
]
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS3198"
)
override
this
.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/ConvertCSharpLambdaToFSharpLambda.fs
浏览文件 @
c2f78593
...
...
@@ -3,6 +3,7 @@
namespace
Microsoft
.
VisualStudio
.
FSharp
.
Editor
open
System
.
Composition
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -11,9 +12,9 @@ open Microsoft.CodeAnalysis.CodeFixes
type
internal
FSharpConvertCSharpLambdaToFSharpLambdaCodeFixProvider
[<
ImportingConstructor
>]
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0039"
;
"FS0043"
]
static
let
title
=
SR
.
UseFSharpLambda
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0039"
,
"FS0043"
)
override
_.
RegisterCodeFixesAsync
context
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/ConvertCSharpUsingToFSharpOpen.fs
浏览文件 @
c2f78593
...
...
@@ -14,7 +14,6 @@ open Microsoft.CodeAnalysis.CodeFixes
type
internal
FSharpConvertCSharpUsingToFSharpOpen
[<
ImportingConstructor
>]
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0039"
;
"FS0201"
]
static
let
title
=
SR
.
ConvertCSharpUsingToFSharpOpen
()
let
usingLength
=
"using"
.
Length
...
...
@@ -47,7 +46,7 @@ type internal FSharpConvertCSharpUsingToFSharpOpen [<ImportingConstructor>] () =
do
context
.
RegisterFsharpFix
(
CodeFix
.
ConvertCSharpUsingToFSharpOpen
,
title
,
[|
replacement
|])
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0039"
,
"FS0201"
)
override
_.
RegisterCodeFixesAsync
context
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/ConvertToAnonymousRecord.fs
浏览文件 @
c2f78593
...
...
@@ -5,18 +5,19 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
.
Composition
open
System
.
Threading
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
open
Microsoft
.
CodeAnalysis
.
CodeActions
[<
ExportCodeFixProvider
(
FSharpConstants
.
FSharpLanguageName
,
Name
=
"ConvertToAnonymousRecord"
);
Shared
>]
[<
ExportCodeFixProvider
(
FSharpConstants
.
FSharpLanguageName
,
Name
=
CodeFix
.
ConvertToAnonymousRecord
);
Shared
>]
type
internal
FSharpConvertToAnonymousRecordCodeFixProvider
[<
ImportingConstructor
>]
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0039"
]
static
let
title
=
SR
.
ConvertToAnonymousRecord
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0039"
)
override
_.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
@@ -34,28 +35,13 @@ type internal FSharpConvertToAnonymousRecordCodeFixProvider [<ImportingConstruct
let
!
recordRange
=
parseResults
.
TryRangeOfRecordExpressionContainingPos
errorRange
.
Start
let
!
recordSpan
=
RoslynHelpers
.
TryFSharpRangeToTextSpan
(
sourceText
,
recordRange
)
let
getChangedText
()
=
sourceText
.
WithChanges
(
TextChange
(
TextSpan
(
recordSpan
.
Start
+
1
,
0
),
"|"
))
.
WithChanges
(
TextChange
(
TextSpan
(
recordSpan
.
End
,
0
),
"|"
))
let
changes
=
[
TextChange
(
TextSpan
(
recordSpan
.
Start
+
1
,
0
),
"|"
)
TextChange
(
TextSpan
(
recordSpan
.
End
,
0
),
"|"
)
]
let
diagnostics
=
context
.
Diagnostics
|>
Seq
.
filter
(
fun
x
->
fixableDiagnosticIds
|>
Set
.
contains
x
.
Id
)
|>
Seq
.
toImmutableArray
let
title
=
SR
.
ConvertToAnonymousRecord
()
let
codeFix
=
CodeAction
.
Create
(
title
,
(
fun
(
cancellationToken
:
CancellationToken
)
->
async
{
return
context
.
Document
.
WithText
(
getChangedText
()
)
}
|>
RoslynHelpers
.
StartAsyncAsTask
(
cancellationToken
)),
title
)
context
.
RegisterCodeFix
(
codeFix
,
diagnostics
)
context
.
RegisterFsharpFix
(
CodeFix
.
ConvertToAnonymousRecord
,
title
,
changes
)
}
|>
Async
.
Ignore
|>
RoslynHelpers
.
StartAsyncUnitAsTask
(
context
.
CancellationToken
)
vsintegration/src/FSharp.Editor/CodeFix/ConvertToNotEqualsEqualityExpression.fs
浏览文件 @
c2f78593
...
...
@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
.
Composition
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -12,10 +13,9 @@ open Microsoft.CodeAnalysis.CodeFixes
type
internal
FSharpConvertToNotEqualsEqualityExpressionCodeFixProvider
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0043"
]
static
let
title
=
SR
.
ConvertToNotEqualsEqualityExpression
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0043"
)
override
this
.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/ConvertToSingleEqualsEqualityExpression.fs
浏览文件 @
c2f78593
...
...
@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
.
Composition
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -12,10 +13,9 @@ open Microsoft.CodeAnalysis.CodeFixes
type
internal
FSharpConvertToSingleEqualsEqualityExpressionCodeFixProvider
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0043"
]
static
let
title
=
SR
.
ConvertToSingleEqualsEqualityExpression
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0043"
)
override
this
.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/FixIndexerAccess.fs
浏览文件 @
c2f78593
...
...
@@ -15,10 +15,10 @@ open FSharp.Compiler.Diagnostics
[<
ExportCodeFixProvider
(
FSharpConstants
.
FSharpLanguageName
,
Name
=
CodeFix
.
FixIndexerAccess
);
Shared
>]
type
internal
LegacyFsharpFixAddDotToIndexerAccess
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS3217"
]
static
let
title
=
CompilerDiagnostics
.
GetErrorMessage
FSharpDiagnosticKind
.
AddIndexerDot
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS3217"
)
override
_.
RegisterCodeFixesAsync
context
:
Task
=
async
{
...
...
@@ -56,7 +56,6 @@ type internal LegacyFsharpFixAddDotToIndexerAccess() =
[<
ExportCodeFixProvider
(
FSharpConstants
.
FSharpLanguageName
,
Name
=
CodeFix
.
RemoveIndexerDotBeforeBracket
);
Shared
>]
type
internal
FsharpFixRemoveDotFromIndexerAccessOptIn
()
as
this
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS3366"
]
static
let
title
=
CompilerDiagnostics
.
GetErrorMessage
FSharpDiagnosticKind
.
RemoveIndexerDot
...
...
@@ -69,7 +68,7 @@ type internal FsharpFixRemoveDotFromIndexerAccessOptIn() as this =
return
changes
}
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS3366"
)
override
_.
RegisterCodeFixesAsync
ctx
:
Task
=
backgroundTask
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/ImplementInterfaceCodeFixProvider.fs
浏览文件 @
c2f78593
...
...
@@ -6,6 +6,7 @@ open System
open
System
.
Composition
open
System
.
Threading
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Formatting
open
Microsoft
.
CodeAnalysis
.
Text
...
...
@@ -33,7 +34,6 @@ type internal InterfaceState =
[<
ExportCodeFixProvider
(
FSharpConstants
.
FSharpLanguageName
,
Name
=
"ImplementInterface"
);
Shared
>]
type
internal
FSharpImplementInterfaceCodeFixProvider
[<
ImportingConstructor
>]
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
[
"FS0366"
]
let
queryInterfaceState
appendBracketAt
(
pos
:
pos
)
(
tokens
:
Tokenizer
.
SavedTokenInfo
[]
)
(
ast
:
ParsedInput
)
=
asyncMaybe
{
...
...
@@ -143,10 +143,6 @@ type internal FSharpImplementInterfaceCodeFixProvider [<ImportingConstructor>] (
|>
Array
.
exists
(
fun
e
->
e
.
Severity
=
FSharpDiagnosticSeverity
.
Error
)
// This comparison is a bit expensive
if
hasTypeCheckError
&&
List
.
length
membersAndRanges
<>
Seq
.
length
interfaceMembers
then
let
diagnostics
=
context
.
Diagnostics
|>
Seq
.
filter
(
fun
x
->
fixableDiagnosticIds
|>
List
.
contains
x
.
Id
)
|>
Seq
.
toImmutableArray
let
registerCodeFix
title
verboseMode
=
let
codeAction
=
...
...
@@ -182,14 +178,14 @@ type internal FSharpImplementInterfaceCodeFixProvider [<ImportingConstructor>] (
title
)
context
.
RegisterCodeFix
(
codeAction
,
d
iagnostics
)
context
.
RegisterCodeFix
(
codeAction
,
context
.
D
iagnostics
)
registerCodeFix
(
SR
.
ImplementInterface
()
)
true
registerCodeFix
(
SR
.
ImplementInterfaceWithoutTypeAnnotation
()
)
false
else
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0366"
)
override
_.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/MakeDeclarationMutable.fs
浏览文件 @
c2f78593
...
...
@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
.
Composition
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -15,10 +16,9 @@ open FSharp.Compiler.Text
type
internal
FSharpMakeDeclarationMutableFixProvider
[<
ImportingConstructor
>]
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0027"
]
static
let
title
=
SR
.
MakeDeclarationMutable
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0027"
)
override
_.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/MakeOuterBindingRecursive.fs
浏览文件 @
c2f78593
...
...
@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
open
System
.
Composition
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -12,9 +13,7 @@ open Microsoft.CodeAnalysis.CodeFixes
type
internal
FSharpMakeOuterBindingRecursiveCodeFixProvider
[<
ImportingConstructor
>]
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0039"
]
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0039"
)
override
_.
RegisterCodeFixesAsync
context
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/ProposeUppercaseLabel.fs
浏览文件 @
c2f78593
...
...
@@ -4,16 +4,18 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
.
Composition
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
CodeFixes
open
Microsoft
.
CodeAnalysis
.
CodeActions
open
FSharp
.
Compiler
.
Diagnostics
[<
ExportCodeFixProvider
(
FSharpConstants
.
FSharpLanguageName
,
Name
=
"ProposeUpperCaseLabel"
);
Shared
>]
type
internal
FSharpProposeUpperCaseLabelCodeFixProvider
[<
ImportingConstructor
>]
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
[
"FS0053"
]
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0053"
)
override
_.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
@@ -25,12 +27,7 @@ type internal FSharpProposeUpperCaseLabelCodeFixProvider [<ImportingConstructor>
let
title
=
CompilerDiagnostics
.
GetErrorMessage
(
FSharpDiagnosticKind
.
ReplaceWithSuggestion
<|
textChanger
originalText
)
context
.
RegisterCodeFix
(
CodeAction
.
Create
(
title
,
solutionChanger
,
title
),
context
.
Diagnostics
|>
Seq
.
filter
(
fun
x
->
fixableDiagnosticIds
|>
List
.
contains
x
.
Id
)
|>
Seq
.
toImmutableArray
)
context
.
RegisterCodeFix
(
CodeAction
.
Create
(
title
,
solutionChanger
,
title
),
context
.
Diagnostics
)
}
|>
Async
.
Ignore
|>
RoslynHelpers
.
StartAsyncUnitAsTask
(
context
.
CancellationToken
)
vsintegration/src/FSharp.Editor/CodeFix/RemoveReturnOrYield.fs
浏览文件 @
c2f78593
...
...
@@ -3,6 +3,7 @@
namespace
Microsoft
.
VisualStudio
.
FSharp
.
Editor
open
System
.
Composition
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -11,9 +12,7 @@ open Microsoft.CodeAnalysis.CodeFixes
type
internal
FSharpRemoveReturnOrYieldCodeFixProvider
[<
ImportingConstructor
>]
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0748"
;
"FS0747"
]
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0748"
,
"FS0747"
)
override
_.
RegisterCodeFixesAsync
context
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/ReplaceWithSuggestion.fs
浏览文件 @
c2f78593
...
...
@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
.
Composition
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -18,9 +19,7 @@ open FSharp.Compiler.Tokenization
type
internal
FSharpReplaceWithSuggestionCodeFixProvider
[<
ImportingConstructor
>]
(
settings
:
EditorOptions
)
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0039"
;
"FS1129"
;
"FS0495"
]
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0039"
,
"FS1129"
,
"FS0495"
)
override
_.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/UseMutationWhenValueIsMutable.fs
浏览文件 @
c2f78593
...
...
@@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
open
System
.
Composition
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -16,9 +17,8 @@ open FSharp.Compiler.Text
type
internal
FSharpUseMutationWhenValueIsMutableFixProvider
[<
ImportingConstructor
>]
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0020"
]
static
let
title
=
SR
.
UseMutationWhenValueIsMutable
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0020"
)
override
_.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/UseTripleQuotedInterpolation.fs
浏览文件 @
c2f78593
...
...
@@ -3,6 +3,7 @@
namespace
Microsoft
.
VisualStudio
.
FSharp
.
Editor
open
System
.
Composition
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
...
...
@@ -11,9 +12,8 @@ open Microsoft.CodeAnalysis.CodeFixes
type
internal
FSharpUseTripleQuotedInterpolationCodeFixProvider
[<
ImportingConstructor
>]
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
[
"FS3373"
]
static
let
title
=
SR
.
UseTripleQuotedInterpolation
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS3373"
)
override
_.
RegisterCodeFixesAsync
context
=
asyncMaybe
{
...
...
vsintegration/src/FSharp.Editor/CodeFix/WrapExpressionInParentheses.fs
浏览文件 @
c2f78593
...
...
@@ -5,42 +5,27 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open
System
.
Composition
open
System
.
Threading
open
System
.
Threading
.
Tasks
open
System
.
Collections
.
Immutable
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
open
Microsoft
.
CodeAnalysis
.
CodeActions
[<
ExportCodeFixProvider
(
FSharpConstants
.
FSharpLanguageName
,
Name
=
"AddParentheses"
);
Shared
>]
[<
ExportCodeFixProvider
(
FSharpConstants
.
FSharpLanguageName
,
Name
=
CodeFix
.
AddParentheses
);
Shared
>]
type
internal
FSharpWrapExpressionInParenthesesFixProvider
()
=
inherit
CodeFixProvider
()
let
fixableDiagnosticIds
=
set
[
"FS0597"
]
static
let
title
=
SR
.
WrapExpressionInParentheses
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
fixableDiagnosticIds
override
_.
FixableDiagnosticIds
=
ImmutableArray
.
Create
(
"FS0597"
)
override
this
.
RegisterCodeFixesAsync
context
:
Task
=
async
{
let
title
=
SR
.
WrapExpressionInParentheses
()
let
getChangedText
(
sourceText
:
SourceText
)
=
sourceText
.
WithChanges
(
TextChange
(
TextSpan
(
context
.
Span
.
Start
,
0
),
"("
))
.
WithChanges
(
TextChange
(
TextSpan
(
context
.
Span
.
End
+
1
,
0
),
")"
))
context
.
RegisterCodeFix
(
CodeAction
.
Create
(
title
,
(
fun
(
cancellationToken
:
CancellationToken
)
->
async
{
let
!
sourceText
=
context
.
Document
.
GetTextAsync
(
cancellationToken
)
|>
Async
.
AwaitTask
return
context
.
Document
.
WithText
(
getChangedText
sourceText
)
}
|>
RoslynHelpers
.
StartAsyncAsTask
(
cancellationToken
)),
title
),
context
.
Diagnostics
|>
Seq
.
filter
(
fun
x
->
this
.
FixableDiagnosticIds
.
Contains
x
.
Id
)
|>
Seq
.
toImmutableArray
)
backgroundTask
{
let
changes
=
[
TextChange
(
TextSpan
(
context
.
Span
.
Start
,
0
),
"("
)
TextChange
(
TextSpan
(
context
.
Span
.
End
+
1
,
0
),
")"
)
]
context
.
RegisterFsharpFix
(
CodeFix
.
AddParentheses
,
title
,
changes
)
}
|>
RoslynHelpers
.
StartAsyncUnitAsTask
(
context
.
CancellationToken
)
vsintegration/src/FSharp.Editor/Common/Constants.fs
浏览文件 @
c2f78593
...
...
@@ -98,6 +98,19 @@ module internal Guids =
[<
RequireQualifiedAccess
>]
module
internal
CodeFix
=
[<
Literal
>]
let
AddParentheses
=
"AddParentheses"
[<
Literal
>]
let
AddTypeAnnotationToObjectOfIndeterminateType
=
"AddTypeAnnotationToObjectOfIndeterminateType"
[<
Literal
>]
let
AddMissingRecToMutuallyRecFunctions
=
"AddMissingRecToMutuallyRecFunctions"
[<
Literal
>]
let
ConvertToAnonymousRecord
=
"ConvertToAnonymousRecord"
[<
Literal
>]
let
AddInstanceMemberParameter
=
"AddInstanceMemberParameter"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录