Skip to content

Commit

Permalink
updated and add a testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mzhongl524 committed Dec 19, 2024
1 parent f87e06b commit f71eb30
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
38 changes: 19 additions & 19 deletions packages/compiler/src/core/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
30 changes: 30 additions & 0 deletions packages/compiler/test/server/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f71eb30

Please sign in to comment.