Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
fsharp
提交
f35fa1a1
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,发现更多精彩内容 >>
未验证
提交
f35fa1a1
编写于
11月 08, 2022
作者:
T
Tomas Grosup
提交者:
GitHub
11月 08, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New codefix provider to remove superflous binding for a Union case that has 0 fields. (#14267)
上级
96cf79f2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
66 addition
and
0 deletion
+66
-0
vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs
vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs
+15
-0
vsintegration/src/FSharp.Editor/CodeFix/RemoveSuperflousCaptureForUnionCaseWithNoData.fs
.../CodeFix/RemoveSuperflousCaptureForUnionCaseWithNoData.fs
+50
-0
vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj
vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj
+1
-0
未找到文件。
vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs
浏览文件 @
f35fa1a1
...
...
@@ -22,3 +22,18 @@ module internal CodeFixHelpers =
|
Some
textChanges
->
return
context
.
Document
.
WithText
(
sourceText
.
WithChanges
(
textChanges
))
}
|>
RoslynHelpers
.
StartAsyncAsTask
(
cancellationToken
)),
title
)
[<
AutoOpen
>]
module
internal
CodeFixExtensions
=
type
CodeFixProvider
with
member
this
.
GetPrunedDiagnostics
(
context
:
CodeFixContext
)
=
context
.
Diagnostics
.
RemoveAll
(
fun
x
->
this
.
FixableDiagnosticIds
.
Contains
(
x
.
Id
)
|>
not
)
member
this
.
RegisterFix
(
context
:
CodeFixContext
,
fixName
,
fixChange
)
=
let
replaceCodeFix
=
CodeFixHelpers
.
createTextChangeCodeFix
(
fixName
,
context
,
(
fun
()
->
asyncMaybe
.
Return
[|
fixChange
|]))
context
.
RegisterCodeFix
(
replaceCodeFix
,
this
.
GetPrunedDiagnostics
(
context
))
vsintegration/src/FSharp.Editor/CodeFix/RemoveSuperflousCaptureForUnionCaseWithNoData.fs
0 → 100644
浏览文件 @
f35fa1a1
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace
Microsoft
.
VisualStudio
.
FSharp
.
Editor
open
System
open
System
.
Composition
open
System
.
Threading
.
Tasks
open
Microsoft
.
CodeAnalysis
.
Text
open
Microsoft
.
CodeAnalysis
.
CodeFixes
open
FSharp
.
Compiler
open
FSharp
.
Compiler
.
CodeAnalysis
open
FSharp
.
Compiler
.
Symbols
open
FSharp
.
Compiler
.
Syntax
open
FSharp
.
Compiler
.
EditorServices
[<
ExportCodeFixProvider
(
FSharpConstants
.
FSharpLanguageName
,
Name
=
"RemoveSuperflousCapture"
);
Shared
>]
type
internal
RemoveSuperflousCaptureForUnionCaseWithNoDataProvider
[<
ImportingConstructor
>]
(
)
=
inherit
CodeFixProvider
()
override
_.
FixableDiagnosticIds
=
Seq
.
toImmutableArray
[
"FS0725"
;
"FS3548"
]
override
this
.
RegisterCodeFixesAsync
context
:
Task
=
asyncMaybe
{
do
!
Option
.
guard
context
.
Document
.
Project
.
IsFSharpCodeFixesUnusedDeclarationsEnabled
let
document
=
context
.
Document
let
!
sourceText
=
document
.
GetTextAsync
(
context
.
CancellationToken
)
let
!
_,
checkResults
=
document
.
GetFSharpParseAndCheckResultsAsync
(
nameof
(
RemoveSuperflousCaptureForUnionCaseWithNoDataProvider
))
|>
liftAsync
let
m
=
RoslynHelpers
.
TextSpanToFSharpRange
(
document
.
FilePath
,
context
.
Span
,
sourceText
)
let
classifications
=
checkResults
.
GetSemanticClassification
(
Some
m
)
let
unionCaseItem
=
classifications
|>
Array
.
tryFind
(
fun
c
->
c
.
Type
=
SemanticClassificationType
.
UnionCase
)
match
unionCaseItem
with
|
None
->
()
|
Some
unionCaseItem
->
// The error/warning captures entire pattern match, like "Ns.Type.DuName bindingName". We want to keep type info when suggesting a replacement, and only remove "bindingName".
let
typeInfoLength
=
unionCaseItem
.
Range
.
EndColumn
-
m
.
StartColumn
let
reminderSpan
=
new
TextSpan
(
context
.
Span
.
Start
+
typeInfoLength
,
context
.
Span
.
Length
-
typeInfoLength
)
this
.
RegisterFix
(
context
,
SR
.
RemoveUnusedBinding
()
,
TextChange
(
reminderSpan
,
""
))
}
|>
Async
.
Ignore
|>
RoslynHelpers
.
StartAsyncUnitAsTask
(
context
.
CancellationToken
)
vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj
浏览文件 @
f35fa1a1
...
...
@@ -114,6 +114,7 @@
<Compile
Include=
"CodeFix\AddOpenCodeFixProvider.fs"
/>
<Compile
Include=
"CodeFix\ProposeUppercaseLabel.fs"
/>
<Compile
Include=
"CodeFix\ReplaceWithSuggestion.fs"
/>
<Compile
Include=
"CodeFix\RemoveSuperflousCaptureForUnionCaseWithNoData.fs"
/>
<Compile
Include=
"CodeFix\RemoveUnusedBinding.fs"
/>
<Compile
Include=
"CodeFix\RenameUnusedValue.fs"
/>
<Compile
Include=
"CodeFix\ImplementInterfaceCodeFixProvider.fs"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录