From f71eb301cb96447c46eb1106048181b6537ec92e Mon Sep 17 00:00:00 2001 From: "Zhonglei Ma (WICRESOFT NORTH AMERICA LTD)" Date: Thu, 19 Dec 2024 11:18:42 +0800 Subject: [PATCH] updated and add a testing --- packages/compiler/src/core/checker.ts | 38 +++++++++---------- .../compiler/test/server/completion.test.ts | 30 +++++++++++++++ 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/packages/compiler/src/core/checker.ts b/packages/compiler/src/core/checker.ts index 8b9ac64683..9f8967b663 100644 --- a/packages/compiler/src/core/checker.ts +++ b/packages/compiler/src/core/checker.ts @@ -2929,27 +2929,27 @@ export function createChecker(program: Program, resolver: NameResolver): Checker } else if (identifier.parent && identifier.parent.kind === SyntaxKind.MemberExpression) { let base = resolver.getNodeLinks(identifier.parent.base).resolvedSymbol; - if (identifier.parent.selector === "::") { - if (base?.node === undefined && base?.declarations) { - // Process meta properties separately, such as `::parameters`, `::returnType` - for (const nodeModels of Object.values(base?.declarations)) { - if (nodeModels.kind === SyntaxKind.OperationStatement) { - const operation = nodeModels as OperationStatementNode; - addCompletion("parameters", operation.symbol); - addCompletion("returnType", operation.symbol); - } - } - } else if (base?.node?.kind === SyntaxKind.ModelProperty) { - // Process meta properties separately, such as `::type` - const metaProperty = base.node as ModelPropertyNode; - addCompletion("type", metaProperty.symbol); + if (base) { + if (base.flags & SymbolFlags.Alias) { + base = getAliasedSymbol(base, undefined); } - } else { + if (base) { - if (base.flags & SymbolFlags.Alias) { - base = getAliasedSymbol(base, undefined); - } - if (base) { + if (identifier.parent.selector === "::") { + if (base?.node === undefined && base?.declarations && base.declarations.length > 0) { + // Process meta properties separately, such as `::parameters`, `::returnType` + const nodeModels = base?.declarations[0]; + if (nodeModels.kind === SyntaxKind.OperationStatement) { + const operation = nodeModels as OperationStatementNode; + addCompletion("parameters", operation.symbol); + addCompletion("returnType", operation.symbol); + } + } else if (base?.node?.kind === SyntaxKind.ModelProperty) { + // Process meta properties separately, such as `::type` + const metaProperty = base.node as ModelPropertyNode; + addCompletion("type", metaProperty.symbol); + } + } else { addCompletions(base.exports ?? base.members); } } diff --git a/packages/compiler/test/server/completion.test.ts b/packages/compiler/test/server/completion.test.ts index 91d4f8c8b8..0efecc6bb5 100644 --- a/packages/compiler/test/server/completion.test.ts +++ b/packages/compiler/test/server/completion.test.ts @@ -510,6 +510,36 @@ describe("identifiers", () => { }); it("completes meta property '::parameters' and '::returnType' on operation", async () => { + const completions = await complete( + ` + op base(one: string): void; + @@doc(base::par┆, "Override"); + `, + ); + + check(completions, [ + { + label: "parameters", + insertText: "parameters", + kind: CompletionItemKind.Method, + documentation: { + kind: MarkupKind.Markdown, + value: "```typespec\nop base(one: string): void\n```", + }, + }, + { + label: "returnType", + insertText: "returnType", + kind: CompletionItemKind.Method, + documentation: { + kind: MarkupKind.Markdown, + value: "```typespec\nop base(one: string): void\n```", + }, + }, + ]); + }); + + it("completes meta property '::parameters' and '::returnType' using alias on operation", async () => { const completions = await complete( ` op a(@doc("base doc") one: string): void;