Skip to content

Commit a623bcf

Browse files
committed
refactor
1 parent d083007 commit a623bcf

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

Editor/AssemblyFilterDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private void Initialize(SerializedProperty property)
2727
_roIncludedAssemblies = new ReorderableList(property.serializedObject, _includedAssemblies, true, true, true, true);
2828
_roIncludedAssemblies.drawHeaderCallback = rect =>
2929
{
30-
EditorGUI.PrefixLabel(rect, new GUIContent(_includedAssemblies.displayName));
30+
EditorGUI.PrefixLabel(rect, new GUIContent("Target Assemblies"));
3131

3232
rect.x += rect.width - 110;
3333
rect.width = 110;

Editor/CSharpProjectModifier.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ private static string OnGeneratedCSProject(string path, string content)
4545
}
4646

4747
// Additional contents.
48-
content = Regex.Replace(content, "[\r\n]+</Project>[\r\n]*", "\r\n<!-- C# Settings For Unity -->");
48+
content = Regex.Replace(content, NewLine + AdditionalContentComment + ".*" + AdditionalContentComment, "", RegexOptions.Singleline);
49+
content = Regex.Replace(content, "[\r\n]+</Project>[\r\n]*", NewLine + AdditionalContentComment);
4950
{
5051
content += NewLine + " <ItemGroup>";
5152
{
@@ -55,17 +56,17 @@ private static string OnGeneratedCSProject(string path, string content)
5556

5657
// Add analyzer packages.
5758
foreach (var package in setting.AnalyzerPackages)
58-
content = AddPackage(content, package.Name, package.Version);
59+
content = AddAnalyzer(content, package.PackageId);
5960
}
6061
content += NewLine + " </ItemGroup>";
6162

6263
// Add rule set files.
6364
content += NewLine + " <PropertyGroup>";
6465
{
6566
// Ruleset.
66-
var rulesets = new[] {"Assets/Default.ruleset"} // Add default rule set for project.
67+
var rulesets = new[] { "Assets/Default.ruleset" } // Add default rule set for project.
6768
.Concat(string.IsNullOrEmpty(asmdefPath)
68-
? new[] {"Assets/" + assemblyName + ".ruleset"} // Add rule set for predefined assemblies (e.g. Assembly-CSharp.dll).
69+
? new[] { "Assets/" + assemblyName + ".ruleset" } // Add rule set for predefined assemblies (e.g. Assembly-CSharp.dll).
6970
: Directory.GetFiles(Path.GetDirectoryName(asmdefPath), "*.ruleset")) // Add rule sets for asmdef.
7071
.Where(File.Exists);
7172

@@ -74,7 +75,7 @@ private static string OnGeneratedCSProject(string path, string content)
7475
}
7576
content += NewLine + " </PropertyGroup>";
7677
}
77-
content += NewLine + "<!-- C# Settings For Unity -->" + NewLine + NewLine + "</Project>" + NewLine;
78+
content += NewLine + AdditionalContentComment + NewLine + "</Project>" + NewLine;
7879

7980
return content;
8081
}
@@ -88,13 +89,22 @@ private static string AddPackage(string content, string name, string version)
8889
return content;
8990
}
9091

92+
private static string AddAnalyzer(string content, string packageId)
93+
{
94+
var info = AnalyzerInfo.GetInstalledInfo(packageId);
95+
foreach (var dll in info.DllFiles)
96+
content += NewLine + " <Analyzer Include=\"" + dll.Replace('/', '\\') + "\" />";
97+
return content;
98+
}
99+
91100
private static string AddRuleSet(string content, string ruleset)
92101
{
93102
if (File.Exists(ruleset))
94103
content += NewLine + " <CodeAnalysisRuleSet>" + ruleset.Replace('/', '\\') + "</CodeAnalysisRuleSet>";
95104
return content;
96105
}
97106

98-
private static string NewLine = "\r\n";
107+
private const string NewLine = "\r\n";
108+
private const string AdditionalContentComment = "<!-- C# Settings For Unity -->";
99109
}
100110
}

Editor/CscSettingsProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal class CscSettingsProvider
1616
private static ReorderableList s_RoAnalyzerPackages;
1717

1818
private static GUIContent s_HeaderCompiler = new GUIContent("Compiler");
19-
private static GUIContent s_HeaderAnalyzer = new GUIContent("Analyzer");
19+
private static GUIContent s_HeaderAnalyzer = new GUIContent("Analyzer / Source Generator");
2020
private static GUIContent s_HeaderDebug = new GUIContent("Debug");
2121

2222

@@ -30,7 +30,7 @@ private static SettingsProvider CreateSettingsProvider()
3030

3131
var analyzerPackages = serializedObject.FindProperty("m_AnalyzerPackages");
3232
s_RoAnalyzerPackages = new ReorderableList(serializedObject, analyzerPackages);
33-
s_RoAnalyzerPackages.drawHeaderCallback = rect => EditorGUI.PrefixLabel(rect, GUIUtility.GetControlID(FocusType.Passive), new GUIContent("Analyzer Packages"));
33+
s_RoAnalyzerPackages.drawHeaderCallback = rect => EditorGUI.PrefixLabel(rect, GUIUtility.GetControlID(FocusType.Passive), new GUIContent("Packages"));
3434
s_RoAnalyzerPackages.elementHeight = NugetPackageDrawer.Height;
3535
s_RoAnalyzerPackages.drawElementCallback = (rect, index, active, focused) =>
3636
{
@@ -42,7 +42,7 @@ private static SettingsProvider CreateSettingsProvider()
4242
for (var i = 0; i < analyzerPackages.arraySize; i++)
4343
{
4444
var sp = analyzerPackages.GetArrayElementAtIndex(i);
45-
sp.FindPropertyRelative("m_Category").intValue = (int) NugetPackage.CategoryType.Analyzer;
45+
sp.FindPropertyRelative("m_Category").intValue = (int)NugetPackage.CategoryType.Analyzer;
4646
}
4747
};
4848

Editor/InspectorGUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static bool DrawCompilerPackage(SerializedObject so)
144144
var spCompilerType = so.FindProperty("m_CompilerType");
145145
EditorGUILayout.PropertyField(spCompilerType);
146146

147-
bool isCustomPackage = spCompilerType.intValue == (int) CompilerType.CustomPackage;
147+
bool isCustomPackage = spCompilerType.intValue == (int)CompilerType.CustomPackage;
148148
if (isCustomPackage)
149149
{
150150
EditorGUI.indentLevel++;

Plugins/CSharpCompilerSettings/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static string[] ModifySymbols(IEnumerable<string> defines, string modifyS
4343
public static void RequestCompilation(string assemblyName = null)
4444
{
4545
var unityVersions = Application.unityVersion.Split('.');
46-
if(2021 <= int.Parse(unityVersions[0]))
46+
if (2021 <= int.Parse(unityVersions[0]))
4747
{
4848
typeof(CompilationPipeline).Call("RequestScriptCompilation");
4949
return;

0 commit comments

Comments
 (0)