未验证 提交 1c8e8166 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #28873 from sharwell/formatting-analyzer

Formatting analyzer
......@@ -26,8 +26,10 @@
Dependency versions
-->
<PropertyGroup>
<!-- RoslynDiagnosticsNugetPackageVersion is used by several individual analyzer references below -->
<!-- Versions used by several individual references below -->
<RoslynDiagnosticsNugetPackageVersion>2.6.2-beta2</RoslynDiagnosticsNugetPackageVersion>
<CodeStyleLayerCodeAnalysisVersion>2.8.2</CodeStyleLayerCodeAnalysisVersion>
<MicrosoftCodeAnalysisTestingVersion>1.0.0-beta1-63310-01</MicrosoftCodeAnalysisTestingVersion>
<BasicUndoVersion>0.9.3</BasicUndoVersion>
<BenchmarkDotNetVersion>0.11.0</BenchmarkDotNetVersion>
......@@ -47,8 +49,10 @@
<MicrosoftBuildTasksCoreVersion>15.1.0-preview-000458-02</MicrosoftBuildTasksCoreVersion>
<MicrosoftCodeAnalysisAnalyzersVersion>$(RoslynDiagnosticsNugetPackageVersion)</MicrosoftCodeAnalysisAnalyzersVersion>
<MicrosoftCodeAnalysisBuildTasksVersion>2.0.0-rc2-61102-09</MicrosoftCodeAnalysisBuildTasksVersion>
<MicrosoftCodeAnalysisCSharpCodeFixTestingXUnitVersion>$(MicrosoftCodeAnalysisTestingVersion)</MicrosoftCodeAnalysisCSharpCodeFixTestingXUnitVersion>
<MicrosoftCodeAnalysisElfieVersion>0.10.6</MicrosoftCodeAnalysisElfieVersion>
<MicrosoftCodeAnalysisTestResourcesProprietaryVersion>2.0.12</MicrosoftCodeAnalysisTestResourcesProprietaryVersion>
<MicrosoftCodeAnalysisVisualBasicCodeFixTestingXUnitVersion>$(MicrosoftCodeAnalysisTestingVersion)</MicrosoftCodeAnalysisVisualBasicCodeFixTestingXUnitVersion>
<MicrosoftCodeQualityAnalyzersVersion>$(RoslynDiagnosticsNugetPackageVersion)</MicrosoftCodeQualityAnalyzersVersion>
<SystemCompositionVersion>1.0.31</SystemCompositionVersion>
<MicrosoftCSharpVersion>4.3.0</MicrosoftCSharpVersion>
......@@ -262,6 +266,17 @@
<xunitrunnerconsoleVersion>2.4.1-pre.build.4059</xunitrunnerconsoleVersion>
<xunitrunnerwpfVersion>1.0.51</xunitrunnerwpfVersion>
<xunitrunnervisualstudioVersion>2.4.1-pre.build.4059</xunitrunnervisualstudioVersion>
<!--
The CodeStyle layer depends on a prior stable release of the CodeAnalysis assemblies so the NuGet packages
produced by the build can be installed in projects building with those older releases.
-->
<MicrosoftCodeAnalysisCommonFixedVersion>$(CodeStyleLayerCodeAnalysisVersion)</MicrosoftCodeAnalysisCommonFixedVersion>
<MicrosoftCodeAnalysisWorkspacesCommonFixedVersion>$(CodeStyleLayerCodeAnalysisVersion)</MicrosoftCodeAnalysisWorkspacesCommonFixedVersion>
<MicrosoftCodeAnalysisCSharpFixedVersion>$(CodeStyleLayerCodeAnalysisVersion)</MicrosoftCodeAnalysisCSharpFixedVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesFixedVersion>$(CodeStyleLayerCodeAnalysisVersion)</MicrosoftCodeAnalysisCSharpWorkspacesFixedVersion>
<MicrosoftCodeAnalysisVisualBasicFixedVersion>$(CodeStyleLayerCodeAnalysisVersion)</MicrosoftCodeAnalysisVisualBasicFixedVersion>
<MicrosoftCodeAnalysisVisualBasicWorkspacesFixedVersion>$(CodeStyleLayerCodeAnalysisVersion)</MicrosoftCodeAnalysisVisualBasicWorkspacesFixedVersion>
</PropertyGroup>
<!--
......
......@@ -8,16 +8,17 @@
<RootNamespace>Microsoft.CodeAnalysis.CSharp</RootNamespace>
<TargetFramework>netstandard1.3</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpFixedVersion)" />
</ItemGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
<ProjectReference Include="..\..\..\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj" />
<ProjectReference Include="..\..\Core\Analyzers\Microsoft.CodeAnalysis.CodeStyle.csproj" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
<ItemGroup>
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.CodeStyle.Tests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.CodeStyle.UnitTests" />
</ItemGroup>
<ItemGroup>
<Compile Update="CSharpCodeStyleResources.Designer.cs">
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.CodeStyle
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class CSharpFormattingAnalyzer : AbstractFormattingAnalyzer
{
protected override Type GetAnalyzerImplType()
{
// Explained at the call site in the base class
return typeof(CSharpFormattingAnalyzerImpl);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.CodingConventions;
namespace Microsoft.CodeAnalysis.CodeStyle
{
internal class CSharpFormattingAnalyzerImpl : AbstractFormattingAnalyzerImpl
{
private readonly EditorConfigOptionsApplier _editorConfigOptionsApplier = new EditorConfigOptionsApplier();
public CSharpFormattingAnalyzerImpl(DiagnosticDescriptor descriptor)
: base(descriptor)
{
}
protected override OptionSet ApplyFormattingOptions(OptionSet optionSet, ICodingConventionContext codingConventionContext)
{
return _editorConfigOptionsApplier.ApplyConventions(optionSet, codingConventionContext.CurrentConventions, LanguageNames.CSharp);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.CodingConventions;
namespace Microsoft.CodeAnalysis.CodeStyle
{
[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.FixFormatting)]
[Shared]
internal class CSharpFormattingCodeFixProvider : AbstractFormattingCodeFixProvider
{
private readonly EditorConfigOptionsApplier _editorConfigOptionsApplier = new EditorConfigOptionsApplier();
protected override OptionSet ApplyFormattingOptions(OptionSet optionSet, ICodingConventionContext codingConventionContext)
{
return _editorConfigOptionsApplier.ApplyConventions(optionSet, codingConventionContext.CurrentConventions, LanguageNames.CSharp);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.CodingConventions;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.CodingConventions;
namespace Microsoft.CodeAnalysis.Tools.Options
namespace Microsoft.CodeAnalysis.CodeStyle
{
internal class EditorConfigOptionsApplier
{
......
......@@ -6,7 +6,8 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis.CSharp</RootNamespace>
<TargetFramework>netstandard1.3</TargetFramework>
<TargetFramework>net46</TargetFramework>
<CopyLocalLockFileDependencies>true</CopyLocalLockFileDependencies>
<!-- NuGet -->
<IsPackable>true</IsPackable>
......@@ -29,14 +30,27 @@
<_File Include="$(ArtifactsConfigurationDir)Dlls\Microsoft.CodeAnalysis.CodeStyle\**\Microsoft.CodeAnalysis.CodeStyle.resources.dll"/>
<_File Include="$(ArtifactsConfigurationDir)Dlls\Microsoft.CodeAnalysis.CodeStyle.Fixes\**\Microsoft.CodeAnalysis.CodeStyle.Fixes.resources.dll"/>
<!-- Workspace layer dependencies -->
<_WorkspaceFile Include="$(ArtifactsConfigurationDir)Dlls\Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes\Microsoft.VisualStudio.CodingConventions.dll"/>
<_WorkspaceFile Include="$(ArtifactsConfigurationDir)Dlls\Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes\Microsoft.CodeAnalysis.Workspaces.dll"/>
<_WorkspaceFile Include="$(ArtifactsConfigurationDir)Dlls\Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes\**\Microsoft.CodeAnalysis.Workspaces.resources.dll"/>
<_WorkspaceFile Include="$(ArtifactsConfigurationDir)Dlls\Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes\Microsoft.CodeAnalysis.CSharp.Workspaces.dll"/>
<_WorkspaceFile Include="$(ArtifactsConfigurationDir)Dlls\Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes\**\Microsoft.CodeAnalysis.CSharp.Workspaces.resources.dll"/>
<!-- .NET Standard dependencies of the workspace layer -->
<_File Include="$(ArtifactsConfigurationDir)Dlls\Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes\System.Composition.AttributedModel.dll"/>
<_File Include="$(ArtifactsConfigurationDir)Dlls\Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes\System.Composition.Hosting.dll"/>
<_File Include="$(ArtifactsConfigurationDir)Dlls\Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes\System.Composition.Runtime.dll"/>
<_File Include="$(ArtifactsConfigurationDir)Dlls\Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes\System.Composition.TypedParts.dll"/>
<TfmSpecificPackageFile Include="@(_File)" PackagePath="analyzers/dotnet/cs/%(_File.RecursiveDir)%(_File.FileName)%(_File.Extension)" />
<TfmSpecificPackageFile Include="@(_WorkspaceFile)" PackagePath="analyzers/dotnet/workspace/%(_WorkspaceFile.RecursiveDir)%(_WorkspaceFile.FileName)%(_WorkspaceFile.Extension)" />
</ItemGroup>
</Target>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisCSharpWorkspacesFixedVersion)" />
</ItemGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
<ProjectReference Include="..\..\..\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj" />
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
<ProjectReference Include="..\..\..\Workspaces\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.Workspaces.csproj" />
<ProjectReference Include="..\..\Core\Analyzers\Microsoft.CodeAnalysis.CodeStyle.csproj" />
<ProjectReference Include="..\..\Core\CodeFixes\Microsoft.CodeAnalysis.CodeStyle.Fixes.csproj" />
<ProjectReference Include="..\Analyzers\Microsoft.CodeAnalysis.CSharp.CodeStyle.csproj" />
......@@ -44,7 +58,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
<ItemGroup>
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.CodeStyle.Tests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.CodeStyle.UnitTests" />
</ItemGroup>
<ItemGroup>
<Compile Update="CSharpCodeStyleFixesResources.Designer.cs">
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using Xunit;
namespace Microsoft.CodeAnalysis.CodeStyle
{
using Verify = CSharpCodeFixVerifier<CSharpFormattingAnalyzer, CSharpFormattingCodeFixProvider, XUnitVerifier>;
public class FormattingAnalyzerTests
{
[Fact]
public async Task TestAlreadyFormatted()
{
var testCode = @"
class MyClass
{
void MyMethod()
{
}
}
";
await Verify.VerifyAnalyzerAsync(testCode);
}
[Fact]
public async Task TestNeedsIndentation()
{
var testCode = @"
class MyClass
{
$$void MyMethod()
$${
$$}
}
";
var fixedCode = @"
class MyClass
{
void MyMethod()
{
}
}
";
await Verify.VerifyCodeFixAsync(testCode, fixedCode);
}
[Fact]
public async Task TestWhitespaceBetweenMethods1()
{
var testCode = @"
class MyClass
{
void MyMethod1()
{
}
[| |]
void MyMethod2()
{
}
}
";
var fixedCode = @"
class MyClass
{
void MyMethod1()
{
}
void MyMethod2()
{
}
}
";
await Verify.VerifyCodeFixAsync(testCode, fixedCode);
}
[Fact]
public async Task TestWhitespaceBetweenMethods2()
{
var testCode = @"
class MyClass
{
void MyMethod1()
{
}[| |]
void MyMethod2()
{
}
}
";
var fixedCode = @"
class MyClass
{
void MyMethod1()
{
}
void MyMethod2()
{
}
}
";
await Verify.VerifyCodeFixAsync(testCode, fixedCode);
}
[Fact]
public async Task TestWhitespaceBetweenMethods3()
{
// This example has trailing whitespace on both lines preceding MyMethod2
var testCode = @"
class MyClass
{
void MyMethod1()
{
}[|
|]void MyMethod2()
{
}
}
";
var fixedCode = @"
class MyClass
{
void MyMethod1()
{
}
void MyMethod2()
{
}
}
";
await Verify.VerifyCodeFixAsync(testCode, fixedCode);
}
[Fact]
public async Task TestOverIndentation()
{
var testCode = @"
class MyClass
{
[| |]void MyMethod()
[| |]{
[| |]}
}
";
var fixedCode = @"
class MyClass
{
void MyMethod()
{
}
}
";
await Verify.VerifyCodeFixAsync(testCode, fixedCode);
}
[Fact]
public async Task TestIncrementalFixesFullLine()
{
var testCode = @"
class MyClass
{
int Property1$${$$get;$$set;$$}
int Property2$${$$get;$$}
}
";
var fixedCode = @"
class MyClass
{
int Property1 { get; set; }
int Property2 { get; }
}
";
await new CSharpCodeFixTest<CSharpFormattingAnalyzer, CSharpFormattingCodeFixProvider, XUnitVerifier>
{
TestCode = testCode,
FixedCode = fixedCode,
// Each application of a single code fix covers all diagnostics on the same line. In total, two lines
// require changes so the number of incremental iterations is exactly 2.
NumberOfIncrementalIterations = 2,
}.RunAsync();
}
[Fact]
public async Task TestEditorConfigUsed()
{
var testCode = @"
class MyClass {
void MyMethod()[| |]{
}
}
";
var fixedCode = @"
class MyClass {
void MyMethod()
{
}
}
";
var editorConfig = @"
root = true
[*.cs]
csharp_new_line_before_open_brace = methods
";
var testDirectoryName = Path.GetRandomFileName();
Directory.CreateDirectory(testDirectoryName);
try
{
File.WriteAllText(Path.Combine(testDirectoryName, ".editorconfig"), editorConfig);
// The contents of this file are ignored, but the coding conventions library checks for existence before
// .editorconfig is used.
File.WriteAllText(Path.Combine(testDirectoryName, "Test0.cs"), string.Empty);
await new CSharpCodeFixTest<CSharpFormattingAnalyzer, CSharpFormattingCodeFixProvider, XUnitVerifier>
{
TestState = { Sources = { (Path.GetFullPath(Path.Combine(testDirectoryName, "Test0.cs")), testCode) } },
FixedState = { Sources = { (Path.GetFullPath(Path.Combine(testDirectoryName, "Test0.cs")), fixedCode) } },
}.RunAsync();
}
finally
{
Directory.Delete(testDirectoryName, true);
}
}
}
}
......@@ -6,14 +6,14 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis.CSharp</RootNamespace>
<TargetFrameworks>$(RoslynPortableTargetFrameworks)</TargetFrameworks>
<RoslynProjectType>UnitTestPortable</RoslynProjectType>
<TargetFramework>net46</TargetFramework>
<RoslynProjectType>UnitTest</RoslynProjectType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisCSharpWorkspacesFixedVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="$(MicrosoftCodeAnalysisCSharpCodeFixTestingXUnitVersion)" />
</ItemGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
<ProjectReference Include="..\..\..\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj" />
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
<ProjectReference Include="..\..\..\Workspaces\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.Workspaces.csproj" />
<ProjectReference Include="..\..\Core\Analyzers\Microsoft.CodeAnalysis.CodeStyle.csproj" />
<ProjectReference Include="..\..\Core\CodeFixes\Microsoft.CodeAnalysis.CodeStyle.Fixes.csproj" />
<ProjectReference Include="..\Analyzers\Microsoft.CodeAnalysis.CSharp.CodeStyle.csproj" />
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.Diagnostics;
......@@ -8,7 +7,7 @@
namespace Microsoft.CodeAnalysis.CodeStyle
{
internal abstract class AbstractCodeStyleDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer
internal abstract class AbstractCodeStyleDiagnosticAnalyzer : DiagnosticAnalyzer
{
protected readonly string DescriptorId;
......@@ -79,7 +78,7 @@ protected DiagnosticDescriptor CreateDescriptorWithTitle(LocalizableString title
{
if (!_configurable)
{
customTags = customTags.Concat(WellKnownDiagnosticTags.NotConfigurable).ToArray();
customTags = customTags.Concat(new[] { WellKnownDiagnosticTags.NotConfigurable }).ToArray();
}
return new DiagnosticDescriptor(
......@@ -100,8 +99,5 @@ public sealed override void Initialize(AnalysisContext context)
}
protected abstract void InitializeWorker(AnalysisContext context);
public abstract DiagnosticAnalyzerCategory GetAnalyzerCategory();
public abstract bool OpenFileOnly(Workspace workspace);
}
}
......@@ -20,7 +20,7 @@ namespace Microsoft.CodeAnalysis {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class CodeStyleResources {
......@@ -62,11 +62,20 @@ internal class CodeStyleResources {
}
/// <summary>
/// Looks up a localized string similar to Remove this value when another is added..
/// Looks up a localized string similar to Fix formatting.
/// </summary>
internal static string EmptyResource {
internal static string Fix_formatting {
get {
return ResourceManager.GetString("EmptyResource", resourceCulture);
return ResourceManager.GetString("Fix_formatting", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Style.
/// </summary>
internal static string Style {
get {
return ResourceManager.GetString("Style", resourceCulture);
}
}
}
......
......@@ -117,8 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="EmptyResource" xml:space="preserve">
<value>Remove this value when another is added.</value>
<comment>https://github.com/Microsoft/msbuild/issues/1661</comment>
<data name="Fix_formatting" xml:space="preserve">
<value>Fix formatting</value>
</data>
<data name="Style" xml:space="preserve">
<value>Style</value>
</data>
</root>
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.CodeStyle
{
internal static class DiagnosticCategory
{
public static readonly string Style = CodeStyleResources.Style;
}
}
......@@ -8,8 +8,8 @@
<RootNamespace>Microsoft.CodeAnalysis</RootNamespace>
<TargetFramework>netstandard1.3</TargetFramework>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisCommonFixedVersion)" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
......@@ -19,9 +19,13 @@
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle.Fixes" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CodeStyle.Tests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.CodeStyle.Tests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle.Tests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CodeStyle.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.CodeStyle.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle.UnitTests" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\Features\Core\Portable\Diagnostics\Analyzers\IDEDiagnosticIds.cs" Link="IDEDiagnosticIds.cs" />
<Compile Include="..\..\..\Features\Core\Portable\Diagnostics\DiagnosticCustomTags.cs" Link="DiagnosticCustomTags.cs" />
</ItemGroup>
<ItemGroup>
<Compile Update="CodeStyleResources.Designer.cs">
......
......@@ -2,10 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../CodeStyleResources.resx">
<body>
<trans-unit id="EmptyResource">
<source>Remove this value when another is added.</source>
<target state="translated">Odebrat tuto hodnotu, když se přidá jiná</target>
<note>https://github.com/Microsoft/msbuild/issues/1661</note>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Style">
<source>Style</source>
<target state="new">Style</target>
<note />
</trans-unit>
</body>
</file>
......
......@@ -2,10 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="de" original="../CodeStyleResources.resx">
<body>
<trans-unit id="EmptyResource">
<source>Remove this value when another is added.</source>
<target state="translated">Dieser Wert wird entfernt, wenn ein anderer hinzugefügt wird.</target>
<note>https://github.com/Microsoft/msbuild/issues/1661</note>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Style">
<source>Style</source>
<target state="new">Style</target>
<note />
</trans-unit>
</body>
</file>
......
......@@ -2,10 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="es" original="../CodeStyleResources.resx">
<body>
<trans-unit id="EmptyResource">
<source>Remove this value when another is added.</source>
<target state="translated">Quite este valor cuando se agregue otro.</target>
<note>https://github.com/Microsoft/msbuild/issues/1661</note>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Style">
<source>Style</source>
<target state="new">Style</target>
<note />
</trans-unit>
</body>
</file>
......
......@@ -2,10 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="fr" original="../CodeStyleResources.resx">
<body>
<trans-unit id="EmptyResource">
<source>Remove this value when another is added.</source>
<target state="translated">Supprimer cette valeur quand une autre est ajoutée.</target>
<note>https://github.com/Microsoft/msbuild/issues/1661</note>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Style">
<source>Style</source>
<target state="new">Style</target>
<note />
</trans-unit>
</body>
</file>
......
......@@ -2,10 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="it" original="../CodeStyleResources.resx">
<body>
<trans-unit id="EmptyResource">
<source>Remove this value when another is added.</source>
<target state="translated">Rimuovere questo valore quando ne viene aggiunto un altro.</target>
<note>https://github.com/Microsoft/msbuild/issues/1661</note>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Style">
<source>Style</source>
<target state="new">Style</target>
<note />
</trans-unit>
</body>
</file>
......
......@@ -2,10 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ja" original="../CodeStyleResources.resx">
<body>
<trans-unit id="EmptyResource">
<source>Remove this value when another is added.</source>
<target state="translated">別の値が追加されたら、この値を削除します。</target>
<note>https://github.com/Microsoft/msbuild/issues/1661</note>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Style">
<source>Style</source>
<target state="new">Style</target>
<note />
</trans-unit>
</body>
</file>
......
......@@ -2,10 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ko" original="../CodeStyleResources.resx">
<body>
<trans-unit id="EmptyResource">
<source>Remove this value when another is added.</source>
<target state="translated">다른 값을 추가할 때 이 값을 제거하세요.</target>
<note>https://github.com/Microsoft/msbuild/issues/1661</note>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Style">
<source>Style</source>
<target state="new">Style</target>
<note />
</trans-unit>
</body>
</file>
......
......@@ -2,10 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pl" original="../CodeStyleResources.resx">
<body>
<trans-unit id="EmptyResource">
<source>Remove this value when another is added.</source>
<target state="translated">Usuń tę wartość, gdy dodawana jest kolejna.</target>
<note>https://github.com/Microsoft/msbuild/issues/1661</note>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Style">
<source>Style</source>
<target state="new">Style</target>
<note />
</trans-unit>
</body>
</file>
......
......@@ -2,10 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pt-BR" original="../CodeStyleResources.resx">
<body>
<trans-unit id="EmptyResource">
<source>Remove this value when another is added.</source>
<target state="translated">Remover este valor quando outro for adicionado.</target>
<note>https://github.com/Microsoft/msbuild/issues/1661</note>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Style">
<source>Style</source>
<target state="new">Style</target>
<note />
</trans-unit>
</body>
</file>
......
......@@ -2,10 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ru" original="../CodeStyleResources.resx">
<body>
<trans-unit id="EmptyResource">
<source>Remove this value when another is added.</source>
<target state="translated">Удалите это значение при добавлении другого значения.</target>
<note>https://github.com/Microsoft/msbuild/issues/1661</note>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Style">
<source>Style</source>
<target state="new">Style</target>
<note />
</trans-unit>
</body>
</file>
......
......@@ -2,10 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="tr" original="../CodeStyleResources.resx">
<body>
<trans-unit id="EmptyResource">
<source>Remove this value when another is added.</source>
<target state="translated">Başka bir değer eklendiğinde bu değeri kaldırın.</target>
<note>https://github.com/Microsoft/msbuild/issues/1661</note>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Style">
<source>Style</source>
<target state="new">Style</target>
<note />
</trans-unit>
</body>
</file>
......
......@@ -2,10 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-Hans" original="../CodeStyleResources.resx">
<body>
<trans-unit id="EmptyResource">
<source>Remove this value when another is added.</source>
<target state="translated">在添加其他值时删除此值。</target>
<note>https://github.com/Microsoft/msbuild/issues/1661</note>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Style">
<source>Style</source>
<target state="new">Style</target>
<note />
</trans-unit>
</body>
</file>
......
......@@ -2,10 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-Hant" original="../CodeStyleResources.resx">
<body>
<trans-unit id="EmptyResource">
<source>Remove this value when another is added.</source>
<target state="translated">當新增另一個值時移除此值。</target>
<note>https://github.com/Microsoft/msbuild/issues/1661</note>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Style">
<source>Style</source>
<target state="new">Style</target>
<note />
</trans-unit>
</body>
</file>
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.IO;
using System.Reflection;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.CodeStyle
{
/// <summary>
/// This analyzer implements <see cref="DiagnosticAnalyzer"/>, but wraps the true formatting analyzer
/// implementations. Since the compiler doesn't provide the use of workspace-layer APIs for analyzers, we need to
/// provide our own copy of the workspace assemblies and load them using reflection if they are not already loaded
/// in the current process.
/// </summary>
internal abstract class AbstractFormattingAnalyzer
: AbstractCodeStyleDiagnosticAnalyzer
{
static AbstractFormattingAnalyzer()
{
AppDomain.CurrentDomain.AssemblyResolve += HandleAssemblyResolve;
}
protected AbstractFormattingAnalyzer()
: base(
IDEDiagnosticIds.FormattingDiagnosticId,
new LocalizableResourceString(nameof(CodeStyleResources.Fix_formatting), CodeStyleResources.ResourceManager, typeof(CodeStyleResources)),
new LocalizableResourceString(nameof(CodeStyleResources.Fix_formatting), CodeStyleResources.ResourceManager, typeof(CodeStyleResources)))
{
}
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
=> ImmutableArray.Create(Descriptor);
protected abstract Type GetAnalyzerImplType();
protected override void InitializeWorker(AnalysisContext context)
{
// Create an instance of the true formatting analyzer (which depends on workspace-layer APIs) only after the
// custom assembly resolver is in place to provide the assemblies if necessary.
var analyzer = (AbstractFormattingAnalyzerImpl)Activator.CreateInstance(GetAnalyzerImplType(), Descriptor);
analyzer.InitializeWorker(context);
}
private static Assembly HandleAssemblyResolve(object sender, ResolveEventArgs args)
{
switch (new AssemblyName(args.Name).Name)
{
case "Microsoft.CodeAnalysis.Workspaces":
case "Microsoft.CodeAnalysis.CSharp.Workspaces":
case "Microsoft.VisualStudio.CodingConventions":
var result = Assembly.LoadFrom(Path.Combine(Path.GetDirectoryName(typeof(AbstractFormattingAnalyzer).Assembly.Location), "..\\workspaces", new AssemblyName(args.Name).Name + ".dll"));
return result;
default:
return null;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.CodingConventions;
namespace Microsoft.CodeAnalysis.CodeStyle
{
internal abstract class AbstractFormattingAnalyzerImpl
{
private readonly DiagnosticDescriptor _descriptor;
protected AbstractFormattingAnalyzerImpl(DiagnosticDescriptor descriptor)
{
_descriptor = descriptor;
}
internal void InitializeWorker(AnalysisContext context)
{
var workspace = new AdhocWorkspace();
var codingConventionsManager = CodingConventionsManagerFactory.CreateCodingConventionsManager();
context.RegisterSyntaxTreeAction(c => AnalyzeSyntaxTree(c, workspace, codingConventionsManager));
}
protected abstract OptionSet ApplyFormattingOptions(OptionSet optionSet, ICodingConventionContext codingConventionContext);
private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context, Workspace workspace, ICodingConventionsManager codingConventionsManager)
{
var tree = context.Tree;
var cancellationToken = context.CancellationToken;
var options = workspace.Options;
if (File.Exists(tree.FilePath))
{
var codingConventionContext = codingConventionsManager.GetConventionContextAsync(tree.FilePath, cancellationToken).GetAwaiter().GetResult();
options = ApplyFormattingOptions(options, codingConventionContext);
}
FormattingAnalyzerHelper.AnalyzeSyntaxTree(context, _descriptor, workspace, options);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
namespace Microsoft.CodeAnalysis.CodeStyle
{
/// <summary>
/// Provides a base class to write a <see cref="FixAllProvider"/> that fixes documents independently.
/// </summary>
internal abstract class DocumentBasedFixAllProvider : FixAllProvider
{
protected abstract string CodeActionTitle
{
get;
}
public override Task<CodeAction> GetFixAsync(FixAllContext fixAllContext)
{
CodeAction fixAction;
switch (fixAllContext.Scope)
{
case FixAllScope.Document:
fixAction = CodeAction.Create(
CodeActionTitle,
cancellationToken => GetDocumentFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)),
nameof(DocumentBasedFixAllProvider));
break;
case FixAllScope.Project:
fixAction = CodeAction.Create(
CodeActionTitle,
cancellationToken => GetProjectFixesAsync(fixAllContext.WithCancellationToken(cancellationToken), fixAllContext.Project),
nameof(DocumentBasedFixAllProvider));
break;
case FixAllScope.Solution:
fixAction = CodeAction.Create(
CodeActionTitle,
cancellationToken => GetSolutionFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)),
nameof(DocumentBasedFixAllProvider));
break;
case FixAllScope.Custom:
default:
fixAction = null;
break;
}
return Task.FromResult(fixAction);
}
/// <summary>
/// Fixes all occurrences of a diagnostic in a specific document.
/// </summary>
/// <param name="fixAllContext">The context for the Fix All operation.</param>
/// <param name="document">The document to fix.</param>
/// <param name="diagnostics">The diagnostics to fix in the document.</param>
/// <returns>
/// <para>The new <see cref="SyntaxNode"/> representing the root of the fixed document.</para>
/// <para>-or-</para>
/// <para><see langword="null"/>, if no changes were made to the document.</para>
/// </returns>
protected abstract Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fixAllContext, Document document, ImmutableArray<Diagnostic> diagnostics);
private async Task<Document> GetDocumentFixesAsync(FixAllContext fixAllContext)
{
var documentDiagnosticsToFix = await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(fixAllContext, progressTrackerOpt: null, (document, cancellationToken) => false).ConfigureAwait(false);
if (!documentDiagnosticsToFix.TryGetValue(fixAllContext.Document, out var diagnostics))
{
return fixAllContext.Document;
}
var newRoot = await FixAllInDocumentAsync(fixAllContext, fixAllContext.Document, diagnostics).ConfigureAwait(false);
if (newRoot == null)
{
return fixAllContext.Document;
}
return fixAllContext.Document.WithSyntaxRoot(newRoot);
}
private async Task<Solution> GetSolutionFixesAsync(FixAllContext fixAllContext, ImmutableArray<Document> documents)
{
var documentDiagnosticsToFix = await FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(fixAllContext, progressTrackerOpt: null, (document, cancellationToken) => false).ConfigureAwait(false);
var solution = fixAllContext.Solution;
var newDocuments = new List<Task<SyntaxNode>>(documents.Length);
foreach (var document in documents)
{
if (!documentDiagnosticsToFix.TryGetValue(document, out var diagnostics))
{
newDocuments.Add(document.GetSyntaxRootAsync(fixAllContext.CancellationToken));
continue;
}
newDocuments.Add(FixAllInDocumentAsync(fixAllContext, document, diagnostics));
}
for (var i = 0; i < documents.Length; i++)
{
var newDocumentRoot = await newDocuments[i].ConfigureAwait(false);
if (newDocumentRoot == null)
{
continue;
}
solution = solution.WithDocumentSyntaxRoot(documents[i].Id, newDocumentRoot);
}
return solution;
}
private Task<Solution> GetProjectFixesAsync(FixAllContext fixAllContext, Project project)
{
return GetSolutionFixesAsync(fixAllContext, project.Documents.ToImmutableArray());
}
private Task<Solution> GetSolutionFixesAsync(FixAllContext fixAllContext)
{
var documents = fixAllContext.Solution.Projects.SelectMany(i => i.Documents).ToImmutableArray();
return GetSolutionFixesAsync(fixAllContext, documents);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Concurrent;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Shared.Utilities;
namespace Microsoft.CodeAnalysis.CodeStyle
{
internal static class FixAllContextHelper
{
public static async Task<ImmutableDictionary<Document, ImmutableArray<Diagnostic>>> GetDocumentDiagnosticsToFixAsync(
FixAllContext fixAllContext,
IProgressTracker progressTrackerOpt,
Func<Document, CancellationToken, bool> isGeneratedCode)
{
var cancellationToken = fixAllContext.CancellationToken;
var allDiagnostics = ImmutableArray<Diagnostic>.Empty;
var projectsToFix = ImmutableArray<Project>.Empty;
var document = fixAllContext.Document;
var project = fixAllContext.Project;
switch (fixAllContext.Scope)
{
case FixAllScope.Document:
if (document != null && !isGeneratedCode(document, cancellationToken))
{
var documentDiagnostics = await fixAllContext.GetDocumentDiagnosticsAsync(document).ConfigureAwait(false);
return ImmutableDictionary<Document, ImmutableArray<Diagnostic>>.Empty.SetItem(document, documentDiagnostics);
}
break;
case FixAllScope.Project:
projectsToFix = ImmutableArray.Create(project);
allDiagnostics = await fixAllContext.GetAllDiagnosticsAsync(project).ConfigureAwait(false);
break;
case FixAllScope.Solution:
projectsToFix = project.Solution.Projects
.Where(p => p.Language == project.Language)
.ToImmutableArray();
progressTrackerOpt?.AddItems(projectsToFix.Length);
var diagnostics = new ConcurrentDictionary<ProjectId, ImmutableArray<Diagnostic>>();
var tasks = new Task[projectsToFix.Length];
for (var i = 0; i < projectsToFix.Length; i++)
{
cancellationToken.ThrowIfCancellationRequested();
var projectToFix = projectsToFix[i];
tasks[i] = Task.Run(async () =>
{
var projectDiagnostics = await fixAllContext.GetAllDiagnosticsAsync(projectToFix).ConfigureAwait(false);
diagnostics.TryAdd(projectToFix.Id, projectDiagnostics);
progressTrackerOpt?.ItemCompleted();
}, cancellationToken);
}
await Task.WhenAll(tasks).ConfigureAwait(false);
allDiagnostics = allDiagnostics.AddRange(diagnostics.SelectMany(i => i.Value));
break;
}
if (allDiagnostics.IsEmpty)
{
return ImmutableDictionary<Document, ImmutableArray<Diagnostic>>.Empty;
}
return await GetDocumentDiagnosticsToFixAsync(
allDiagnostics, projectsToFix, fixAllContext.CancellationToken).ConfigureAwait(false);
}
private static async Task<ImmutableDictionary<Document, ImmutableArray<Diagnostic>>> GetDocumentDiagnosticsToFixAsync(
ImmutableArray<Diagnostic> diagnostics,
ImmutableArray<Project> projects,
CancellationToken cancellationToken)
{
var treeToDocumentMap = await GetTreeToDocumentMapAsync(projects, cancellationToken).ConfigureAwait(false);
var builder = ImmutableDictionary.CreateBuilder<Document, ImmutableArray<Diagnostic>>();
foreach (var documentAndDiagnostics in diagnostics.GroupBy(d => GetReportedDocument(d, treeToDocumentMap)))
{
cancellationToken.ThrowIfCancellationRequested();
var document = documentAndDiagnostics.Key;
var diagnosticsForDocument = documentAndDiagnostics.ToImmutableArray();
builder.Add(document, diagnosticsForDocument);
}
return builder.ToImmutable();
}
private static async Task<ImmutableDictionary<SyntaxTree, Document>> GetTreeToDocumentMapAsync(ImmutableArray<Project> projects, CancellationToken cancellationToken)
{
var builder = ImmutableDictionary.CreateBuilder<SyntaxTree, Document>();
foreach (var project in projects)
{
cancellationToken.ThrowIfCancellationRequested();
foreach (var document in project.Documents)
{
cancellationToken.ThrowIfCancellationRequested();
var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
builder.Add(tree, document);
}
}
return builder.ToImmutable();
}
private static Document GetReportedDocument(Diagnostic diagnostic, ImmutableDictionary<SyntaxTree, Document> treeToDocumentsMap)
{
var tree = diagnostic.Location.SourceTree;
if (tree != null)
{
Document document;
if (treeToDocumentsMap.TryGetValue(tree, out document))
{
return document;
}
}
return null;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.CodeStyle
{
internal static class FormattingAnalyzerHelper
{
internal static void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context, DiagnosticDescriptor descriptor, Workspace workspace, OptionSet options)
{
var tree = context.Tree;
var cancellationToken = context.CancellationToken;
var oldText = tree.GetText(cancellationToken);
var formattingChanges = Formatter.GetFormattedTextChanges(tree.GetRoot(cancellationToken), workspace, options, cancellationToken);
// formattingChanges could include changes that impact a larger section of the original document than
// necessary. Before reporting diagnostics, process the changes to minimize the span of individual
// diagnostics.
foreach (var formattingChange in formattingChanges)
{
var change = formattingChange;
if (change.NewText.Length > 0 && !change.Span.IsEmpty)
{
// Handle cases where the change is a substring removal from the beginning. In these cases, we want
// the diagnostic span to cover the unwanted leading characters (which should be removed), and
// nothing more.
var offset = change.Span.Length - change.NewText.Length;
if (offset >= 0)
{
if (oldText.GetSubText(new TextSpan(change.Span.Start + offset, change.NewText.Length)).ContentEquals(SourceText.From(change.NewText)))
{
change = new TextChange(new TextSpan(change.Span.Start, offset), "");
}
else
{
// Handle cases where the change is a substring removal from the end. In these cases, we want
// the diagnostic span to cover the unwanted trailing characters (which should be removed), and
// nothing more.
if (oldText.GetSubText(new TextSpan(change.Span.Start, change.NewText.Length)).ContentEquals(SourceText.From(change.NewText)))
{
change = new TextChange(new TextSpan(change.Span.Start + change.NewText.Length, offset), "");
}
}
}
}
if (change.NewText.Length == 0 && change.Span.IsEmpty)
{
// No actual change (allows for the formatter to report a NOP change without triggering a
// diagnostic that can't be fixed).
continue;
}
var location = Location.Create(tree, change.Span);
context.ReportDiagnostic(Diagnostic.Create(
descriptor,
location,
additionalLocations: null,
properties: null));
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
{
internal static class FormattingCodeFixHelper
{
internal static async Task<Document> FixOneAsync(Document document, OptionSet options, Diagnostic diagnostic, CancellationToken cancellationToken)
{
var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
// The span to format is the full line(s) containing the diagnostic
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
var diagnosticSpan = diagnostic.Location.SourceSpan;
var diagnosticLinePositionSpan = text.Lines.GetLinePositionSpan(diagnosticSpan);
var spanToFormat = TextSpan.FromBounds(
text.Lines[diagnosticLinePositionSpan.Start.Line].Start,
text.Lines[diagnosticLinePositionSpan.End.Line].End);
return await Formatter.FormatAsync(document, spanToFormat, options, cancellationToken).ConfigureAwait(false);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.CodingConventions;
namespace Microsoft.CodeAnalysis.CodeStyle
{
internal abstract class AbstractFormattingCodeFixProvider : CodeFixProvider
{
public sealed override ImmutableArray<string> FixableDiagnosticIds
=> ImmutableArray.Create(IDEDiagnosticIds.FormattingDiagnosticId);
public sealed override FixAllProvider GetFixAllProvider()
{
return new FixAll(this);
}
public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diagnostic in context.Diagnostics)
{
context.RegisterCodeFix(
CodeAction.Create(
CodeStyleResources.Fix_formatting,
c => FixOneAsync(context, diagnostic, c),
nameof(AbstractFormattingCodeFixProvider)),
diagnostic);
}
return Task.CompletedTask;
}
protected abstract OptionSet ApplyFormattingOptions(OptionSet optionSet, ICodingConventionContext codingConventionContext);
private async Task<Document> FixOneAsync(CodeFixContext context, Diagnostic diagnostic, CancellationToken cancellationToken)
{
var options = await GetOptionsAsync(context.Document, cancellationToken).ConfigureAwait(false);
return await FormattingCodeFixHelper.FixOneAsync(context.Document, options, diagnostic, cancellationToken).ConfigureAwait(false);
}
private async Task<OptionSet> GetOptionsAsync(Document document, CancellationToken cancellationToken)
{
OptionSet options = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);
// The in-IDE workspace supports .editorconfig without special handling. However, the AdhocWorkspace used
// in testing requires manual handling of .editorconfig.
if (document.Project.Solution.Workspace is AdhocWorkspace && File.Exists(document.FilePath ?? document.Name))
{
var codingConventionsManager = CodingConventionsManagerFactory.CreateCodingConventionsManager();
var codingConventionContext = await codingConventionsManager.GetConventionContextAsync(document.FilePath ?? document.Name, cancellationToken).ConfigureAwait(false);
options = ApplyFormattingOptions(options, codingConventionContext);
}
return options;
}
/// <summary>
/// Provide an optimized Fix All implementation that runs
/// <see cref="Formatter.FormatAsync(Document, Options.OptionSet, CancellationToken)"/> on the document(s)
/// included in the Fix All scope.
/// </summary>
private class FixAll : DocumentBasedFixAllProvider
{
private readonly AbstractFormattingCodeFixProvider _formattingCodeFixProvider;
public FixAll(AbstractFormattingCodeFixProvider formattingCodeFixProvider)
{
_formattingCodeFixProvider = formattingCodeFixProvider;
}
protected override string CodeActionTitle => CodeStyleResources.Fix_formatting;
protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fixAllContext, Document document, ImmutableArray<Diagnostic> diagnostics)
{
var options = await _formattingCodeFixProvider.GetOptionsAsync(document, fixAllContext.CancellationToken).ConfigureAwait(false);
var updatedDocument = await Formatter.FormatAsync(document, options, fixAllContext.CancellationToken).ConfigureAwait(false);
return await updatedDocument.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false);
}
}
}
}
......@@ -6,11 +6,17 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis</RootNamespace>
<TargetFramework>netstandard1.3</TargetFramework>
<TargetFramework>net46</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\Features\Core\Portable\CodeFixes\PredefinedCodeFixProviderNames.cs" Link="PredefinedCodeFixProviderNames.cs" />
<Compile Include="..\..\..\Workspaces\Core\Portable\Shared\Utilities\IProgressTracker.cs" Link="IProgressTracker.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(MicrosoftCodeAnalysisWorkspacesCommonFixedVersion)" />
<PackageReference Include="Microsoft.VisualStudio.CodingConventions" Version="$(MicrosoftVisualStudioCodingConventionsVersion)" />
</ItemGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
<ProjectReference Include="..\Analyzers\Microsoft.CodeAnalysis.CodeStyle.csproj" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
......@@ -18,9 +24,9 @@
<ItemGroup>
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle.Fixes" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CodeStyle.Tests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.CodeStyle.Tests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle.Tests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CodeStyle.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.CodeStyle.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle.UnitTests" />
</ItemGroup>
<ItemGroup>
<Compile Update="CodeStyleFixesResources.Designer.cs">
......
......@@ -6,12 +6,10 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis</RootNamespace>
<TargetFrameworks>$(RoslynPortableTargetFrameworks)</TargetFrameworks>
<RoslynProjectType>UnitTestPortable</RoslynProjectType>
<TargetFramework>net46</TargetFramework>
<RoslynProjectType>UnitTest</RoslynProjectType>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
<ProjectReference Include="..\Analyzers\Microsoft.CodeAnalysis.CodeStyle.csproj" />
<ProjectReference Include="..\CodeFixes\Microsoft.CodeAnalysis.CodeStyle.Fixes.csproj" />
</ItemGroup>
......
......@@ -8,16 +8,17 @@
<TargetFramework>netstandard1.3</TargetFramework>
<RootNamespace></RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="$(MicrosoftCodeAnalysisVisualBasicFixedVersion)" />
</ItemGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
<ProjectReference Include="..\..\..\Compilers\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj" />
<ProjectReference Include="..\..\Core\Analyzers\Microsoft.CodeAnalysis.CodeStyle.csproj" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
<ItemGroup>
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle.Fixes" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle.Tests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle.UnitTests" />
</ItemGroup>
<ItemGroup>
<Compile Update="VBCodeStyleResources.Designer.vb">
......
......@@ -5,7 +5,7 @@
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
<PlatformTarget>AnyCPU</PlatformTarget>
<OutputType>Library</OutputType>
<TargetFramework>netstandard1.3</TargetFramework>
<TargetFramework>net46</TargetFramework>
<RootNamespace></RootNamespace>
<!-- NuGet -->
......@@ -32,11 +32,10 @@
<TfmSpecificPackageFile Include="@(_File)" PackagePath="analyzers/dotnet/vb/%(_File.RecursiveDir)%(_File.FileName)%(_File.Extension)" />
</ItemGroup>
</Target>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="$(MicrosoftCodeAnalysisVisualBasicWorkspacesFixedVersion)" />
</ItemGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
<ProjectReference Include="..\..\..\Compilers\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj" />
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
<ProjectReference Include="..\..\..\Workspaces\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.Workspaces.vbproj" />
<ProjectReference Include="..\..\Core\Analyzers\Microsoft.CodeAnalysis.CodeStyle.csproj" />
<ProjectReference Include="..\..\Core\CodeFixes\Microsoft.CodeAnalysis.CodeStyle.Fixes.csproj" />
<ProjectReference Include="..\Analyzers\Microsoft.CodeAnalysis.VisualBasic.CodeStyle.vbproj" />
......@@ -44,7 +43,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
<ItemGroup>
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle.Tests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle.UnitTests" />
</ItemGroup>
<ItemGroup>
<Compile Update="VBCodeStyleFixesResources.Designer.vb">
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports Microsoft.CodeAnalysis.Diagnostics
Namespace Microsoft.CodeAnalysis.CodeStyle
<DiagnosticAnalyzer(LanguageNames.VisualBasic)>
Friend Class VisualBasicFormattingAnalyzer
Inherits AbstractFormattingAnalyzer
Protected Overrides Function GetAnalyzerImplType() As Type
' Explained at the call site in the base class
Return GetType(VisualBasicFormattingAnalyzerImpl)
End Function
End Class
End Namespace
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.VisualStudio.CodingConventions
Namespace Microsoft.CodeAnalysis.CodeStyle
Friend Class VisualBasicFormattingAnalyzerImpl
Inherits AbstractFormattingAnalyzerImpl
Public Sub New(descriptor As DiagnosticDescriptor)
MyBase.New(descriptor)
End Sub
Protected Overrides Function ApplyFormattingOptions(optionSet As OptionSet, codingConventionContext As ICodingConventionContext) As OptionSet
Return optionSet
End Function
End Class
End Namespace
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Composition
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.VisualStudio.CodingConventions
Namespace Microsoft.CodeAnalysis.CodeStyle
<ExportCodeFixProvider(LanguageNames.VisualBasic, Name:=PredefinedCodeFixProviderNames.FixFormatting)>
<[Shared]>
Friend Class VisualBasicFormattingCodeFixProvider
Inherits AbstractFormattingCodeFixProvider
Protected Overrides Function ApplyFormattingOptions(optionSet As OptionSet, codingConventionContext As ICodingConventionContext) As OptionSet
Return optionSet
End Function
End Class
End Namespace
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports Xunit
Imports VerifyVB = Microsoft.CodeAnalysis.VisualBasic.Testing.VisualBasicCodeFixVerifier(
Of Microsoft.CodeAnalysis.CodeStyle.VisualBasicFormattingAnalyzer,
Microsoft.CodeAnalysis.CodeStyle.VisualBasicFormattingCodeFixProvider,
Microsoft.CodeAnalysis.Testing.Verifiers.XUnitVerifier)
Namespace Microsoft.CodeAnalysis.CodeStyle
Public Class FormattingAnalyzerTests
<Fact>
Public Async Function TestCaseCorrection() As Task
Dim testCode = "
class TestClass
public Sub MyMethod()
End Sub
end class
"
' Currently the analyzer and code fix rely on Formatter.FormatAsync, which does not normalize the casing of
' keywords in Visual Basic.
Await VerifyVB.VerifyAnalyzerAsync(testCode)
End Function
End Class
End Namespace
......@@ -5,15 +5,15 @@
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
<PlatformTarget>AnyCPU</PlatformTarget>
<OutputType>Library</OutputType>
<TargetFrameworks>$(RoslynPortableTargetFrameworks)</TargetFrameworks>
<RoslynProjectType>UnitTestPortable</RoslynProjectType>
<TargetFramework>net46</TargetFramework>
<RoslynProjectType>UnitTest</RoslynProjectType>
<RootNamespace></RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="$(MicrosoftCodeAnalysisVisualBasicWorkspacesFixedVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.CodeFix.Testing.XUnit" Version="$(MicrosoftCodeAnalysisVisualBasicCodeFixTestingXUnitVersion)" />
</ItemGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
<ProjectReference Include="..\..\..\Compilers\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj" />
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
<ProjectReference Include="..\..\..\Workspaces\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.Workspaces.vbproj" />
<ProjectReference Include="..\..\Core\Analyzers\Microsoft.CodeAnalysis.CodeStyle.csproj" />
<ProjectReference Include="..\..\Core\CodeFixes\Microsoft.CodeAnalysis.CodeStyle.Fixes.csproj" />
<ProjectReference Include="..\Analyzers\Microsoft.CodeAnalysis.VisualBasic.CodeStyle.vbproj" />
......
......@@ -436,13 +436,11 @@ private async Task ExecutePrimaryAnalysisTaskAsync(AnalysisScope analysisScope,
await ProcessCompilationEventsAsync(analysisScope, analysisStateOpt, usingPrePopulatedEventQueue, cancellationToken).ConfigureAwait(false);
#if DEBUG
// If not using pre-populated event queue (batch mode), then verify all symbol end actions were processed.
if (!usingPrePopulatedEventQueue)
{
AnalyzerManager.VerifyAllSymbolEndActionsExecuted();
}
#endif
}
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Formatting
{
public class FormattingAnalyzerTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
{
internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
=> (new FormattingDiagnosticAnalyzer(), new FormattingCodeFixProvider());
[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
public async Task TrailingWhitespace()
{
var testCode =
"class X[| |]" + Environment.NewLine +
"{" + Environment.NewLine +
"}" + Environment.NewLine;
var expected =
"class X" + Environment.NewLine +
"{" + Environment.NewLine +
"}" + Environment.NewLine;
await TestInRegularAndScriptAsync(testCode, expected);
}
[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
public async Task TestMissingSpace()
{
var testCode = @"
class TypeName
{
void Method()
{
if$$(true)return;
}
}
";
var expected = @"
class TypeName
{
void Method()
{
if (true) return;
}
}
";
await TestInRegularAndScriptAsync(testCode, expected);
}
}
}
......@@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Diagnostics.AddBraces
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal sealed class CSharpAddBracesDiagnosticAnalyzer :
AbstractCodeStyleDiagnosticAnalyzer
AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public CSharpAddBracesDiagnosticAnalyzer()
: base(IDEDiagnosticIds.AddBracesDiagnosticId,
......
......@@ -10,7 +10,7 @@
namespace Microsoft.CodeAnalysis.CSharp.Diagnostics.TypeStyle
{
internal abstract partial class CSharpTypeStyleDiagnosticAnalyzerBase :
AbstractCodeStyleDiagnosticAnalyzer
AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
protected abstract CSharpTypeStyleHelper Helper { get; }
......
......@@ -26,7 +26,7 @@ namespace Microsoft.CodeAnalysis.CSharp.InlineDeclaration
///
/// </summary>
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class CSharpInlineDeclarationDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal class CSharpInlineDeclarationDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
private const string CS0165 = nameof(CS0165); // Use of unassigned local variable 's'
......
......@@ -18,7 +18,7 @@ internal static class Constants
}
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class InvokeDelegateWithConditionalAccessAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal class InvokeDelegateWithConditionalAccessAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public InvokeDelegateWithConditionalAccessAnalyzer()
: base(IDEDiagnosticIds.InvokeDelegateWithConditionalAccessId,
......
......@@ -13,7 +13,7 @@
namespace Microsoft.CodeAnalysis.CSharp.RemoveUnreachableCode
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class CSharpRemoveUnreachableCodeDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal class CSharpRemoveUnreachableCodeDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
private const string CS0162 = nameof(CS0162); // Unreachable code detected
......
......@@ -17,7 +17,7 @@
namespace Microsoft.CodeAnalysis.CSharp.UseDeconstruction
{
[DiagnosticAnalyzer(LanguageNames.CSharp), Shared]
internal class CSharpUseDeconstructionDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal class CSharpUseDeconstructionDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public CSharpUseDeconstructionDiagnosticAnalyzer()
: base(IDEDiagnosticIds.UseDeconstructionDiagnosticId,
......
......@@ -10,7 +10,7 @@
namespace Microsoft.CodeAnalysis.CSharp.UseDefaultLiteral
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class CSharpUseDefaultLiteralDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal class CSharpUseDefaultLiteralDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public CSharpUseDefaultLiteralDiagnosticAnalyzer()
: base(IDEDiagnosticIds.UseDefaultLiteralDiagnosticId,
......
......@@ -11,7 +11,7 @@
namespace Microsoft.CodeAnalysis.CSharp.UseExpressionBody
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class UseExpressionBodyDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal class UseExpressionBodyDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public const string FixesError = nameof(FixesError);
......
......@@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.CSharp.UseExpressionBodyForLambda
using static UseExpressionBodyForLambdaHelpers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal sealed class UseExpressionBodyForLambdaDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal sealed class UseExpressionBodyForLambdaDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public const string FixesError = nameof(FixesError);
......
......@@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.CSharp.UseIsNullCheck
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class CSharpUseIsNullCheckForCastAndEqualityOperatorDiagnosticAnalyzer
: AbstractCodeStyleDiagnosticAnalyzer
: AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
private static readonly ImmutableDictionary<string, string> s_properties =
ImmutableDictionary<string, string>.Empty.Add(UseIsNullConstants.Kind, UseIsNullConstants.CastAndEqualityKey);
......
......@@ -38,7 +38,7 @@ namespace Microsoft.CodeAnalysis.CSharp.UseLocalFunction
/// }
/// </summary>
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class CSharpUseLocalFunctionDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal class CSharpUseLocalFunctionDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public override bool OpenFileOnly(Workspace workspace) => false;
......
......@@ -24,7 +24,7 @@ namespace Microsoft.CodeAnalysis.CSharp.UsePatternMatching
///
/// </summary>
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal partial class CSharpAsAndNullCheckDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal partial class CSharpAsAndNullCheckDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public override bool OpenFileOnly(Workspace workspace) => false;
......
......@@ -27,7 +27,7 @@ namespace Microsoft.CodeAnalysis.CSharp.UsePatternMatching
/// }
/// </summary>
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class CSharpIsAndCastCheckDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal class CSharpIsAndCastCheckDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public static readonly CSharpIsAndCastCheckDiagnosticAnalyzer Instance = new CSharpIsAndCastCheckDiagnosticAnalyzer();
......
......@@ -30,7 +30,7 @@ namespace Microsoft.CodeAnalysis.CSharp.UsePatternMatching
// we will re-enable it once the issue is addressed.
// https://devdiv.visualstudio.com/DevDiv/_workitems?id=504089&_a=edit&triage=true
// [DiagnosticAnalyzer(LanguageNames.CSharp), Shared]
internal class CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal class CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
private const string CS0165 = nameof(CS0165); // Use of unassigned local variable 's'
private static readonly SyntaxAnnotation s_referenceAnnotation = new SyntaxAnnotation();
......
......@@ -6,7 +6,7 @@
namespace Microsoft.CodeAnalysis.RemoveUnnecessaryParentheses
{
internal abstract class AbstractParenthesesDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal abstract class AbstractParenthesesDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
protected AbstractParenthesesDiagnosticAnalyzer(
string descriptorId, LocalizableString title, LocalizableString message)
......
......@@ -9,7 +9,7 @@
namespace Microsoft.CodeAnalysis.AddAccessibilityModifiers
{
internal abstract class AbstractAddAccessibilityModifiersDiagnosticAnalyzer<TCompilationUnitSyntax>
: AbstractCodeStyleDiagnosticAnalyzer
: AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TCompilationUnitSyntax : SyntaxNode
{
protected AbstractAddAccessibilityModifiersDiagnosticAnalyzer()
......
......@@ -21,6 +21,7 @@ internal static class PredefinedCodeFixProviderNames
public const string AddMissingReference = nameof(AddMissingReference);
public const string AddImport = nameof(AddImport);
public const string FullyQualify = nameof(FullyQualify);
public const string FixFormatting = nameof(FixFormatting);
public const string FixIncorrectFunctionReturnType = nameof(FixIncorrectFunctionReturnType);
public const string FixIncorrectExitContinue = nameof(FixIncorrectExitContinue);
public const string GenerateConstructor = nameof(GenerateConstructor);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.CodeStyle
{
internal abstract class AbstractBuiltInCodeStyleDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer, IBuiltInAnalyzer
{
protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(
string descriptorId, LocalizableString title,
LocalizableString messageFormat = null,
bool configurable = true)
: base(descriptorId, title, messageFormat, configurable)
{
}
public abstract DiagnosticAnalyzerCategory GetAnalyzerCategory();
public abstract bool OpenFileOnly(Workspace workspace);
}
}
......@@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.ConvertAnonymousTypeToTuple
internal abstract class AbstractConvertAnonymousTypeToTupleDiagnosticAnalyzer<
TSyntaxKind,
TAnonymousObjectCreationExpressionSyntax>
: AbstractCodeStyleDiagnosticAnalyzer
: AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TSyntaxKind : struct
where TAnonymousObjectCreationExpressionSyntax : SyntaxNode
{
......
......@@ -84,6 +84,8 @@ internal static class IDEDiagnosticIds
public const string UseExpressionBodyForLambdaExpressionsDiagnosticId = "IDE0053";
public const string FormattingDiagnosticId = "IDE0054";
// Analyzer error Ids
public const string AnalyzerChangedId = "IDE1001";
public const string AnalyzerDependencyConflictId = "IDE1002";
......
......@@ -14,7 +14,7 @@
namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles
{
internal abstract class NamingStyleDiagnosticAnalyzerBase<TLanguageKindEnum> :
AbstractCodeStyleDiagnosticAnalyzer where TLanguageKindEnum : struct
AbstractBuiltInCodeStyleDiagnosticAnalyzer where TLanguageKindEnum : struct
{
private static readonly LocalizableString s_localizableMessageFormat = new LocalizableResourceString(nameof(FeaturesResources.Naming_rule_violation_0), FeaturesResources.ResourceManager, typeof(FeaturesResources));
private static readonly LocalizableString s_localizableTitleNamingStyle = new LocalizableResourceString(nameof(FeaturesResources.Naming_Styles), FeaturesResources.ResourceManager, typeof(FeaturesResources));
......
......@@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Diagnostics.RemoveUnnecessaryCast
{
internal abstract class RemoveUnnecessaryCastDiagnosticAnalyzerBase<
TLanguageKindEnum,
TCastExpression> : AbstractCodeStyleDiagnosticAnalyzer
TCastExpression> : AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TLanguageKindEnum : struct
where TCastExpression : SyntaxNode
{
......
......@@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.Features.EmbeddedLanguages
{
internal abstract class AbstractEmbeddedLanguageDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer
{
private readonly ImmutableArray<AbstractCodeStyleDiagnosticAnalyzer> _analyzers;
private readonly ImmutableArray<AbstractBuiltInCodeStyleDiagnosticAnalyzer> _analyzers;
private readonly DiagnosticAnalyzerCategory _category;
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
......@@ -22,7 +22,7 @@ internal abstract class AbstractEmbeddedLanguageDiagnosticAnalyzer : DiagnosticA
{
var supportedDiagnostics = ArrayBuilder<DiagnosticDescriptor>.GetInstance();
var analyzers = ArrayBuilder<AbstractCodeStyleDiagnosticAnalyzer>.GetInstance();
var analyzers = ArrayBuilder<AbstractBuiltInCodeStyleDiagnosticAnalyzer>.GetInstance();
var category = default(DiagnosticAnalyzerCategory?);
Debug.Assert(languagesProvider.Languages.Length > 0);
......
......@@ -21,6 +21,6 @@ internal interface IEmbeddedLanguageFeatures : IEmbeddedLanguage
/// <summary>
/// An optional analyzer that produces diagnostics for an embedded language string.
/// </summary>
AbstractCodeStyleDiagnosticAnalyzer DiagnosticAnalyzer { get; }
AbstractBuiltInCodeStyleDiagnosticAnalyzer DiagnosticAnalyzer { get; }
}
}
......@@ -13,7 +13,7 @@ namespace Microsoft.CodeAnalysis.Features.EmbeddedLanguages.RegularExpressions
/// <summary>
/// Analyzer that reports diagnostics in strings that we know are regex text.
/// </summary>
internal sealed class RegexDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal sealed class RegexDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public const string DiagnosticId = "RE0001";
......
......@@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Features.EmbeddedLanguages.RegularExpressions
internal class RegexEmbeddedLanguageFeatures : RegexEmbeddedLanguage, IEmbeddedLanguageFeatures
{
public IDocumentHighlightsService DocumentHighlightsService { get; }
public AbstractCodeStyleDiagnosticAnalyzer DiagnosticAnalyzer { get; }
public AbstractBuiltInCodeStyleDiagnosticAnalyzer DiagnosticAnalyzer { get; }
public RegexEmbeddedLanguageFeatures(EmbeddedLanguageInfo info) : base(info)
{
......
......@@ -1351,6 +1351,15 @@ internal class FeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Fix formatting.
/// </summary>
internal static string Fix_formatting {
get {
return ResourceManager.GetString("Fix_formatting", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Fix Name Violation: {0}.
/// </summary>
......
......@@ -1439,4 +1439,7 @@ This version used in: {2}</value>
<data name="Modifying_source_file_will_prevent_the_debug_session_from_continuing_due_to_internal_error" xml:space="preserve">
<value>Modifying source file {0} will prevent the debug session from continuing due to internal error: {1}.</value>
</data>
<data name="Fix_formatting" xml:space="preserve">
<value>Fix formatting</value>
</data>
</root>
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editing;
namespace Microsoft.CodeAnalysis.Formatting
{
[ExportCodeFixProvider(LanguageNames.CSharp, LanguageNames.VisualBasic, Name = PredefinedCodeFixProviderNames.FixFormatting)]
[Shared]
internal class FormattingCodeFixProvider : SyntaxEditorBasedCodeFixProvider
{
public override ImmutableArray<string> FixableDiagnosticIds
=> ImmutableArray.Create(IDEDiagnosticIds.FormattingDiagnosticId);
public override Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diagnostic in context.Diagnostics)
{
context.RegisterCodeFix(
new MyCodeAction(c => FixOneAsync(context, diagnostic, c)),
diagnostic);
}
return Task.CompletedTask;
}
private static async Task<Document> FixOneAsync(CodeFixContext context, Diagnostic diagnostic, CancellationToken cancellationToken)
{
var options = await context.Document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);
return await FormattingCodeFixHelper.FixOneAsync(context.Document, options, diagnostic, cancellationToken).ConfigureAwait(false);
}
protected override async Task FixAllAsync(Document document, ImmutableArray<Diagnostic> diagnostics, SyntaxEditor editor, CancellationToken cancellationToken)
{
var options = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);
var updatedDocument = await Formatter.FormatAsync(document, options, cancellationToken).ConfigureAwait(false);
editor.ReplaceNode(editor.OriginalRoot, await updatedDocument.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false));
}
private sealed class MyCodeAction : CodeAction.DocumentChangeAction
{
public MyCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
: base(FeaturesResources.Fix_formatting, createChangedDocument, FeaturesResources.Fix_formatting)
{
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.Formatting
{
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
internal class FormattingDiagnosticAnalyzer
: AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public FormattingDiagnosticAnalyzer()
: base(
IDEDiagnosticIds.FormattingDiagnosticId,
new LocalizableResourceString(nameof(FeaturesResources.Fix_formatting), FeaturesResources.ResourceManager, typeof(FeaturesResources)),
new LocalizableResourceString(nameof(FeaturesResources.Fix_formatting), FeaturesResources.ResourceManager, typeof(FeaturesResources)))
{
}
public override DiagnosticAnalyzerCategory GetAnalyzerCategory()
=> DiagnosticAnalyzerCategory.SyntaxAnalysis;
public override bool OpenFileOnly(Workspace workspace)
=> false;
protected override void InitializeWorker(AnalysisContext context)
=> context.RegisterSyntaxTreeAction(AnalyzeSyntaxTree);
private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context)
{
if (!(context.Options is WorkspaceAnalyzerOptions workspaceAnalyzerOptions))
{
return;
}
var tree = context.Tree;
var cancellationToken = context.CancellationToken;
var options = context.Options.GetDocumentOptionSetAsync(tree, cancellationToken).GetAwaiter().GetResult();
if (options == null)
{
return;
}
var workspace = workspaceAnalyzerOptions.Services.Workspace;
FormattingAnalyzerHelper.AnalyzeSyntaxTree(context, Descriptor, workspace, options);
}
}
}
......@@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.MakeFieldReadonly
{
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
internal sealed class MakeFieldReadonlyDiagnosticAnalyzer
: AbstractCodeStyleDiagnosticAnalyzer
: AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public MakeFieldReadonlyDiagnosticAnalyzer()
: base(
......
......@@ -96,6 +96,9 @@
<InternalsVisibleTo Include="Microsoft.VisualStudio.Completion.Tests" Key="$(CompletionTestsKey)" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\CodeStyle\Core\Analyzers\AbstractCodeStyleDiagnosticAnalyzer.cs" Link="CodeStyle\AbstractCodeStyleDiagnosticAnalyzer.cs" />
<Compile Include="..\..\..\CodeStyle\Core\CodeFixes\FormattingAnalyzerHelper.cs" Link="Formatting\FormattingAnalyzerHelper.cs" />
<Compile Include="..\..\..\CodeStyle\Core\CodeFixes\FormattingCodeFixHelper.cs" Link="Formatting\FormattingCodeFixHelper.cs" />
<Compile Include="..\..\..\Compilers\Shared\DesktopShim.cs">
<Link>Shared\Utilities\DesktopShim.cs</Link>
</Compile>
......
......@@ -9,7 +9,7 @@
namespace Microsoft.CodeAnalysis.OrderModifiers
{
internal abstract class AbstractOrderModifiersDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal abstract class AbstractOrderModifiersDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
private readonly ISyntaxFactsService _syntaxFacts;
private readonly Option<CodeStyleOption<string>> _option;
......
......@@ -13,7 +13,7 @@ namespace Microsoft.CodeAnalysis.PopulateSwitch
{
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
internal sealed class PopulateSwitchDiagnosticAnalyzer :
AbstractCodeStyleDiagnosticAnalyzer
AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
private static readonly LocalizableString s_localizableTitle = new LocalizableResourceString(nameof(FeaturesResources.Add_missing_cases), FeaturesResources.ResourceManager, typeof(FeaturesResources));
private static readonly LocalizableString s_localizableMessage = new LocalizableResourceString(nameof(WorkspacesResources.Populate_switch), WorkspacesResources.ResourceManager, typeof(WorkspacesResources));
......
......@@ -8,7 +8,7 @@
namespace Microsoft.CodeAnalysis.PreferFrameworkType
{
internal abstract class PreferFrameworkTypeDiagnosticAnalyzerBase<TSyntaxKind, TExpressionSyntax, TPredefinedTypeSyntax> :
AbstractCodeStyleDiagnosticAnalyzer
AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TSyntaxKind : struct
where TExpressionSyntax : SyntaxNode
where TPredefinedTypeSyntax : TExpressionSyntax
......
......@@ -12,7 +12,7 @@ internal abstract class AbstractQualifyMemberAccessDiagnosticAnalyzer<
TLanguageKindEnum,
TExpressionSyntax,
TSimpleNameSyntax>
: AbstractCodeStyleDiagnosticAnalyzer
: AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TLanguageKindEnum : struct
where TExpressionSyntax : SyntaxNode
where TSimpleNameSyntax : TExpressionSyntax
......
......@@ -17,7 +17,7 @@ internal abstract class AbstractSimplifyThisOrMeDiagnosticAnalyzer<
TExpressionSyntax,
TThisExpressionSyntax,
TMemberAccessExpressionSyntax> :
AbstractCodeStyleDiagnosticAnalyzer
AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TLanguageKindEnum : struct
where TExpressionSyntax : SyntaxNode
where TThisExpressionSyntax : TExpressionSyntax
......
......@@ -9,7 +9,7 @@
namespace Microsoft.CodeAnalysis.UseAutoProperty
{
internal abstract class AbstractUseAutoPropertyAnalyzer<
TPropertyDeclaration, TFieldDeclaration, TVariableDeclarator, TExpression> : AbstractCodeStyleDiagnosticAnalyzer
TPropertyDeclaration, TFieldDeclaration, TVariableDeclarator, TExpression> : AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TPropertyDeclaration : SyntaxNode
where TFieldDeclaration : SyntaxNode
where TVariableDeclarator : SyntaxNode
......
......@@ -14,7 +14,7 @@ internal abstract class AbstractUseCoalesceExpressionDiagnosticAnalyzer<
TSyntaxKind,
TExpressionSyntax,
TConditionalExpressionSyntax,
TBinaryExpressionSyntax> : AbstractCodeStyleDiagnosticAnalyzer
TBinaryExpressionSyntax> : AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TSyntaxKind : struct
where TExpressionSyntax : SyntaxNode
where TConditionalExpressionSyntax : TExpressionSyntax
......
......@@ -14,7 +14,7 @@ internal abstract class AbstractUseCoalesceExpressionForNullableDiagnosticAnalyz
TConditionalExpressionSyntax,
TBinaryExpressionSyntax,
TMemberAccessExpression,
TPrefixUnaryExpressionSyntax> : AbstractCodeStyleDiagnosticAnalyzer
TPrefixUnaryExpressionSyntax> : AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TSyntaxKind : struct
where TExpressionSyntax : SyntaxNode
where TConditionalExpressionSyntax : TExpressionSyntax
......
......@@ -20,7 +20,7 @@ internal abstract partial class AbstractUseCollectionInitializerDiagnosticAnalyz
TInvocationExpressionSyntax,
TExpressionStatementSyntax,
TVariableDeclaratorSyntax>
: AbstractCodeStyleDiagnosticAnalyzer
: AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TSyntaxKind : struct
where TExpressionSyntax : SyntaxNode
where TStatementSyntax : SyntaxNode
......
......@@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.UseConditionalExpression
{
internal abstract class AbstractUseConditionalExpressionDiagnosticAnalyzer<
TIfStatementSyntax>
: AbstractCodeStyleDiagnosticAnalyzer
: AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TIfStatementSyntax : SyntaxNode
{
private readonly PerLanguageOption<CodeStyleOption<bool>> _option;
......
......@@ -10,7 +10,7 @@
namespace Microsoft.CodeAnalysis.UseExplicitTupleName
{
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
internal class UseExplicitTupleNameDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal class UseExplicitTupleNameDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public const string ElementName = nameof(ElementName);
......
......@@ -6,7 +6,7 @@
namespace Microsoft.CodeAnalysis.UseInferredMemberName
{
internal abstract class AbstractUseInferredMemberNameDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal abstract class AbstractUseInferredMemberNameDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
abstract protected void LanguageSpecificAnalyzeSyntax(SyntaxNodeAnalysisContext context, SyntaxTree syntaxTree, OptionSet optionSet);
......
......@@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.UseIsNullCheck
{
internal abstract class AbstractUseIsNullCheckForReferenceEqualsDiagnosticAnalyzer<
TLanguageKindEnum>
: AbstractCodeStyleDiagnosticAnalyzer
: AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TLanguageKindEnum : struct
{
protected AbstractUseIsNullCheckForReferenceEqualsDiagnosticAnalyzer(LocalizableString title)
......
......@@ -22,7 +22,7 @@ internal abstract class AbstractUseNullPropagationDiagnosticAnalyzer<
TInvocationExpression,
TMemberAccessExpression,
TConditionalAccessExpression,
TElementAccessExpression> : AbstractCodeStyleDiagnosticAnalyzer
TElementAccessExpression> : AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TSyntaxKind : struct
where TExpressionSyntax : SyntaxNode
where TConditionalExpressionSyntax : TExpressionSyntax
......
......@@ -18,7 +18,7 @@ internal abstract partial class AbstractUseObjectInitializerDiagnosticAnalyzer<
TMemberAccessExpressionSyntax,
TAssignmentStatementSyntax,
TVariableDeclaratorSyntax>
: AbstractCodeStyleDiagnosticAnalyzer
: AbstractBuiltInCodeStyleDiagnosticAnalyzer
where TSyntaxKind : struct
where TExpressionSyntax : SyntaxNode
where TStatementSyntax : SyntaxNode
......
......@@ -33,7 +33,7 @@ namespace Microsoft.CodeAnalysis.UseThrowExpression
/// expressions as well.
/// </summary>
internal abstract class AbstractUseThrowExpressionDiagnosticAnalyzer :
AbstractCodeStyleDiagnosticAnalyzer
AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
protected AbstractUseThrowExpressionDiagnosticAnalyzer()
: base(IDEDiagnosticIds.UseThrowExpressionDiagnosticId,
......
......@@ -62,6 +62,11 @@
<target state="new">Convert to tuple</target>
<note />
</trans-unit>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Fix_typo_0">
<source>Fix typo '{0}'</source>
<target state="translated">Opravit překlep {0}</target>
......
......@@ -62,6 +62,11 @@
<target state="new">Convert to tuple</target>
<note />
</trans-unit>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Fix_typo_0">
<source>Fix typo '{0}'</source>
<target state="translated">Tippfehler "{0}" korrigieren</target>
......
......@@ -62,6 +62,11 @@
<target state="new">Convert to tuple</target>
<note />
</trans-unit>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Fix_typo_0">
<source>Fix typo '{0}'</source>
<target state="translated">Corregir error de escritura "{0}"</target>
......
......@@ -62,6 +62,11 @@
<target state="new">Convert to tuple</target>
<note />
</trans-unit>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Fix_typo_0">
<source>Fix typo '{0}'</source>
<target state="translated">Corriger la faute de frappe '{0}'</target>
......
......@@ -62,6 +62,11 @@
<target state="new">Convert to tuple</target>
<note />
</trans-unit>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Fix_typo_0">
<source>Fix typo '{0}'</source>
<target state="translated">Correggere l'errore di ortografia '{0}'</target>
......
......@@ -62,6 +62,11 @@
<target state="new">Convert to tuple</target>
<note />
</trans-unit>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Fix_typo_0">
<source>Fix typo '{0}'</source>
<target state="translated">'{0}' の入力ミスを修正します</target>
......
......@@ -62,6 +62,11 @@
<target state="new">Convert to tuple</target>
<note />
</trans-unit>
<trans-unit id="Fix_formatting">
<source>Fix formatting</source>
<target state="new">Fix formatting</target>
<note />
</trans-unit>
<trans-unit id="Fix_typo_0">
<source>Fix typo '{0}'</source>
<target state="translated">오타 '{0}' 수정</target>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册