Skip to content

Commit

Permalink
updated and add testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mzhongl524 committed Dec 18, 2024
1 parent 7369d0f commit f87e06b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 12 deletions.
30 changes: 18 additions & 12 deletions packages/compiler/src/core/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2928,25 +2928,31 @@ 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 (base) {
if (base.flags & SymbolFlags.Alias) {
base = getAliasedSymbol(base, undefined);
}
if (base && (base.exports || base.members)) {
addCompletions(base.exports ?? base.members);
} else if (base?.node === undefined && base?.declarations) {

if (identifier.parent.selector === "::") {
if (base?.node === undefined && base?.declarations) {
// Process meta properties separately, such as `::parameters`, `::returnType`
const [nodeModels] = Object.values(base?.declarations);
if (nodeModels.kind === SyntaxKind.OperationStatement) {
const operation = nodeModels as OperationStatementNode;
addCompletion("parameters", operation.symbol);
addCompletion("returnType", operation.symbol);
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);
}
} else {
if (base) {
if (base.flags & SymbolFlags.Alias) {
base = getAliasedSymbol(base, undefined);
}
if (base) {
addCompletions(base.exports ?? base.members);
}
}
}
} else {
// We will only add template arguments if the template isn't already named
Expand Down
61 changes: 61 additions & 0 deletions packages/compiler/test/server/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,67 @@ describe("identifiers", () => {
]);
});

it("completes meta property '::type' on model property", async () => {
const completions = await complete(
`
model A{
name: string;
}
model B{
a: A;
}
model C {
...B.a::┆;
}
`,
);

check(completions, [
{
label: "type",
insertText: "type",
kind: CompletionItemKind.Field,
documentation: {
kind: MarkupKind.Markdown,
value: "(model property)\n```typespec\nB.a: A\n```",
},
},
]);
});

it("completes meta property '::parameters' and '::returnType' on operation", async () => {
const completions = await complete(
`
op a(@doc("base doc") one: string): void;
op b is a;
@@doc(b::par┆, "override for b");
`,
);

check(completions, [
{
label: "parameters",
insertText: "parameters",
kind: CompletionItemKind.Method,
documentation: {
kind: MarkupKind.Markdown,
value: "```typespec\nop b(one: string): void\n```",
},
},
{
label: "returnType",
insertText: "returnType",
kind: CompletionItemKind.Method,
documentation: {
kind: MarkupKind.Markdown,
value: "```typespec\nop b(one: string): void\n```",
},
},
]);
});

it("completes partial identifiers", async () => {
const completions = await complete(
`
Expand Down

0 comments on commit f87e06b

Please sign in to comment.