From c2f1c2dbf0a1f2aea2d8d7fa9d8701142d482ccf Mon Sep 17 00:00:00 2001 From: mreow Date: Sat, 3 Jan 2026 01:43:30 -0500 Subject: [PATCH 1/3] Fix diagnostic messages and add parser documentation - Fixed DC0003 diagnostic to show 'Value out of range' instead of 'Type mismatch' - Improved message format to include property name and constraint details - Added XML documentation for IsIncremental explaining incremental parsing behavior - Added XML documentation for Width property clarifying direct vs tree-wide counting - Replaced empty string literals with string.Empty to avoid .NET 9.0.308 compiler crash --- .../Diagnostics.cs | 6 +++--- src/Discord.Net.ComponentDesigner.Parser/CXParser.cs | 5 +++++ .../DebugUtils/ASTFormatter.Structural.cs | 8 ++++---- src/Discord.Net.ComponentDesigner.Parser/Nodes/CXNode.cs | 8 +++++++- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Discord.Net.ComponentDesigner.Generator/Diagnostics.cs b/src/Discord.Net.ComponentDesigner.Generator/Diagnostics.cs index 9110860..0666427 100644 --- a/src/Discord.Net.ComponentDesigner.Generator/Diagnostics.cs +++ b/src/Discord.Net.ComponentDesigner.Generator/Diagnostics.cs @@ -35,10 +35,10 @@ public static DiagnosticDescriptor CreateParsingDiagnostic(CXDiagnostic diagnost true ); - public static DiagnosticDescriptor OutOfRange(string a, string b) => new( + public static DiagnosticDescriptor OutOfRange(string property, string constraint) => new( "DC0003", - "Type mismatch", - "'{0}' must be {1}", + "Value out of range", + "Property '{0}' is out of range: {1}", "Components", DiagnosticSeverity.Error, true diff --git a/src/Discord.Net.ComponentDesigner.Parser/CXParser.cs b/src/Discord.Net.ComponentDesigner.Parser/CXParser.cs index 3d28e39..043fc81 100644 --- a/src/Discord.Net.ComponentDesigner.Parser/CXParser.cs +++ b/src/Discord.Net.ComponentDesigner.Parser/CXParser.cs @@ -27,6 +27,11 @@ public sealed partial class CXParser /// /// Gets whether this parser is operating in an incremental mode. /// + /// + /// In incremental mode, the parser reuses unchanged AST nodes from a previous parse, + /// dramatically improving performance for editor scenarios where only small regions change. + /// When false, a complete reparse is performed from scratch. + /// [MemberNotNullWhen(true, nameof(Blender), nameof(_blendedNodes))] public bool IsIncremental => Blender is not null && _blendedNodes is not null; diff --git a/src/Discord.Net.ComponentDesigner.Parser/DebugUtils/ASTFormatter.Structural.cs b/src/Discord.Net.ComponentDesigner.Parser/DebugUtils/ASTFormatter.Structural.cs index 69f3e31..881a5c3 100644 --- a/src/Discord.Net.ComponentDesigner.Parser/DebugUtils/ASTFormatter.Structural.cs +++ b/src/Discord.Net.ComponentDesigner.Parser/DebugUtils/ASTFormatter.Structural.cs @@ -53,7 +53,7 @@ void Write(ICXNode node, int depth = 0, int padding = 2) .Append(": ".Grey()); } - var spacer = "".PadLeft((depth + 1) * padding); + var spacer = string.Empty.PadLeft((depth + 1) * padding); sb.AppendLine("[").Append(spacer); @@ -162,7 +162,7 @@ or nameof(CXValue.Multipart.HasInterpolations) var startPos = sb.Length; - sb.Append("".PadLeft((depth + 1) * padding)).Append($"{name}: "); + sb.Append(string.Empty.PadLeft((depth + 1) * padding)).Append($"{name}: "); var preValuePos = sb.Length; @@ -174,7 +174,7 @@ or nameof(CXValue.Multipart.HasInterpolations) sb.AppendLine(","); } - sb.Append("".PadLeft(depth * padding)).Append("}"); + sb.Append(string.Empty.PadLeft(depth * padding)).Append("}"); break; } } @@ -236,7 +236,7 @@ void WriteValue(object? value, int depth, int padding) .Append(": ".Grey()); } - var spacer = "".PadLeft((depth + 1) * padding); + var spacer = string.Empty.PadLeft((depth + 1) * padding); sb.AppendLine("[").Append(spacer); diff --git a/src/Discord.Net.ComponentDesigner.Parser/Nodes/CXNode.cs b/src/Discord.Net.ComponentDesigner.Parser/Nodes/CXNode.cs index ee3f8a4..8880d92 100644 --- a/src/Discord.Net.ComponentDesigner.Parser/Nodes/CXNode.cs +++ b/src/Discord.Net.ComponentDesigner.Parser/Nodes/CXNode.cs @@ -20,7 +20,13 @@ public abstract class CXNode : ICXNode /// public CXNode? Parent { get; set; } - /// + /// + /// Gets the number of child slots directly contained within this node. + /// + /// + /// Width counts only direct children (elements in the _slots collection). + /// Use to count the entire descendant tree. + /// public int Width { get; private set; } /// From db6f02f2dea98e5db3adecbe3ee8be1b39bbbe41 Mon Sep 17 00:00:00 2001 From: M1tsumi <0000imdumb0000@gmail.com> Date: Sun, 4 Jan 2026 22:53:10 -0500 Subject: [PATCH 2/3] Address PR feedback: fix Width documentation and improve diagnostic message format --- .../Diagnostics.cs | 2 +- src/Discord.Net.ComponentDesigner.Parser/Nodes/CXNode.cs | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Discord.Net.ComponentDesigner.Generator/Diagnostics.cs b/src/Discord.Net.ComponentDesigner.Generator/Diagnostics.cs index 0666427..f269aee 100644 --- a/src/Discord.Net.ComponentDesigner.Generator/Diagnostics.cs +++ b/src/Discord.Net.ComponentDesigner.Generator/Diagnostics.cs @@ -38,7 +38,7 @@ public static DiagnosticDescriptor CreateParsingDiagnostic(CXDiagnostic diagnost public static DiagnosticDescriptor OutOfRange(string property, string constraint) => new( "DC0003", "Value out of range", - "Property '{0}' is out of range: {1}", + $"'{property}' must be {constraint}", "Components", DiagnosticSeverity.Error, true diff --git a/src/Discord.Net.ComponentDesigner.Parser/Nodes/CXNode.cs b/src/Discord.Net.ComponentDesigner.Parser/Nodes/CXNode.cs index 8880d92..ee3f8a4 100644 --- a/src/Discord.Net.ComponentDesigner.Parser/Nodes/CXNode.cs +++ b/src/Discord.Net.ComponentDesigner.Parser/Nodes/CXNode.cs @@ -20,13 +20,7 @@ public abstract class CXNode : ICXNode /// public CXNode? Parent { get; set; } - /// - /// Gets the number of child slots directly contained within this node. - /// - /// - /// Width counts only direct children (elements in the _slots collection). - /// Use to count the entire descendant tree. - /// + /// public int Width { get; private set; } /// From 55ff49c50133e65e58f5242add988dc401560f8f Mon Sep 17 00:00:00 2001 From: quefep <88093506+M1tsumi@users.noreply.github.com> Date: Wed, 7 Jan 2026 00:51:43 -0500 Subject: [PATCH 3/3] Fix typo in README.md for 'optional' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f1209e4..e535757 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ Action rows wrap buttons or select menus providing top-level layout. | Name | Type | Description | | ---- | ---- | ---------------------------------- | -| id? | int | The optonal identifier for the row | +| id? | int | The optional identifier for the row | #### Valid children - [Button](#button)