Skip to content

Commit

Permalink
Include template arguments for operation in intellisense (#3183)
Browse files Browse the repository at this point in the history
fix #2423 

Include template arguments for operation in intellisense

---------

Co-authored-by: Timothee Guerin <[email protected]>
  • Loading branch information
RodgeFu and timotheeguerin authored Apr 18, 2024
1 parent 1265330 commit 9fcc90f
Show file tree
Hide file tree
Showing 6 changed files with 484 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/compiler"
---

Show template parameters when hovering on an operation template
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));
opName += `<${params.join(", ")}>`;
}
const prefix = op.interface
? getInterfaceName(op.interface, options) + "."
: getNamespacePrefix(op.namespace, options);
return `${prefix}${opName}`;
}

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

0 comments on commit 9fcc90f

Please sign in to comment.