forked from dotnet/roslyn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* For background, see: * dotnet#35591 * dotnet/fsharp#16078, * dotnet/fsharp#16079 (comment) * dotnet/fsharp#16079 (review) * dotnet/fsharp#16211
- Loading branch information
1 parent
139f845
commit c9868af
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...udio/ExternalAccess/FSharp/Diagnostics/IFSharpUnnecessaryParenthesesDiagnosticAnalyzer.cs
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,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); | ||
} |
54 changes: 54 additions & 0 deletions
54
...ernalAccess/FSharp/Internal/Diagnostics/FSharpUnnecessaryParenthesesDiagnosticAnalyzer.cs
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,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; | ||
} |
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