Skip to content

Commit 5306c73

Browse files
authored
feat: IDE type navigation assistance for command classes (#1373)
1 parent b2be4f3 commit 5306c73

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,37 @@ private void generateClientCommand() {
210210
.protocolGenerator(protocolGenerator)
211211
.applicationProtocol(applicationProtocol)
212212
.build());
213+
214+
{
215+
// This block places the most commonly sought type definitions
216+
// closer to the command definition, for navigation assistance
217+
// in IDEs.
218+
Shape operationInputShape = model.expectShape(operation.getInputShape());
219+
Symbol baseInput = symbolProvider.toSymbol(operationInputShape);
220+
Shape operationOutputShape = model.expectShape(operation.getOutputShape());
221+
Symbol baseOutput = symbolProvider.toSymbol(operationOutputShape);
222+
223+
writer.write("/** @internal type navigation helper, not in runtime. */");
224+
writer.openBlock("declare protected static __types: {", "};", () -> {
225+
String baseInputStr = operationInputShape.getAllMembers().isEmpty()
226+
? "{}"
227+
: baseInput.getName();
228+
String baseOutputStr = operationOutputShape.getAllMembers().isEmpty()
229+
? "{}"
230+
: baseOutput.getName();
231+
writer.write("""
232+
api: {
233+
input: $L;
234+
output: $L;
235+
};""", baseInputStr, baseOutputStr);
236+
writer.write("""
237+
sdk: {
238+
input: $T;
239+
output: $T;
240+
};""", inputType, outputType);
241+
});
242+
}
243+
213244
writer.write("}"); // class close bracket.
214245
}
215246

0 commit comments

Comments
 (0)