You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
C#: Various fixes to generic scripts
- Report a diagnostic when there are multiple classes that match the script file name in the same script since that will result in a duplicate path key in the bimap and it's not allowed. - Fix InspectorPlugin to handle empty paths in case the project was built with a previous version of Godot that used empty paths for generic scripts. - Add tests for the new diagnostic GD0003.
This commit is contained in:
@@ -58,9 +58,10 @@ namespace Godot.SourceGenerators
|
||||
.GroupBy<(ClassDeclarationSyntax cds, INamedTypeSymbol symbol), INamedTypeSymbol>(x => x.symbol, SymbolEqualityComparer.Default)
|
||||
.ToDictionary<IGrouping<INamedTypeSymbol, (ClassDeclarationSyntax cds, INamedTypeSymbol symbol)>, INamedTypeSymbol, IEnumerable<ClassDeclarationSyntax>>(g => g.Key, g => g.Select(x => x.cds), SymbolEqualityComparer.Default);
|
||||
|
||||
var usedPaths = new HashSet<string>();
|
||||
foreach (var godotClass in godotClasses)
|
||||
{
|
||||
VisitGodotScriptClass(context, godotProjectDir,
|
||||
VisitGodotScriptClass(context, godotProjectDir, usedPaths,
|
||||
symbol: godotClass.Key,
|
||||
classDeclarations: godotClass.Value);
|
||||
}
|
||||
@@ -74,6 +75,7 @@ namespace Godot.SourceGenerators
|
||||
private static void VisitGodotScriptClass(
|
||||
GeneratorExecutionContext context,
|
||||
string godotProjectDir,
|
||||
HashSet<string> usedPaths,
|
||||
INamedTypeSymbol symbol,
|
||||
IEnumerable<ClassDeclarationSyntax> classDeclarations
|
||||
)
|
||||
@@ -93,8 +95,19 @@ namespace Godot.SourceGenerators
|
||||
if (attributes.Length != 0)
|
||||
attributes.Append("\n");
|
||||
|
||||
string scriptPath = RelativeToDir(cds.SyntaxTree.FilePath, godotProjectDir);
|
||||
if (!usedPaths.Add(scriptPath))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
Common.MultipleClassesInGodotScriptRule,
|
||||
cds.Identifier.GetLocation(),
|
||||
symbol.Name
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
attributes.Append(@"[ScriptPathAttribute(""res://");
|
||||
attributes.Append(RelativeToDir(cds.SyntaxTree.FilePath, godotProjectDir));
|
||||
attributes.Append(scriptPath);
|
||||
attributes.Append(@""")]");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user