From 747800b452ec8d35affe4a2891b87b7d7cb8699e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 11 Nov 2025 00:51:51 +0000 Subject: [PATCH 1/2] Initial plan From f2a854b77df174731f699ab890d90506c552ff0f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 11 Nov 2025 01:04:49 +0000 Subject: [PATCH 2/2] Fix inconsistent spacing in ClientUriBuilder binary operators Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> --- .../src/Providers/ClientUriBuilderDefinition.cs | 16 ++++++++-------- .../src/Generated/Internal/ClientUriBuilder.cs | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ClientUriBuilderDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ClientUriBuilderDefinition.cs index 8231562b2f4..3837c2822b4 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ClientUriBuilderDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ClientUriBuilderDefinition.cs @@ -33,7 +33,7 @@ internal sealed class ClientUriBuilderDefinition : TypeProvider modifiers: MethodSignatureModifiers.Private, name: "UriBuilder", type: typeof(UriBuilder), - body: new ExpressionPropertyBody(new BinaryOperatorExpression(" ??= ", _uriBuilderField, New.Instance(typeof(UriBuilder)))), + body: new ExpressionPropertyBody(new BinaryOperatorExpression("??=", _uriBuilderField, New.Instance(typeof(UriBuilder)))), description: null, enclosingType: this); @@ -51,7 +51,7 @@ internal sealed class ClientUriBuilderDefinition : TypeProvider modifiers: MethodSignatureModifiers.Private, name: "PathAndQuery", type: typeof(StringBuilder), - body: new ExpressionPropertyBody(new BinaryOperatorExpression(" ??= ", _pathAndQueryField, New.Instance(typeof(StringBuilder)))), + body: new ExpressionPropertyBody(new BinaryOperatorExpression("??=", _pathAndQueryField, New.Instance(typeof(StringBuilder)))), description: null, enclosingType: this); @@ -153,14 +153,14 @@ private MethodProvider[] BuildAppendPathMethods() }, MethodBodyStatement.Empty, // Check for double slashes: if path ends with '/' and value starts with '/' - new IfStatement(pathLength.GreaterThan(Int(0)).And(stringBuilder.Index(new BinaryOperatorExpression(" - ", pathLength, Int(1))).Equal(Literal('/'))).And(valueParameter.As().Index(Int(0)).Equal(Literal('/')))) + new IfStatement(pathLength.GreaterThan(Int(0)).And(stringBuilder.Index(new BinaryOperatorExpression("-", pathLength, Int(1))).Equal(Literal('/'))).And(valueParameter.As().Index(Int(0)).Equal(Literal('/')))) { - stringBuilder.Remove(new BinaryOperatorExpression(" - ", pathLength, Int(1)), Int(1)).Terminate(), - _pathLengthField.Assign(new BinaryOperatorExpression(" - ", pathLength, Int(1))).Terminate() + stringBuilder.Remove(new BinaryOperatorExpression("-", pathLength, Int(1)), Int(1)).Terminate(), + _pathLengthField.Assign(new BinaryOperatorExpression("-", pathLength, Int(1))).Terminate() }, MethodBodyStatement.Empty, stringBuilder.Invoke("Insert", [pathLength, valueParameter]).Terminate(), - _pathLengthField.Assign(new BinaryOperatorExpression(" + ", pathLength, valueParameter.As().Length())).Terminate() + _pathLengthField.Assign(new BinaryOperatorExpression("+", pathLength, valueParameter.As().Length())).Terminate() }; return @@ -222,7 +222,7 @@ private MethodProvider[] BuildAppendQueryMethods() { stringBuilder.Append(Literal('?')).Terminate() }, - new IfStatement(stringBuilder.Length().GreaterThan(pathLength).And(stringBuilder.Index(new BinaryOperatorExpression(" - ", stringBuilder.Length(), Int(1))).NotEqual(Literal('?')))) + new IfStatement(stringBuilder.Length().GreaterThan(pathLength).And(stringBuilder.Index(new BinaryOperatorExpression("-", stringBuilder.Length(), Int(1))).NotEqual(Literal('?')))) { stringBuilder.Append(Literal('&')).Terminate() }, @@ -353,7 +353,7 @@ private MethodProvider BuildToUriMethod() // Set the query portion if it exists new IfStatement(stringBuilder.Length().GreaterThan(pathLength)) { - UriBuilderQuery.Assign(stringBuilder.Invoke("ToString", [new BinaryOperatorExpression(" + ", pathLength, Int(1)), new BinaryOperatorExpression(" - ", new BinaryOperatorExpression(" - ", stringBuilder.Length(), pathLength), Int(1))])).Terminate() + UriBuilderQuery.Assign(stringBuilder.Invoke("ToString", [new BinaryOperatorExpression("+", pathLength, Int(1)), new BinaryOperatorExpression("-", new BinaryOperatorExpression("-", stringBuilder.Length(), pathLength), Int(1))])).Terminate() }, new IfStatement(stringBuilder.Length().Equal(pathLength)) { diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Internal/ClientUriBuilder.cs b/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Internal/ClientUriBuilder.cs index b3b65c2d894..175c84b6875 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Internal/ClientUriBuilder.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Internal/ClientUriBuilder.cs @@ -22,9 +22,9 @@ public ClientUriBuilder() { } - private UriBuilder UriBuilder => _uriBuilder ??= new UriBuilder(); + private UriBuilder UriBuilder => _uriBuilder ??= new UriBuilder(); - private StringBuilder PathAndQuery => _pathAndQuery ??= new StringBuilder(); + private StringBuilder PathAndQuery => _pathAndQuery ??= new StringBuilder(); public void Reset(Uri uri) { @@ -40,13 +40,13 @@ public void AppendPath(string value, bool escape) { value = Uri.EscapeDataString(value); } - if (_pathLength > 0 && PathAndQuery[_pathLength - 1] == '/' && value[0] == '/') + if (_pathLength > 0 && PathAndQuery[_pathLength - 1] == '/' && value[0] == '/') { - PathAndQuery.Remove(_pathLength - 1, 1); - _pathLength = _pathLength - 1; + PathAndQuery.Remove(_pathLength - 1, 1); + _pathLength = _pathLength - 1; } PathAndQuery.Insert(_pathLength, value); - _pathLength = _pathLength + value.Length; + _pathLength = _pathLength + value.Length; } public void AppendPath(bool value, bool escape = false) => AppendPath(TypeFormatters.ConvertToString(value), escape); @@ -80,7 +80,7 @@ public void AppendQuery(string name, string value, bool escape) { PathAndQuery.Append('?'); } - if (PathAndQuery.Length > _pathLength && PathAndQuery[PathAndQuery.Length - 1] != '?') + if (PathAndQuery.Length > _pathLength && PathAndQuery[PathAndQuery.Length - 1] != '?') { PathAndQuery.Append('&'); } @@ -127,7 +127,7 @@ public Uri ToUri() UriBuilder.Path = PathAndQuery.ToString(0, _pathLength); if (PathAndQuery.Length > _pathLength) { - UriBuilder.Query = PathAndQuery.ToString(_pathLength + 1, PathAndQuery.Length - _pathLength - 1); + UriBuilder.Query = PathAndQuery.ToString(_pathLength + 1, PathAndQuery.Length - _pathLength - 1); } if (PathAndQuery.Length == _pathLength) {