Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/services/jsDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ import {
length,
lineBreakPart,
map,
mapDefined,
MethodDeclaration,
MethodSignature,
Node,
Expand Down Expand Up @@ -420,19 +419,21 @@ export function getJSDocParameterNameCompletions(tag: JSDocParameterTag): Comple
const fn = jsdoc.parent;
if (!isFunctionLike(fn)) return [];

return mapDefined(fn.parameters, param => {
if (!isIdentifier(param.name)) return undefined;
const entries: CompletionEntry[] = [];
for (const param of fn.parameters) {
if (!isIdentifier(param.name)) continue;

const name = param.name.text;
if (
jsdoc.tags!.some(t => t !== tag && isJSDocParameterTag(t) && isIdentifier(t.name) && t.name.escapedText === name) // TODO: GH#18217
|| nameThusFar !== undefined && !startsWith(name, nameThusFar)
) {
return undefined;
continue;
}

return { name, kind: ScriptElementKind.parameterElement, kindModifiers: "", sortText: Completions.SortText.LocationPriority };
});
entries.push({ name, kind: ScriptElementKind.parameterElement, kindModifiers: "", sortText: Completions.SortText.LocationPriority });
}
return entries;
}

/** @internal */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference path="fourslash.ts" />

// Expectation: Only 'a' is suggested because 'z' is already documented.
//// /**
//// * @param z
//// * @param /*1*/
//// */
//// function foo(z: number, a: number) {}

verify.completions({ marker: "1", exact: ["a"] });


14 changes: 14 additions & 0 deletions tests/cases/fourslash/jsDocParamCompletion_jsFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />
// @allowJs: true
// @Filename: a.js

// Expectation (JS): Declaration order is preserved: 'z' before 'a'.
//// /**
//// * @param /*1*/
//// */
//// function foo(z, a) {}

goTo.file("a.js");
verify.completions({ marker: "1", exact: ["z", "a"] });


11 changes: 11 additions & 0 deletions tests/cases/fourslash/jsDocParamCompletion_optionalAndRest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />

// Expectation: Declaration order is preserved: 'a' (optional) before 'z' (rest).
//// /**
//// * @param /*1*/
//// */
//// function foo(a?: number, ...z: number[]) {}

verify.completions({ marker: "1", exact: ["a", "z"] });


16 changes: 16 additions & 0 deletions tests/cases/fourslash/jsDocParamCompletion_order.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />

//// /**
//// * @param /*1*/
//// */
//// function foo(z: number, a: number) {}

verify.completions({
marker: "1",
exact: ["z", "a"], // expected: declaration order
});

/**
* @param |
*/
function foo(z: number, a: number) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference path="fourslash.ts" />

// Expectation: Suggestions are based on the implementation signature: 'a', then 'z'.
//// /**
//// * @param /*1*/
//// */
//// function foo(a: number, z: number): void;
//// function foo(a: number, z: number): void {}

verify.completions({ marker: "1", exact: ["a", "z"] });


11 changes: 11 additions & 0 deletions tests/cases/fourslash/jsDocParamCompletion_prefixFiltering.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />

// Expectation: Only 'a' is suggested due to prefix filtering after '@param a'.
//// /**
//// * @param a/*1*/
//// */
//// function foo(z: number, a: number) {}

verify.completions({ marker: "1", exact: ["a"] });


11 changes: 11 additions & 0 deletions tests/cases/fourslash/jsDocParamCompletion_skipDestructured.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />

// Expectation: Destructured parameter is skipped; only identifier param 'z' is suggested.
//// /**
//// * @param /*1*/
//// */
//// function foo({ x }: any, z: number) {}

verify.completions({ marker: "1", exact: ["z"] });