Skip to content

Commit

Permalink
feat: IDE type navigation assistance for command classes (#1373)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Sep 13, 2024
1 parent b2be4f3 commit 5306c73
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,37 @@ private void generateClientCommand() {
.protocolGenerator(protocolGenerator)
.applicationProtocol(applicationProtocol)
.build());

{
// This block places the most commonly sought type definitions
// closer to the command definition, for navigation assistance
// in IDEs.
Shape operationInputShape = model.expectShape(operation.getInputShape());
Symbol baseInput = symbolProvider.toSymbol(operationInputShape);
Shape operationOutputShape = model.expectShape(operation.getOutputShape());
Symbol baseOutput = symbolProvider.toSymbol(operationOutputShape);

writer.write("/** @internal type navigation helper, not in runtime. */");
writer.openBlock("declare protected static __types: {", "};", () -> {
String baseInputStr = operationInputShape.getAllMembers().isEmpty()
? "{}"
: baseInput.getName();
String baseOutputStr = operationOutputShape.getAllMembers().isEmpty()
? "{}"
: baseOutput.getName();
writer.write("""
api: {
input: $L;
output: $L;
};""", baseInputStr, baseOutputStr);
writer.write("""
sdk: {
input: $T;
output: $T;
};""", inputType, outputType);
});
}

writer.write("}"); // class close bracket.
}

Expand Down

0 comments on commit 5306c73

Please sign in to comment.