Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include template arguments for operation in intellisense #3183

Merged
merged 13 commits into from
Apr 18, 2024
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
RodgeFu marked this conversation as resolved.
Show resolved Hide resolved
packages:
- "@typespec/compiler"
---

Show template arguments when hoving on an operation template
RodgeFu marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 10 additions & 1 deletion packages/compiler/src/core/helpers/type-name-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,16 @@ function getInterfaceName(iface: Interface, options: TypeNameOptions | undefined
}

function getOperationName(op: Operation, options: TypeNameOptions | undefined) {
return `${getNamespacePrefix(op.namespace, options)}${getIdentifierName(op.name, options)}`;
let opName = getIdentifierName(op.name, options);
if (op.node.templateParameters.length > 0) {
// template
const params = op.node.templateParameters.map((t) => getIdentifierName(t.id.sv, options));
timotheeguerin marked this conversation as resolved.
Show resolved Hide resolved
opName += `<${params.join(", ")}>`;
}
const prefix = op.interface
? getInterfaceName(op.interface, options) + "."
: getNamespacePrefix(op.namespace, options);
return `${prefix}${opName}`;
}
timotheeguerin marked this conversation as resolved.
Show resolved Hide resolved

function getIdentifierName(name: string, options: TypeNameOptions | undefined) {
Expand Down
3 changes: 1 addition & 2 deletions packages/compiler/src/server/type-signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ function getFunctionSignature(type: FunctionType) {
}

function getOperationSignature(type: Operation) {
const ns = getQualifier(type.namespace) || getQualifier(type.interface);
const parameters = [...type.parameters.properties.values()].map(getModelPropertySignature);
return `op ${ns}${type.name}(${parameters.join(", ")}): ${getPrintableTypeName(type.returnType)}`;
return `op ${getTypeName(type)}(${parameters.join(", ")}): ${getPrintableTypeName(type.returnType)}`;
}

function getFunctionParameterSignature(parameter: FunctionParameter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ describe("compiler: projector: Identity", () => {
}`,
ref: "Foo.one",
expectedTypes: [
["Operation", "one"],
["Operation", "Foo.one"],
["Interface", "Foo"],
],
});
Expand Down
Loading
Loading