Skip to content

Commit

Permalink
Merge branch 'main' into bug/escape-characters-in-docblock
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin authored May 23, 2024
2 parents 49ac54a + 4107059 commit 69e900e
Show file tree
Hide file tree
Showing 137 changed files with 1,887 additions and 3,979 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/versioning"
---

Using `@removed` on member types and `@added` on containing type could result in errors
1 change: 1 addition & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ words:
- unsourced
- unversioned
- VITE
- vitest
- vsix
- VSSDK
- Vsts
Expand Down
2 changes: 1 addition & 1 deletion eng/common/scripts/Analyze-Changes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function Get-ActiveVariables($changes) {
}

# set global flag to run all if common files are changed
$runAll = $root.PathExists('eng/common')
$runAll = $root.PathExists('eng/common') -or $root.PathExists('vitest.config.ts')

# set global isolated package flag to run if any eng/emiters files changed
$runIsolated = $root.PathExists('eng/emitters')
Expand Down
27 changes: 12 additions & 15 deletions packages/http-client-csharp/emitter/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export async function $onEmit(context: EmitContext<NetEmitterOptions>) {
const command = `dotnet --roll-forward Major ${generatorPath} ${outputFolder} ${newProjectOption} ${existingProjectOption}${debugFlag}`;
Logger.getInstance().info(command);

await execAsync(
const result = await execAsync(
"dotnet",
[
"--roll-forward",
Expand All @@ -155,20 +155,17 @@ export async function $onEmit(context: EmitContext<NetEmitterOptions>) {
debugFlag,
],
{ stdio: "inherit" }
)
.then(() => {
if (!options["save-inputs"]) {
// delete
deleteFile(resolvePath(outputFolder, tspOutputFileName));
deleteFile(resolvePath(outputFolder, configurationFileName));
}
})
.catch((error: any) => {
if (error.message) Logger.getInstance().info(error.message);
if (error.stderr) Logger.getInstance().error(error.stderr);
if (error.stdout) Logger.getInstance().verbose(error.stdout);
throw error;
});
);
if (result.exitCode !== 0) {
if (result.stderr) Logger.getInstance().error(result.stderr);
if (result.stdout) Logger.getInstance().verbose(result.stdout);
throw new Error(`Failed to generate SDK. Exit code: ${result.exitCode}`);
}
if (!options["save-inputs"]) {
// delete
deleteFile(resolvePath(outputFolder, tspOutputFileName));
deleteFile(resolvePath(outputFolder, configurationFileName));
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/http-client-csharp/eng/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@
<Rule Id="SA1505" Action="None" /> <!-- Opening braces should not be followed by blank line -->
<Rule Id="SA1506" Action="None" /> <!-- Element documentation headers should not be followed by blank line -->
<Rule Id="SA1507" Action="None" /> <!-- Code should not contain multiple blank lines in a row -->
<Rule Id="SA1508" Action="None" /> <!-- Closing braces should not be preceded by blank line -->
<Rule Id="SA1509" Action="None" /> <!-- Opening braces should not be preceded by blank line -->
<Rule Id="SA1508" Action="Warning" /> <!-- Closing braces should not be preceded by blank line -->
<Rule Id="SA1509" Action="Warning" /> <!-- Opening braces should not be preceded by blank line -->
<Rule Id="SA1510" Action="None" /> <!-- Chained statement blocks should not be preceded by blank line -->
<Rule Id="SA1511" Action="None" /> <!-- While-do footer should not be preceded by blank line -->
<Rule Id="SA1512" Action="None" /> <!-- Single-line comments should not be followed by blank line -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.Generator.CSharp.ClientModel.Expressions;
using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Writers;

namespace Microsoft.Generator.CSharp.ClientModel
{
Expand All @@ -25,6 +25,16 @@ public class ClientModelPlugin : CodeModelPlugin

public override ExtensibleSnippets ExtensibleSnippets { get; }

/// <summary>
/// Returns the serialization type providers for the given model type provider.
/// </summary>
/// <param name="provider">The model type provider.</param>
public override IReadOnlyList<TypeProvider> GetSerializationTypeProviders(ModelTypeProvider provider)
{
// Add JSON serialization type provider
return [new MrwSerializationTypeProvider(provider)];
}

[ImportingConstructor]
public ClientModelPlugin(GeneratorContext context)
: base(context)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.ClientModel;
using Microsoft.Generator.CSharp.Expressions;

namespace Microsoft.Generator.CSharp.ClientModel.Expressions
{
internal sealed record ClientResultExpression(ValueExpression Untyped) : TypedValueExpression<ClientResult>(Untyped)
{
public ValueExpression Value => Property(nameof(ClientResult<object>.Value));
public BinaryDataExpression Content => throw new InvalidOperationException("Result does not have a Content property");
public StreamExpression ContentStream => throw new InvalidOperationException("Result does not have a ContentStream property");

public static ClientResultExpression FromResponse(PipelineResponseExpression response)
=> new(InvokeStatic(nameof(ClientResult.FromResponse), response));

public static ClientResultExpression FromValue(ValueExpression value, PipelineResponseExpression response)
=> new(InvokeStatic(nameof(ClientResult.FromValue), value, response));

public static ClientResultExpression FromValue(CSharpType explicitValueType, ValueExpression value, PipelineResponseExpression response)
=> new(new InvokeStaticMethodExpression(typeof(ClientResult), nameof(ClientResult.FromValue), new[] { value, response }, new[] { explicitValueType }));

public ClientResultExpression FromValue(ValueExpression value)
=> new(new InvokeStaticMethodExpression(typeof(ClientResult), nameof(ClientResult.FromValue), new[] { value, this }));

public ClientResultExpression FromValue(CSharpType explicitValueType, ValueExpression value)
=> new(new InvokeStaticMethodExpression(typeof(ClientResult), nameof(ClientResult.FromValue), new[] { value, this }, new[] { explicitValueType }));

public PipelineResponseExpression GetRawResponse() => new(Invoke(nameof(ClientResult<object>.GetRawResponse)));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel.Primitives;
Expand All @@ -9,5 +9,9 @@ namespace Microsoft.Generator.CSharp.ClientModel.Expressions
internal sealed record PipelineMessageExpression(ValueExpression Untyped) : TypedValueExpression<PipelineMessage>(Untyped)
{
public PipelineRequestExpression Request => new(Property(nameof(PipelineMessage.Request)));

public PipelineResponseExpression Response => new(Property(nameof(PipelineMessage.Response)));

public BoolExpression BufferResponse => new(Property(nameof(PipelineMessage.BufferResponse)));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
Expand All @@ -11,8 +11,8 @@ namespace Microsoft.Generator.CSharp.ClientModel.Expressions
internal sealed record PipelineRequestExpression(ValueExpression Untyped) : TypedValueExpression<PipelineRequest>(Untyped)
{
public TypedValueExpression Uri => new FrameworkTypeExpression(typeof(Uri), Property(nameof(PipelineRequest.Uri)));
public RequestBodyExpression Content => new(Property(nameof(PipelineRequest.Content)));
public MethodBodyStatement SetMethod(string method) => new InvokeInstanceMethodStatement(Untyped, nameof(PipelineRequest.SetMethod), Literal(method));
public MethodBodyStatement SetHeaderValue(string name, StringExpression value) => new InvokeInstanceMethodStatement(Untyped, nameof(PipelineRequest.SetHeaderValue), Literal(name), value);
public MethodBodyStatement SetMethod(string method) => Assign(Untyped.Property("Method"), Literal(method));
public MethodBodyStatement SetHeaderValue(string name, StringExpression value)
=> new InvokeInstanceMethodStatement(Untyped.Property(nameof(PipelineRequest.Headers)), nameof(PipelineRequestHeaders.Set), Literal(name), value);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel;
using System.ClientModel.Primitives;
using Microsoft.Generator.CSharp.Expressions;


Expand All @@ -10,6 +10,8 @@ namespace Microsoft.Generator.CSharp.ClientModel.Expressions
internal sealed record RequestOptionsExpression(ValueExpression Untyped) : TypedValueExpression<RequestOptions>(Untyped)
{
public static RequestOptionsExpression FromCancellationToken()
=> new(new InvokeStaticMethodExpression(null, nameof(FromCancellationToken), new ValueExpression[] { KnownParameters.CancellationTokenParameter }));
=> new(new InvokeStaticMethodExpression(null, "FromCancellationToken", new ValueExpression[] { KnownParameters.CancellationTokenParameter }));

public ValueExpression ErrorOptions => Property(nameof(RequestOptions.ErrorOptions));
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.ClientModel.Internal;
using System.ClientModel.Primitives;
using Microsoft.Generator.CSharp.Expressions;

Expand All @@ -12,21 +10,6 @@ internal partial class SystemExtensibleSnippets
{
internal class SystemModelSnippets : ModelSnippets
{
public override CSharpMethod BuildConversionToRequestBodyMethod(MethodSignatureModifiers modifiers)
{
return new CSharpMethod
(
new MethodSignature(ClientModelPlugin.Instance.Configuration.ApiTypes.ToRequestContentName, null, $"Convert into a {nameof(Utf8JsonRequestBody)}.", modifiers, typeof(RequestBody), null, Array.Empty<Parameter>()),
new[]
{
Snippets.Extensible.RestOperations.DeclareContentWithUtf8JsonWriter(out var requestContent, out var writer),
writer.WriteObjectValue(Snippets.This),
Snippets.Return(requestContent)
},
"default"
);
}

public override CSharpMethod BuildFromOperationResponseMethod(TypeProvider typeProvider, MethodSignatureModifiers modifiers)
{
var result = new Parameter("response", $"The result to deserialize the model from.", typeof(PipelineResponse), null, ValidationType.None, null);
Expand All @@ -41,8 +24,6 @@ public override CSharpMethod BuildFromOperationResponseMethod(TypeProvider typeP
"default"
);
}

public override TypedValueExpression InvokeToRequestBodyMethod(TypedValueExpression model) => new RequestBodyExpression(model.Invoke("ToRequestBody"));
}
}
}
Loading

0 comments on commit 69e900e

Please sign in to comment.