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

Commit162e572

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
Add new keyword code fix (dotnet#2077)
* "add 'new' keyword" code fix* "add open" code fix returns FS0039 as "fixed" diagnostics (only)* fix a typo in file name
1 parent1c8f113 commit162e572

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.Text
11+
openMicrosoft.CodeAnalysis.CodeFixes
12+
openMicrosoft.CodeAnalysis.CodeActions
13+
14+
[<ExportCodeFixProvider(FSharpCommonConstants.FSharpLanguageName, Name="AddNewKeyword"); Shared>]
15+
typeinternalFSharpAddNewKeywordCodeFixProvider()=
16+
inherit CodeFixProvider()
17+
18+
override__.FixableDiagnosticIds=["FS0760"].ToImmutableArray()
19+
20+
overridethis.RegisterCodeFixesAsync context:Task=
21+
async{
22+
lettitle="Add\"new\" keyword"
23+
context.RegisterCodeFix(
24+
CodeAction.Create(
25+
title,
26+
(fun(cancellationToken: CancellationToken)->
27+
async{
28+
let!sourceText= context.Document.GetTextAsync()|> Async.AwaitTask
29+
return context.Document.WithText(sourceText.WithChanges(TextChange(TextSpan(context.Span.Start,0),"new")))
30+
}|> CommonRoslynHelpers.StartAsyncAsTask(cancellationToken)),
31+
title),(context.Diagnostics|> Seq.filter(fun x-> this.FixableDiagnosticIds.Contains x.Id)).ToImmutableArray())
32+
}|> CommonRoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)
33+

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ type internal FSharpAddOpenCodeFixProvider
108108
assemblyContentProvider: AssemblyContentProvider
109109
)=
110110
inherit CodeFixProvider()
111+
letfixableDiagnosticIds=["FS0039"]
111112

112113
letchecker= checkerProvider.Checker
113114
letfixUnderscoresInMenuText(text:string)= text.Replace("_","__")
@@ -162,9 +163,9 @@ type internal FSharpAddOpenCodeFixProvider
162163
|> Seq.toList
163164

164165
for codeFixin openNamespaceFixes@ quilifySymbolFixesdo
165-
context.RegisterCodeFix(codeFix, context.Diagnostics)
166+
context.RegisterCodeFix(codeFix,(context.Diagnostics|> Seq.filter(fun x-> fixableDiagnosticIds.Contains x.Id)).ToImmutableArray())
166167

167-
override__.FixableDiagnosticIds=["FS0039"].ToImmutableArray()
168+
override__.FixableDiagnosticIds=fixableDiagnosticIds.ToImmutableArray()
168169

169170
override__.RegisterCodeFixesAsync context:Task=
170171
async{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<CompileInclude="Commands\HelpContextService.fs" />
5858
<CompileInclude="Commands\FsiCommandService.fs" />
5959
<CompileInclude="CodeFix\AddOpenCodeFixProvider.fs" />
60+
<CompileInclude="CodeFix\AddNewKeywordToDisposableConstructorInvocation.fs" />
6061
</ItemGroup>
6162
<ItemGroup>
6263
<ProjectReferenceInclude="$(FSharpSourcesRoot)\fsharp\FSharp.Core\FSharp.Core.fsproj">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp