Skip to content

Sort JSDoc @param completions by argument position#63306

Closed
Vi-Ku wants to merge 1 commit intomicrosoft:mainfrom
Vi-Ku:fix/jsdoc-param-sort-20183
Closed

Sort JSDoc @param completions by argument position#63306
Vi-Ku wants to merge 1 commit intomicrosoft:mainfrom
Vi-Ku:fix/jsdoc-param-sort-20183

Conversation

@Vi-Ku
Copy link
Copy Markdown

@Vi-Ku Vi-Ku commented Mar 27, 2026

Fixes #20183

Problem

When writing JSDoc @param tags, the completions for parameter names are sorted alphabetically instead of by their position in the function signature.

For example, given:

/**
 * @param |
 */
function foo(z, a) {}

Triggering completions at | returns a before z, because both entries have the same sortText value ("11" / LocationPriority), causing the editor to fall back to alphabetical sorting.

Fix

Set sortText for each JSDoc @param completion to LocationPriority + parameterIndex (e.g., "110", "111", "112"). This ensures completions appear in the same order as the function's parameter list.

Changes:

  • src/services/completions.ts: Updated getJSDocParameterCompletions to use parameter index in sortText for both named and destructuring parameters
  • src/services/jsDoc.ts: Updated getJSDocParameterNameCompletions to use parameter index in sortText
  • Updated existing tests and baselines to reflect new sortText values
  • Added new test jsdocParameterNameSortOrder.ts that explicitly verifies the sort order

…0183)

Previously, all JSDoc @param completion entries used the same sortText
value, causing editors to sort them alphabetically by name rather than
by their position in the function signature.

This fix sets sortText to LocationPriority + parameterIndex so that
completions appear in declaration order (e.g., for function foo(z, a),
'z' appears before 'a').
@RyanCavanaugh
Copy link
Copy Markdown
Member

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Sort jsdoc parameter suggestions by argument position

2 participants