Skip to content

Commit cc0736c

Browse files
committed
Refactor localization code-fix provider
Added a new `Editor.Localization.CodeFixProvider` project to encapsulate the `OldGetTranslateAnalyzerCodeFixProvider` functionality. Updated the solution and project files to include the new project as an analyzer. Replaced the old implementation of the code-fix provider with a cleaner, more maintainable version in the new project. Streamlined dependencies in `Editor.Localization.Analyzers.csproj` by replacing `Microsoft.CodeAnalysis.CSharp.Workspaces` with `Microsoft.CodeAnalysis.CSharp`. Improved code structure, diagnostic handling, and utility methods for transforming old localization API calls. These changes enhance modularity, maintainability, and adherence to modern coding standards while preserving existing functionality.
1 parent ccc10f3 commit cc0736c

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

Editor.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<File Path="Localization/README.md" />
55
<Project Path="Localization/Editor.Localization.Analyzers/Editor.Localization.Analyzers.csproj" />
66
<Project Path="Localization/Editor.Localization.Attributes/Editor.Localization.Attributes.csproj" />
7+
<Project Path="Localization/Editor.Localization.CodeFixProvider/Editor.Localization.CodeFixProvider.csproj" Id="77d44011-a18d-4968-ab54-fbe7db91a189" />
78
<Project Path="Localization/Editor.Localization.Shared/Editor.Localization.Shared.csproj" />
89
<Project Path="Localization/Editor.Localization.SourceGenerators/Editor.Localization.SourceGenerators.csproj" />
910
</Folder>

Editor/Editor.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<ItemGroup>
4646
<ProjectReference Include="..\Localization\Editor.Localization.Analyzers\Editor.Localization.Analyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
4747
<ProjectReference Include="..\Localization\Editor.Localization.Attributes\Editor.Localization.Attributes.csproj" OutputItemType="Analyzer" />
48+
<ProjectReference Include="..\Localization\Editor.Localization.CodeFixProvider\Editor.Localization.CodeFixProvider.csproj" OutputItemType="Analyzer" />
4849
<ProjectReference Include="..\Localization\Editor.Localization.Shared\Editor.Localization.Shared.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
4950
<ProjectReference Include="..\Localization\Editor.Localization.SourceGenerators\Editor.Localization.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
5051
</ItemGroup>

Localization/Editor.Localization.Analyzers/Editor.Localization.Analyzers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1313
</PackageReference>
14-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0" />
14+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
1515
</ItemGroup>
1616

1717
<ItemGroup>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
6+
<RootNamespace>Editor.Localization.CodeFixProvider</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\Editor.Localization.Shared\Editor.Localization.Shared.csproj" />
15+
</ItemGroup>
16+
17+
</Project>

Localization/Editor.Localization.Analyzers/Localize/OldGetTranslateAnalyzerCodeFixProvider.cs renamed to Localization/Editor.Localization.CodeFixProvider/Localize/OldGetTranslateAnalyzerCodeFixProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class OldGetTranslateAnalyzerCodeFixProvider : CodeFixProvider
1717
#region CodeFixProvider
1818

1919
public sealed override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(
20-
AnalyzerDiagnostics.OldLocalizationApiUsed.Id
20+
Constants.OldLocalizationApiUsedId
2121
);
2222

2323
public sealed override FixAllProvider GetFixAllProvider()
@@ -35,7 +35,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
3535
CodeAction.Create(
3636
title: $"Replace with '{Constants.ClassName}.localization_key(...args)'",
3737
createChangedDocument: _ => FixOldTranslationAsync(context, root, diagnostic),
38-
equivalenceKey: AnalyzerDiagnostics.OldLocalizationApiUsed.Id
38+
equivalenceKey: Constants.OldLocalizationApiUsedId
3939
),
4040
diagnostic
4141
);

0 commit comments

Comments
 (0)