Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OpenCode.Sdk/Events/Internal/EventsRawClient.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using OpenCode.Sdk.Tools.Generator.Binding.Models;
using OpenCode.Sdk.Tools.Generator.Emission;
using OpenCode.Sdk.Tools.Tests.Generator.Emission.Support;
using OpenCode.Sdk.Tools.Tests.Support;
Expand Down Expand Up @@ -86,4 +87,20 @@ await Assert
var diagnostics = await GeneratedSourceCompiler.CompileWithSdkCoreAsync(sources);
await Assert.That(diagnostics).IsEmpty();
}

[Test]
[Arguments(false, "The per-call options; NoThrow is refused. NetworkTimeout bounds only the opening and is refused for reconnecting streams, including Timeout.InfiniteTimeSpan.")]
[Arguments(true, "The per-call options; the family's hand-written owner decides which apply.")]
public async Task Emit_Should_Document_Stream_Request_Options_By_Family_Emission(bool internalRaw, string expected)
{
var plan = await EmitterPlanFixture.CreateStreamPlanAsync();
var operation = plan.Clients.SelectMany(static client => client.Operations).Single();

var xml = OperationMethodEmitter
.Emit(operation, internalRaw ? EmissionMode.InternalRaw : EmissionMode.Public)
.GetLeadingTrivia()
.ToFullString();

await Assert.That(xml).Contains($"/// <param name=\"requestOptions\">{expected}</param>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static MethodDeclarationSyntax Emit(OperationPlan operation, EmissionMode
.AddAttributeLists(ExperimentalAttributeSyntax.Emit(emission is EmissionMode.Public && !classMarked ? operation.ExperimentalDiagnostic : null))
.WithParameterList(SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(EmitParameters(operation, methodParameters))))
.WithBody(SyntaxFactory.Block(statements))
.WithLeadingTrivia(EmitDocumentation(operation, methodParameters));
.WithLeadingTrivia(EmitDocumentation(operation, emission, methodParameters));
}

/// <summary>
Expand Down Expand Up @@ -252,7 +252,20 @@ private static ExpressionSyntax EmitRoute(OperationPlan operation)
return EmissionSyntax.Invocation(member, [.. arguments]);
}

private static SyntaxTriviaList EmitDocumentation(OperationPlan operation, IReadOnlyList<OperationParameterPlan> methodParameters)
/// <summary>
/// Describes the per-call options. An internal-raw stream's family has a hand-written owner that
/// decides which per-call options apply, so the caller-facing stream rules do not describe it.
/// </summary>
private static string RequestOptionsDocumentation(OperationPlan operation, EmissionMode emission) =>
(operation.Stream, emission) switch
{
(null, _) => "The per-call options.",
(_, EmissionMode.InternalRaw) => "The per-call options; the family's hand-written owner decides which apply.",
_ => "The per-call options; NoThrow is refused. NetworkTimeout bounds only the opening and is refused for reconnecting streams, including Timeout.InfiniteTimeSpan.",
};

private static SyntaxTriviaList EmitDocumentation(OperationPlan operation, EmissionMode emission,
IReadOnlyList<OperationParameterPlan> methodParameters)
{
var parameters = new List<DocumentedParameter>();
parameters.AddRange(methodParameters.Select(static parameter =>
Expand Down Expand Up @@ -285,9 +298,7 @@ private static SyntaxTriviaList EmitDocumentation(OperationPlan operation, IRead
parameters.AddRange(operation.DeclaredHeaders.Select(static header =>
new DocumentedParameter(header.Name, $"The '{header.WireName}' request header; omitted when null.")));

parameters.Add(new DocumentedParameter(ReservedNamePolicy.RequestOptionsParameter, operation.Stream is null
? "The per-call options."
: "The per-call options; NoThrow is refused. NetworkTimeout bounds only the opening and is refused for reconnecting streams, including Timeout.InfiniteTimeSpan."));
parameters.Add(new DocumentedParameter(ReservedNamePolicy.RequestOptionsParameter, RequestOptionsDocumentation(operation, emission)));

parameters.Add(new DocumentedParameter(ReservedNamePolicy.CancellationTokenParameter, "The cancellation token."));

Expand Down
Loading