Skip to content

fix(completions): sort JSDoc @param suggestions by declaration order#63439

Open
creazyfrog wants to merge 1 commit intomicrosoft:mainfrom
creazyfrog:fix/jsdoc-param-sort-by-position
Open

fix(completions): sort JSDoc @param suggestions by declaration order#63439
creazyfrog wants to merge 1 commit intomicrosoft:mainfrom
creazyfrog:fix/jsdoc-param-sort-by-position

Conversation

@creazyfrog
Copy link
Copy Markdown

Summary

Fixes #20183

Problem

When triggering completions after @param in a JSDoc comment, all parameter suggestions had the same sortText: "11" (SortText.LocationPriority). This caused them to be sorted alphabetically by name rather than by their declaration order in the function signature.

/**
 * @param |
 */
function foo(z, a) {}
// Completions before fix: ["a" (sort: "11"), "z" (sort: "11")]
// Completions after fix:  ["z" (sort: "110000"), "a" (sort: "110001")]

Fix

Expose the parameter index i from the mapDefined callback and build a per-parameter sortText that encodes declaration position:

-return mapDefined(func.parameters, param => {
+return mapDefined(func.parameters, (param, paramIndex) => {
     ...
+    const sortText = (SortText.LocationPriority + String(paramIndex).padStart(4, "0")) as SortText;
     return {
         ...
-        sortText: SortText.LocationPriority,
+        sortText,
     };
 });

This produces "110000", "110001", … — parameters stay within the same priority tier ("11" prefix) but are now ordered by their position in the function signature. The fix applies to both named parameters and destructuring parameters.

When triggering completions after `@param` in a JSDoc comment, all
parameter suggestions were assigned the same sortText ("11"), causing
them to be ordered alphabetically by name rather than by their position
in the function signature.

For example, `function foo(z, a)` would suggest `a` before `z`.

Fix: expose the parameter index from the `mapDefined` callback and
compose a unique sortText per parameter:

    sortText = SortText.LocationPriority + paramIndex.padStart(4, "0")

This produces "110000", "110001", … so parameters are sorted by their
declaration order while still being grouped within the same priority
tier as other location-priority completions. The fix applies to both
named parameters and destructuring parameters.

Fixes microsoft#20183

Signed-off-by: creazyfrog <rohitcse.gec@gmail.com>
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Apr 26, 2026
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Apr 26, 2026
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