From 9db1400ef7474cd17938a2e60432d5473dd40433 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Wed, 1 Oct 2025 00:49:47 +1000 Subject: [PATCH] Use generic ref counted container for metadata --- .../Problems/DiagnosticMetadataContainer.cs | 20 ------------------- .../Features/Problems/ProblemsPanel.cs | 12 +++++------ .../Features/Problems/RefCountedContainer.cs | 10 ++++++++++ ...iner.cs.uid => RefCountedContainer.cs.uid} | 0 .../SharpIdeFileGodotContainer.cs | 14 ------------- .../SharpIdeFileGodotContainer.cs.uid | 1 - .../SolutionExplorer/SolutionExplorerPanel.cs | 9 +++++---- 7 files changed, 21 insertions(+), 45 deletions(-) delete mode 100644 src/SharpIDE.Godot/Features/Problems/DiagnosticMetadataContainer.cs create mode 100644 src/SharpIDE.Godot/Features/Problems/RefCountedContainer.cs rename src/SharpIDE.Godot/Features/Problems/{DiagnosticMetadataContainer.cs.uid => RefCountedContainer.cs.uid} (100%) delete mode 100644 src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs delete mode 100644 src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs.uid diff --git a/src/SharpIDE.Godot/Features/Problems/DiagnosticMetadataContainer.cs b/src/SharpIDE.Godot/Features/Problems/DiagnosticMetadataContainer.cs deleted file mode 100644 index e23720c..0000000 --- a/src/SharpIDE.Godot/Features/Problems/DiagnosticMetadataContainer.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Godot; -using Microsoft.CodeAnalysis; -using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; - -namespace SharpIDE.Godot.Features.Problems; - -// public partial class GenericContainer(T item) : RefCounted -// { -// public T Item { get; } = item; -// } - -public partial class DiagnosticMetadataContainer(Diagnostic diagnostic) : RefCounted -{ - public Diagnostic Diagnostic { get; } = diagnostic; -} - -public partial class ProjectContainer(SharpIdeProjectModel project) : RefCounted -{ - public SharpIdeProjectModel Project { get; } = project; -} \ No newline at end of file diff --git a/src/SharpIDE.Godot/Features/Problems/ProblemsPanel.cs b/src/SharpIDE.Godot/Features/Problems/ProblemsPanel.cs index e2383fc..668087b 100644 --- a/src/SharpIDE.Godot/Features/Problems/ProblemsPanel.cs +++ b/src/SharpIDE.Godot/Features/Problems/ProblemsPanel.cs @@ -64,7 +64,7 @@ public partial class ProblemsPanel : Control var treeItem = tree.CreateItem(parent); treeItem.SetText(0, e.NewItem.Value.Name); treeItem.SetIcon(0, CsprojIcon); - treeItem.SetMetadata(0, new ProjectContainer(e.NewItem.Value)); + treeItem.SetMetadata(0, new RefCountedContainer(e.NewItem.Value)); e.NewItem.View.Value = treeItem; Observable.EveryValueChanged(e.NewItem.Value, s => s.Diagnostics.Count).Subscribe(s => treeItem.Visible = s is not 0).AddTo(this); @@ -86,7 +86,7 @@ public partial class ProblemsPanel : Control { var diagItem = tree.CreateItem(parent); diagItem.SetText(0, e.NewItem.Value.GetMessage()); - diagItem.SetMetadata(0, new DiagnosticMetadataContainer(e.NewItem.Value)); + diagItem.SetMetadata(0, new RefCountedContainer(e.NewItem.Value)); diagItem.SetIcon(0, e.NewItem.Value.Severity switch { DiagnosticSeverity.Error => ErrorIcon, @@ -108,13 +108,13 @@ public partial class ProblemsPanel : Control private void TreeOnItemActivated() { var selected = _tree.GetSelected(); - var diagnosticContainer = selected.GetMetadata(0).As(); + var diagnosticContainer = selected.GetMetadata(0).As?>(); if (diagnosticContainer is null) return; - var diagnostic = diagnosticContainer.Diagnostic; + var diagnostic = diagnosticContainer.Item; var parentTreeItem = selected.GetParent(); - var projectContainer = parentTreeItem.GetMetadata(0).As(); + var projectContainer = parentTreeItem.GetMetadata(0).As?>(); if (projectContainer is null) return; - var projectModel = projectContainer.Project; + var projectModel = projectContainer.Item; OpenDocumentContainingDiagnostic(diagnostic, projectModel); } diff --git a/src/SharpIDE.Godot/Features/Problems/RefCountedContainer.cs b/src/SharpIDE.Godot/Features/Problems/RefCountedContainer.cs new file mode 100644 index 0000000..7964002 --- /dev/null +++ b/src/SharpIDE.Godot/Features/Problems/RefCountedContainer.cs @@ -0,0 +1,10 @@ +using Godot; +using Microsoft.CodeAnalysis; +using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; + +namespace SharpIDE.Godot.Features.Problems; + +public partial class RefCountedContainer(T item) : RefCounted +{ + public T Item { get; } = item; +} diff --git a/src/SharpIDE.Godot/Features/Problems/DiagnosticMetadataContainer.cs.uid b/src/SharpIDE.Godot/Features/Problems/RefCountedContainer.cs.uid similarity index 100% rename from src/SharpIDE.Godot/Features/Problems/DiagnosticMetadataContainer.cs.uid rename to src/SharpIDE.Godot/Features/Problems/RefCountedContainer.cs.uid diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs deleted file mode 100644 index 24cfc06..0000000 --- a/src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Godot; -using SharpIDE.Application.Features.SolutionDiscovery; - -namespace SharpIDE.Godot.Features.SolutionExplorer; - -public partial class SharpIdeFileGodotContainer : RefCounted -{ - public required SharpIdeFile File { get; init; } -} - -// public partial class GodotContainer(T value) : GodotObject where T : class -// { -// public T Value { get; init; } = value; -// } \ No newline at end of file diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs.uid b/src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs.uid deleted file mode 100644 index 3123d61..0000000 --- a/src/SharpIDE.Godot/Features/SolutionExplorer/SharpIdeFileGodotContainer.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://dixmfygdn8ogt diff --git a/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs b/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs index 746c7be..86982ad 100644 --- a/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs +++ b/src/SharpIDE.Godot/Features/SolutionExplorer/SolutionExplorerPanel.cs @@ -3,6 +3,7 @@ using Godot; using SharpIDE.Application.Features.Analysis; using SharpIDE.Application.Features.SolutionDiscovery; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; +using SharpIDE.Godot.Features.Problems; namespace SharpIDE.Godot.Features.SolutionExplorer; @@ -32,9 +33,9 @@ public partial class SolutionExplorerPanel : MarginContainer { var selected = _tree.GetSelected(); if (selected is null) return; - var sharpIdeFileContainer = selected.GetMetadata(0).As(); + var sharpIdeFileContainer = selected.GetMetadata(0).As?>(); if (sharpIdeFileContainer is null) return; - var sharpIdeFile = sharpIdeFileContainer.File; + var sharpIdeFile = sharpIdeFileContainer.Item; Guard.Against.Null(sharpIdeFile, nameof(sharpIdeFile)); GodotGlobalEvents.Instance.InvokeFileSelected(sharpIdeFile); } @@ -60,7 +61,7 @@ public partial class SolutionExplorerPanel : MarginContainer private static TreeItem? FindItemRecursive(TreeItem item, SharpIdeFile file) { var metadata = item.GetMetadata(0); - if (metadata.As()?.File == file) + if (metadata.As?>()?.Item == file) return item; var child = item.GetFirstChild(); @@ -160,7 +161,7 @@ public partial class SolutionExplorerPanel : MarginContainer var fileItem = _tree.CreateItem(parent); fileItem.SetText(0, file.Name); fileItem.SetIcon(0, CsharpFileIcon); - var container = new SharpIdeFileGodotContainer { File = file }; + var container = new RefCountedContainer(file); fileItem.SetMetadata(0, container); } }