Skip to content

Commit 9d4779d

Browse files
committed
[#2] FIXED Expressing custom types using full namespace
1 parent 6c1648d commit 9d4779d

13 files changed

Lines changed: 113 additions & 31 deletions

CustomGeneratorTests/CustomGeneratorTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1010
</PropertyGroup>
1111
<ItemGroup>
12-
<PackageReference Include="GodotSharp.SourceGenerators" Version="1.1.1" />
12+
<PackageReference Include="GodotSharp.SourceGenerators" Version="1.1.2" />
1313
</ItemGroup>
1414
</Project>

GodotTests/.filenesting.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"help": "https://go.microsoft.com/fwlink/?linkid=866610",
3+
4+
"dependentFileProviders": {
5+
"add": {
6+
"extensionToExtension": {
7+
"add": {
8+
".tscn": [
9+
".cs"
10+
]
11+
}
12+
},
13+
"fileToFile": {
14+
"add": {
15+
"plugin.cfg": [
16+
"Plugin.cs",
17+
"plugin.gd"
18+
]
19+
}
20+
}
21+
}
22+
}
23+
}

GodotTests/GodotTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<ItemGroup>
1515
<PackageReference Include="FluentAssertions" Version="6.0.0-alpha0002" />
1616
<PackageReference Include="FluentAssertions.Analyzers" Version="0.11.4" />
17-
<PackageReference Include="GodotSharp.SourceGenerators" Version="1.1.1" />
17+
<PackageReference Include="GodotSharp.SourceGenerators" Version="1.1.2" />
1818
</ItemGroup>
1919
<ItemGroup>
2020
<ProjectReference Include="..\CustomGeneratorTests\CustomGeneratorTests.csproj" OutputItemType="analyzer" />
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Godot;
2+
3+
namespace GodotTests.TestScenes
4+
{
5+
[SceneTree]
6+
public partial class InstancingSceneWithSameNameAsNamespace : Control
7+
{
8+
}
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[gd_scene load_steps=3 format=2]
2+
3+
[ext_resource path="res://TestScenes/InstancingSceneWithSameNameAsNamespace.cs" type="Script" id=1]
4+
[ext_resource path="res://TestScenes/SceneWithSameNameAsNamespace/SceneWithSameNameAsNamespace.tscn" type="PackedScene" id=2]
5+
6+
[node name="Control" type="Control"]
7+
anchor_right = 1.0
8+
anchor_bottom = 1.0
9+
script = ExtResource( 1 )
10+
__meta__ = {
11+
"_edit_use_anchors_": false
12+
}
13+
14+
[node name="Control" parent="." instance=ExtResource( 2 )]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Godot;
2+
3+
namespace GodotTests.TestScenes.SceneWithSameNameAsNamespace
4+
{
5+
[SceneTree]
6+
public partial class SceneWithSameNameAsNamespace : Control
7+
{
8+
}
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extends Control
2+
3+
4+
# Declare member variables here. Examples:
5+
# var a = 2
6+
# var b = "text"
7+
8+
9+
# Called when the node enters the scene tree for the first time.
10+
func _ready():
11+
pass # Replace with function body.
12+
13+
14+
# Called every frame. 'delta' is the elapsed time since the previous frame.
15+
#func _process(delta):
16+
# pass
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[gd_scene load_steps=2 format=2]
2+
3+
[ext_resource path="res://TestScenes/SceneWithSameNameAsNamespace/SceneWithSameNameAsNamespace.cs" type="Script" id=1]
4+
5+
[node name="Control" type="Control"]
6+
anchor_right = 1.0
7+
anchor_bottom = 1.0
8+
script = ExtResource( 1 )
9+
__meta__ = {
10+
"_edit_use_anchors_": false
11+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Linq;
2+
using Microsoft.CodeAnalysis;
3+
4+
namespace GodotSharp.SourceGenerators
5+
{
6+
public static class CompilationExtensions
7+
{
8+
public static string GetNamespace(this Compilation compilation, string type)
9+
{
10+
return compilation
11+
.GetSymbolsWithName(type, SymbolFilter.Type)
12+
.First().NamespaceOrNull();
13+
}
14+
15+
public static string GetFullName(this Compilation compilation, string type)
16+
{
17+
var ns = compilation.GetNamespace(type);
18+
return ns is null ? type : $"{ns}.{type}";
19+
}
20+
}
21+
}
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
using System.Linq;
32
using Microsoft.CodeAnalysis;
43

54
namespace GodotSharp.SourceGenerators.SceneTreeExtensions
@@ -10,28 +9,13 @@ internal class SceneTreeDataModel
109
public string NSClose { get; }
1110
public string NSIndent { get; }
1211
public string ClassName { get; }
13-
public ICollection<string> Usings { get; }
1412
public ICollection<SceneTreeNode> Properties { get; }
1513

1614
public SceneTreeDataModel(Compilation compilation, INamedTypeSymbol symbol, string tscnFile)
1715
{
1816
ClassName = symbol.ClassDef();
1917
(NSOpen, NSClose, NSIndent) = symbol.GetNamespaceDeclaration();
20-
21-
var (childNodes, customTypes) = SceneTreeScraper.GetNodes(tscnFile);
22-
23-
Properties = childNodes;
24-
Usings = customTypes
25-
.Select(GetNamespace)
26-
.Where(x => x is not null)
27-
.ToList();
28-
29-
string GetNamespace(string type)
30-
{
31-
return compilation
32-
.GetSymbolsWithName(type, SymbolFilter.Type)
33-
.First().NamespaceOrNull();
34-
}
18+
Properties = SceneTreeScraper.GetNodes(compilation, tscnFile);
3519
}
3620
}
3721
}

0 commit comments

Comments
 (0)