@@ -12,6 +12,8 @@ open Microsoft.CodeAnalysis.Text
1212open Microsoft.CodeAnalysis .CodeFixes
1313open Microsoft.CodeAnalysis .CodeActions
1414
15+ open Microsoft.FSharp .Compiler
16+
1517[<ExportCodeFixProvider( FSharpCommonConstants.FSharpLanguageName, Name= " PrefixUnusedValueWithUnderscore" ); Shared>]
1618type internal FSharpPrefixUnusedValueWithUnderscoreCodeFixProvider () =
1719inherit CodeFixProvider()
@@ -30,8 +32,14 @@ type internal FSharpPrefixUnusedValueWithUnderscoreCodeFixProvider() =
3032override __.FixableDiagnosticIds = fixableDiagnosticIds.ToImmutableArray()
3133
3234override __.RegisterCodeFixesAsync context : Task =
33- async {
34- let diagnostics = ( context.Diagnostics|> Seq.filter( fun x -> fixableDiagnosticIds|> List.contains x.Id)). ToImmutableArray()
35- context.RegisterCodeFix( createCodeFix( SR.PrefixValueNameWithUnderscore.Value, context, TextChange( TextSpan( context.Span.Start, 0 ), " _" )), diagnostics)
36- context.RegisterCodeFix( createCodeFix( SR.RenameValueToUnderscore.Value, context, TextChange( context.Span, " _" )), diagnostics)
35+ async {
36+ let! sourceText = context.Document.GetTextAsync()
37+ let ident = sourceText.ToString( context.Span)
38+ // Prefixing operators and backticked identifiers does not make sense.
39+ // We have to use the additional check for backtickes because `IsOperatorOrBacktickedName` operates on display names
40+ // where backtickes are replaced with parens.
41+ if not ( PrettyNaming.IsOperatorOrBacktickedName ident) && not ( ident.StartsWith" ``" ) then
42+ let diagnostics = ( context.Diagnostics|> Seq.filter( fun x -> fixableDiagnosticIds|> List.contains x.Id)). ToImmutableArray()
43+ context.RegisterCodeFix( createCodeFix( SR.PrefixValueNameWithUnderscore.Value, context, TextChange( TextSpan( context.Span.Start, 0 ), " _" )), diagnostics)
44+ context.RegisterCodeFix( createCodeFix( SR.RenameValueToUnderscore.Value, context, TextChange( context.Span, " _" )), diagnostics)
3745} |> CommonRoslynHelpers.StartAsyncUnitAsTask( context.CancellationToken)