Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F# unnecessary parentheses analyzer shim #75015

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ internal static class FSharpIDEDiagnosticIds
{
public static string SimplifyNamesDiagnosticId => IDEDiagnosticIds.SimplifyNamesDiagnosticId;
public static string RemoveUnnecessaryImportsDiagnosticId => IDEDiagnosticIds.RemoveUnnecessaryImportsDiagnosticId;
public static string RemoveUnnecessaryParenthesesDiagnosticId => IDEDiagnosticIds.RemoveUnnecessaryParenthesesDiagnosticId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics;

internal interface IFSharpUnnecessaryParenthesesDiagnosticAnalyzer
{
Task<ImmutableArray<Diagnostic>> AnalyzeSyntaxAsync(DiagnosticDescriptor descriptor, Document document, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Immutable;
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;

namespace Microsoft.CodeAnalysis.ExternalAccess.FSharp.Internal.Diagnostics;

[Shared]
[ExportLanguageService(typeof(FSharpUnnecessaryParenthesesDiagnosticAnalyzerService), LanguageNames.FSharp)]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class FSharpUnnecessaryParenthesesDiagnosticAnalyzerService(IFSharpUnnecessaryParenthesesDiagnosticAnalyzer analyzer) : ILanguageService
{
public Task<ImmutableArray<Diagnostic>> AnalyzeSyntaxAsync(DiagnosticDescriptor descriptor, Document document, CancellationToken cancellationToken)
=> analyzer.AnalyzeSyntaxAsync(descriptor, document, cancellationToken);
}

[DiagnosticAnalyzer(LanguageNames.FSharp)]
internal sealed class FSharpUnnecessaryParenthesesDiagnosticAnalyzer : DocumentDiagnosticAnalyzer, IBuiltInAnalyzer
{
private readonly DiagnosticDescriptor _descriptor =
new(
IDEDiagnosticIds.RemoveUnnecessaryParenthesesDiagnosticId,
new LocalizableResourceString(nameof(AnalyzersResources.Remove_unnecessary_parentheses), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)),
new LocalizableResourceString(nameof(AnalyzersResources.Parentheses_can_be_removed), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)),
DiagnosticCategory.Style,
DiagnosticSeverity.Hidden,
isEnabledByDefault: true,
customTags: FSharpDiagnosticCustomTags.Unnecessary);

public FSharpUnnecessaryParenthesesDiagnosticAnalyzer() => SupportedDiagnostics = [_descriptor];

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }

public override Task<ImmutableArray<Diagnostic>> AnalyzeSemanticsAsync(Document document, CancellationToken cancellationToken)
=> Task.FromResult<ImmutableArray<Diagnostic>>([]);

public override Task<ImmutableArray<Diagnostic>> AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
=> document.Project.Services.GetService<FSharpUnnecessaryParenthesesDiagnosticAnalyzerService>()?.AnalyzeSyntaxAsync(_descriptor, document, cancellationToken)
?? Task.FromResult<ImmutableArray<Diagnostic>>([]);

public bool IsHighPriority => false;

public DiagnosticAnalyzerCategory GetAnalyzerCategory() => DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics.FSharpIDEDiagnosticIds
Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics.IFSharpDiagnosticAnalyzerService
Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics.IFSharpDocumentDiagnosticAnalyzer
Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics.IFSharpSimplifyNameDiagnosticAnalyzer
Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics.IFSharpUnnecessaryParenthesesDiagnosticAnalyzer
Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics.IFSharpUnnecessaryParenthesesDiagnosticAnalyzer.AnalyzeSyntaxAsync(Microsoft.CodeAnalysis.DiagnosticDescriptor! descriptor, Microsoft.CodeAnalysis.Document! document, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Diagnostic!>>!
Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics.IFSharpUnusedDeclarationsDiagnosticAnalyzer
Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics.IFSharpUnusedOpensDiagnosticAnalyzer
Microsoft.CodeAnalysis.ExternalAccess.FSharp.DocumentHighlighting.FSharpDocumentHighlights
Expand Down Expand Up @@ -569,6 +571,7 @@ static Microsoft.CodeAnalysis.ExternalAccess.FSharp.TaskList.FSharpTaskListItem.
~static Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics.FSharpDiagnosticCustomTags.Microsoft.get -> string[]
~static Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics.FSharpDiagnosticCustomTags.Unnecessary.get -> string[]
~static Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics.FSharpIDEDiagnosticIds.RemoveUnnecessaryImportsDiagnosticId.get -> string
~static Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics.FSharpIDEDiagnosticIds.RemoveUnnecessaryParenthesesDiagnosticId.get -> string
~static Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics.FSharpIDEDiagnosticIds.SimplifyNamesDiagnosticId.get -> string
~static Microsoft.CodeAnalysis.ExternalAccess.FSharp.Editor.Shared.Extensions.FSharpDependencyObjectExtensions.SetDefaultTextProperties(this System.Windows.DependencyObject dependencyObject, Microsoft.VisualStudio.Text.Classification.IClassificationFormatMap formatMap) -> void
~static Microsoft.CodeAnalysis.ExternalAccess.FSharp.Editor.Shared.Extensions.FSharpDependencyObjectExtensions.SetTextProperties(this System.Windows.DependencyObject dependencyObject, Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties textProperties) -> void
Expand Down
Loading