Skip to content

Sort JSDoc parameter suggestions by argument position#63414

Open
Jah-yee wants to merge 1 commit intomicrosoft:mainfrom
Jah-yee:fix/jsdoc-param-completion-order
Open

Sort JSDoc parameter suggestions by argument position#63414
Jah-yee wants to merge 1 commit intomicrosoft:mainfrom
Jah-yee:fix/jsdoc-param-completion-order

Conversation

@Jah-yee
Copy link
Copy Markdown

@Jah-yee Jah-yee commented Apr 18, 2026

Good day

Summary

This PR fixes issue #20183 by sorting JSDoc parameter suggestions by their position in the function signature rather than alphabetically.

Problem

When triggering completions after @param in a JSDoc comment, all parameters had the same sortText (LocationPriority = "11"), causing them to be sorted alphabetically instead of by their actual position in the function.

For example, in foo(z, a):

  • Before: a and z both had sortText="11", sorted alphabetically
  • After: z (index 0) comes before a (index 1) because "00" < "01"

Solution

Modified getJSDocParameterNameCompletions in src/services/jsDoc.ts to use the parameter's array index to generate a unique sortText prefixed with its position (e.g., "00", "01", "02").

Changes

  • src/services/jsDoc.ts: Use parameter position index for sortText instead of LocationPriority

Testing

  • Compiled successfully with npm run build:compiler
  • The fix follows the same pattern as other completion entries that use position-based sorting

Thank you for your attention. If there are any issues or suggestions, please leave a comment and I will address them promptly.

Warmly,
RoomWithOutRoof

Fixes microsoft#20183

When triggering completions after @param in a JSDoc comment,
parameter suggestions are now sorted by their position in the
function signature, so 'z' from foo(z, a) appears before 'a'.

Previously all parameters had the same sortText (LocationPriority),
causing them to be sorted alphabetically instead of by position.

Co-Authored-By: RoomWithOutRoof <[email protected]>
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Apr 18, 2026
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Apr 18, 2026
@typescript-bot
Copy link
Copy Markdown
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@jakebailey
Copy link
Copy Markdown
Member

Please disclaim what tool you have used to send this PR

https://github.com/microsoft/TypeScript/blob/main/CONTRIBUTING.md#use-of-ai-assistance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

3 participants