Skip to content

Conversation

@murataslan1
Copy link

Fixes #20183

Problem

When triggering completions after @param in a JSDoc comment, parameter suggestions were sorted alphabetically instead of by their position in the function signature.

For example, with function foo(z, a) {}:

  • Before: Completions showed a, z (alphabetical)
  • After: Completions show z, a (argument order)

Solution

Modified getJSDocParameterNameCompletions() in src/services/jsDoc.ts to use the parameter index when generating the sortText value. This ensures parameters are displayed in the order they appear in the function definition.

Testing

  • Updated existing test jsdocParameterNameCompletion.ts to verify sort order
  • All jsdocParam* tests pass (43 tests)

Made with Cursor

Fixes microsoft#20183

When triggering completions after `@param` in a JSDoc comment, parameter
suggestions are now sorted by their position in the function signature
rather than alphabetically.

Before: For `function foo(z, a) {}`, completions showed `a`, `z`
After: Completions now show `z`, `a` (matching argument order)

The fix uses the parameter index to generate a unique sortText value,
ensuring the IDE displays parameters in the order they appear in the
function definition. This makes it easier to document parameters in
the correct order.

Co-authored-by: Cursor <[email protected]>
Copilot AI review requested due to automatic review settings February 2, 2026 11:08
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Feb 2, 2026
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Feb 2, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts JSDoc @param name completions to be ordered by the function’s parameter list position instead of alphabetically (fixes #20183).

Changes:

  • Update getJSDocParameterNameCompletions() to incorporate the parameter index into sortText, ensuring stable ordering by signature position.
  • Update the existing fourslash test to assert the ordered results (and expected sortText values).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/services/jsDoc.ts Generates sortText with a zero-padded parameter index so completions sort by signature order.
tests/cases/fourslash/jsdocParameterNameCompletion.ts Adds assertions to verify completion ordering (and sortText) matches parameter positions.

Comment on lines +28 to +35
// sortText uses LocationPriority ("11") + zero-padded index to maintain argument order
const locationPriority = completion.SortText.LocationPriority;
verify.completions(
{ marker: ["0", "3", "4"], exact: ["foo", "bar"] },
{ marker: "1", exact: "bar" },
{ marker: "2", exact: ["canary", "canoodle"] },
{
marker: ["0", "3", "4"],
exact: [
{ name: "foo", sortText: locationPriority + "0000" },
{ name: "bar", sortText: locationPriority + "0001" },
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

completion.SortText is a branded string type; using locationPriority + "0000" produces a plain string, which is not type-compatible with completion.SortText. Consider constructing the expected sortText values as completion.SortText (e.g., via an explicit cast or small helper that returns completion.SortText) to keep the test type-safe and resilient to harness type checking changes.

Copilot uses AI. Check for mistakes.
Comment on lines +39 to +42
marker: "1",
// bar is the second parameter (index 1), already documented foo is filtered out
exact: { name: "bar", sortText: locationPriority + "0001" },
},
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same type-safety issue here: locationPriority + "0001" results in an unbranded string, but sortText is typed as completion.SortText in the fourslash harness types. Prefer constructing/casting to completion.SortText (or using a helper) for the expected entry.

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +48
{ name: "foo", sortText: locationPriority + "0000" },
{ name: "bar", sortText: locationPriority + "0001" },
],
},
{
marker: "1",
// bar is the second parameter (index 1), already documented foo is filtered out
exact: { name: "bar", sortText: locationPriority + "0001" },
},
{
marker: "2",
// canary is index 1, canoodle is index 2 (cat=0, cantaloupe=3 filtered)
exact: [
{ name: "canary", sortText: locationPriority + "0001" },
{ name: "canoodle", sortText: locationPriority + "0002" },
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same type-safety issue here: locationPriority + "0001"/"0002" yields string, but the expected sortText type is completion.SortText. Consider casting or using a helper that returns completion.SortText for these concatenations.

Suggested change
{ name: "foo", sortText: locationPriority + "0000" },
{ name: "bar", sortText: locationPriority + "0001" },
],
},
{
marker: "1",
// bar is the second parameter (index 1), already documented foo is filtered out
exact: { name: "bar", sortText: locationPriority + "0001" },
},
{
marker: "2",
// canary is index 1, canoodle is index 2 (cat=0, cantaloupe=3 filtered)
exact: [
{ name: "canary", sortText: locationPriority + "0001" },
{ name: "canoodle", sortText: locationPriority + "0002" },
{ name: "foo", sortText: (locationPriority + "0000") as completion.SortText },
{ name: "bar", sortText: (locationPriority + "0001") as completion.SortText },
],
},
{
marker: "1",
// bar is the second parameter (index 1), already documented foo is filtered out
exact: { name: "bar", sortText: (locationPriority + "0001") as completion.SortText },
},
{
marker: "2",
// canary is index 1, canoodle is index 2 (cat=0, cantaloupe=3 filtered)
exact: [
{ name: "canary", sortText: (locationPriority + "0001") as completion.SortText },
{ name: "canoodle", sortText: (locationPriority + "0002") as completion.SortText },

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Sort jsdoc parameter suggestions by argument position

2 participants