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

Commit07e08e2

Browse files
committed
Add FixIndexerAccessCodeFix
1 parent64f9a90 commit07e08e2

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

‎src/fsharp/FSComp.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ undefinedNameSuggestionsIntro,"Maybe you want one of the following:"
1616
undefinedNameTypeParameter,"The type parameter %s is not defined."
1717
undefinedNamePatternDiscriminator,"The pattern discriminator '%s' is not defined."
1818
replaceWithSuggestion,"Replace with '%s'"
19+
addIndexerDot,"Add . for indexer access."
1920
missingElseBranch,"The 'if' expression is missing an 'else' branch. The 'then' branch has type '%s'. Because 'if' is an expression, and not a statement, add an 'else' branch which returns a value of the same type."
2021
elseBranchHasWrongType,"All branches of an 'if' expression must return the same type. This expression was expected to have type '%s' but here has type '%s'."
2122
commaInsteadOfSemicolonInRecord,"A ';' is used to separate field values in records. Consider replacing ',' with ';'."
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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
6+
openSystem.Composition
7+
openSystem.Collections.Immutable
8+
openSystem.Threading
9+
openSystem.Threading.Tasks
10+
11+
openMicrosoft.CodeAnalysis
12+
openMicrosoft.CodeAnalysis.Text
13+
openMicrosoft.CodeAnalysis.CodeFixes
14+
openMicrosoft.CodeAnalysis.CodeActions
15+
16+
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name="FixIndexerAccess"); Shared>]
17+
typeinternalFSharpFixIndexerAccessCodeFixProvider()=
18+
inherit CodeFixProvider()
19+
letfixableDiagnosticIds= set["FS3217"]
20+
21+
letcreateCodeFix(title:string,context:CodeFixContext,textChange:TextChange)=
22+
CodeAction.Create(
23+
title,
24+
(fun(cancellationToken: CancellationToken)->
25+
async{
26+
let!cancellationToken= Async.CancellationToken
27+
let!sourceText= context.Document.GetTextAsync(cancellationToken)|> Async.AwaitTask
28+
return context.Document.WithText(sourceText.WithChanges(textChange))
29+
}|> RoslynHelpers.StartAsyncAsTask(cancellationToken)),
30+
title)
31+
32+
override__.FixableDiagnosticIds= Seq.toImmutableArray fixableDiagnosticIds
33+
34+
override__.RegisterCodeFixesAsync context:Task=
35+
async{
36+
letdiagnostics=
37+
context.Diagnostics
38+
|> Seq.filter(fun x-> fixableDiagnosticIds|> Set.contains x.Id)
39+
|> Seq.toList
40+
ifnot(List.isEmpty diagnostics)then
41+
let!sourceText= context.Document.GetTextAsync()|> Async.AwaitTask
42+
43+
diagnostics
44+
|> Seq.iter(fun diagnostic->
45+
letdiagnostics= ImmutableArray.Create diagnostic
46+
47+
letcodefix=
48+
createCodeFix(
49+
FSComp.SR.addIndexerDot(),
50+
context,
51+
TextChange(context.Span, sourceText.GetSubText(context.Span).ToString()+"."))
52+
context.RegisterCodeFix(codefix, diagnostics))
53+
}|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
<CompileInclude="CodeFix\SimplifyName.fs" />
9292
<CompileInclude="CodeFix\RemoveUnusedOpens.fs" />
9393
<CompileInclude="CodeFix\MissingReferenceCodeFixProvider.fs" />
94+
<CompileInclude="CodeFix\FixIndexerAccess.fs" />
9495
</ItemGroup>
9596
<ItemGroup>
9697
<ProjectReferenceInclude="$(FSharpSourcesRoot)\fsharp\FSharp.Core\FSharp.Core.fsproj">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp