-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15734 from dotnet/merges/main-to-release/dev17.8
- Loading branch information
Showing
28 changed files
with
215 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
vsintegration/src/FSharp.Editor/CodeFixes/DiscardUnusedValue.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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 System.Collections.Immutable | ||
|
||
open Microsoft.CodeAnalysis.Text | ||
open Microsoft.CodeAnalysis.CodeFixes | ||
|
||
open FSharp.Compiler.Symbols | ||
|
||
open CancellableTasks | ||
|
||
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = CodeFix.RenameUnusedValue); Shared>] | ||
type internal RenameUnusedValueWithUnderscoreCodeFixProvider [<ImportingConstructor>] () = | ||
|
||
inherit CodeFixProvider() | ||
|
||
static let getTitle (symbolName: string) = | ||
String.Format(SR.RenameValueToUnderscore(), symbolName) | ||
|
||
override _.FixableDiagnosticIds = ImmutableArray.Create "FS1182" | ||
|
||
override this.RegisterCodeFixesAsync context = | ||
if context.Document.Project.IsFSharpCodeFixesUnusedDeclarationsEnabled then | ||
context.RegisterFsharpFix this | ||
else | ||
Task.CompletedTask | ||
|
||
override this.GetFixAllProvider() = this.RegisterFsharpFixAll() | ||
|
||
interface IFSharpCodeFixProvider with | ||
member _.GetCodeFixIfAppliesAsync context = | ||
cancellableTask { | ||
let! sourceText = context.GetSourceTextAsync() | ||
let! symbol = UnusedCodeFixHelper.getUnusedSymbol context.Span context.Document sourceText CodeFix.RenameUnusedValue | ||
|
||
return | ||
symbol | ||
|> ValueOption.filter (fun symbol -> | ||
match symbol with | ||
| :? FSharpMemberOrFunctionOrValue as x when x.IsConstructorThisValue -> false | ||
| _ -> true) | ||
|> ValueOption.map (fun symbol -> | ||
{ | ||
Name = CodeFix.RenameUnusedValue | ||
Message = getTitle symbol.DisplayName | ||
Changes = [ TextChange(context.Span, "_") ] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
vsintegration/src/FSharp.Editor/CodeFixes/PrefixUnusedValue.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// 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 System.Collections.Immutable | ||
|
||
open Microsoft.CodeAnalysis.Text | ||
open Microsoft.CodeAnalysis.CodeFixes | ||
|
||
open CancellableTasks | ||
|
||
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = CodeFix.PrefixUnusedValue); Shared>] | ||
type internal PrefixUnusedValueWithUnderscoreCodeFixProvider [<ImportingConstructor>] () = | ||
|
||
inherit CodeFixProvider() | ||
|
||
static let getTitle (symbolName: string) = | ||
String.Format(SR.PrefixValueNameWithUnderscore(), symbolName) | ||
|
||
override _.FixableDiagnosticIds = ImmutableArray.Create "FS1182" | ||
|
||
override this.RegisterCodeFixesAsync context = | ||
if context.Document.Project.IsFSharpCodeFixesUnusedDeclarationsEnabled then | ||
context.RegisterFsharpFix this | ||
else | ||
Task.CompletedTask | ||
|
||
override this.GetFixAllProvider() = this.RegisterFsharpFixAll() | ||
|
||
interface IFSharpCodeFixProvider with | ||
member _.GetCodeFixIfAppliesAsync context = | ||
cancellableTask { | ||
let! sourceText = context.GetSourceTextAsync() | ||
let! symbol = UnusedCodeFixHelper.getUnusedSymbol context.Span context.Document sourceText CodeFix.PrefixUnusedValue | ||
|
||
return | ||
symbol | ||
|> ValueOption.map (fun symbol -> | ||
{ | ||
Name = CodeFix.PrefixUnusedValue | ||
Message = getTitle symbol.DisplayName | ||
Changes = [ TextChange(TextSpan(context.Span.Start, 0), "_") ] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.