Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7906466

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
PrefixUnusedValueWithUnderscore code fix (dotnet#2088)
* add PrefixUnusedValueWithUnderscore code fix* add "rename unused value to '_'" code fix* naming
1 parenta9b8235 commit7906466

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

‎vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ open System.Collections.Generic
99
openSystem.Collections.Immutable
1010
openSystem.Threading
1111
openSystem.Threading.Tasks
12-
openSystem.Linq
1312
openSystem.Runtime.CompilerServices
1413
openSystem.Windows
1514
openSystem.Windows.Controls
@@ -164,7 +163,7 @@ type internal FSharpAddOpenCodeFixProvider
164163
|> Seq.toList
165164

166165
for codeFixin openNamespaceFixes@ quilifySymbolFixesdo
167-
context.RegisterCodeFix(codeFix,(context.Diagnostics|> Seq.filter(fun x-> fixableDiagnosticIds.Contains x.Id)).ToImmutableArray())
166+
context.RegisterCodeFix(codeFix,(context.Diagnostics|> Seq.filter(fun x-> fixableDiagnosticIds|> List.contains x.Id)).ToImmutableArray())
168167

169168
override__.FixableDiagnosticIds= fixableDiagnosticIds.ToImmutableArray()
170169

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2+
3+
namespacerecMicrosoft.VisualStudio.FSharp.Editor
4+
5+
openSystem.Composition
6+
openSystem.Collections.Immutable
7+
openSystem.Threading
8+
openSystem.Threading.Tasks
9+
10+
openMicrosoft.CodeAnalysis
11+
openMicrosoft.CodeAnalysis.Text
12+
openMicrosoft.CodeAnalysis.CodeFixes
13+
openMicrosoft.CodeAnalysis.CodeActions
14+
15+
[<ExportCodeFixProvider(FSharpCommonConstants.FSharpLanguageName, Name="PrefixUnusedValueWithUnderscore"); Shared>]
16+
typeinternalFSharpPrefixUnusedValueWithUnderscoreCodeFixProvider()=
17+
inherit CodeFixProvider()
18+
letfixableDiagnosticIds=["FS1182"]
19+
20+
letcreateCodeFix(title:string,context:CodeFixContext,textChange:TextChange)=
21+
CodeAction.Create(
22+
title,
23+
(fun(cancellationToken: CancellationToken)->
24+
async{
25+
let!sourceText= context.Document.GetTextAsync()|> Async.AwaitTask
26+
return context.Document.WithText(sourceText.WithChanges(textChange))
27+
}|> CommonRoslynHelpers.StartAsyncAsTask(cancellationToken)),
28+
title)
29+
30+
override__.FixableDiagnosticIds= fixableDiagnosticIds.ToImmutableArray()
31+
32+
override__.RegisterCodeFixesAsync context:Task=
33+
async{
34+
letdiagnostics=(context.Diagnostics|> Seq.filter(fun x-> fixableDiagnosticIds|> List.contains x.Id)).ToImmutableArray()
35+
context.RegisterCodeFix(createCodeFix("Prefix value name with underscore", context, TextChange(TextSpan(context.Span.Start,0),"_")), diagnostics)
36+
context.RegisterCodeFix(createCodeFix("Rename value to '_'", context, TextChange(context.Span,"_")), diagnostics)
37+
}|> CommonRoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)

‎vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@
6060
<CompileInclude="Structure\BlockStructureService.fs" />
6161
<CompileInclude="Commands\HelpContextService.fs" />
6262
<CompileInclude="Commands\FsiCommandService.fs" />
63-
<CompileInclude="CodeFix\AddOpenCodeFixProvider.fs" />
6463
<CompileInclude="CodeFix\AddNewKeywordToDisposableConstructorInvocation.fs" />
64+
<CompileInclude="CodeFix\AddOpenCodeFixProvider.fs" />
65+
<CompileInclude="CodeFix\PrefixUnusedValueWithUnderscore.fs" />
6566
</ItemGroup>
6667
<ItemGroup>
6768
<ProjectReferenceInclude="$(FSharpSourcesRoot)\fsharp\FSharp.Core\FSharp.Core.fsproj">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp