Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide snippet completions for @param in JSDoc #52370

Closed
DanielRosenwasser opened this issue Jan 23, 2023 · 7 comments · Fixed by #53260
Closed

Provide snippet completions for @param in JSDoc #52370

DanielRosenwasser opened this issue Jan 23, 2023 · 7 comments · Fixed by #53260
Assignees
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Domain: JSDoc Relates to JSDoc parsing and type generation Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fix Available A PR has been opened for this issue Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jan 23, 2023

/**
 * @para$
 */
function printValue(value, maximumFractionDigits) {
}

Today, we provide the expected @param JSDoc tag completion.

However, if we're going by the book with JSDoc, the name of the parameter is already known. Can we provide snippet completions that contain the name of the parameter?

Thoughts:

  1. This should work in both JS and TS.
  2. In TS it should have a placeholder by the comment
  3. In JS it should have a placeholder that starts on the type, followed by a placeholder at the comment
  4. I don't know (/remember) how this should work with destructuring.
@DanielRosenwasser DanielRosenwasser added Suggestion An idea for TypeScript In Discussion Not yet reached consensus Domain: Completion Lists The issue relates to showing completion lists in an editor Domain: JSDoc Relates to JSDoc parsing and type generation Help Wanted You can do this Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". and removed In Discussion Not yet reached consensus labels Jan 23, 2023
@DanielRosenwasser DanielRosenwasser modified the milestone: Backlog Jan 25, 2023
@ufukbakan
Copy link

snippet completors related to IDEs, not directly to typescript. However I guess you use VSCode and it already does what you want.
Write your function, go to the line just before your function, type /** then hit enter, it should autocomplete params and names

@DanielRosenwasser
Copy link
Member Author

DanielRosenwasser commented Jan 30, 2023

snippet completors related to IDEs, not directly to typescript.

TypeScript provides certain snippet completions for IDEs, such as object and class member completions and switch/case completions.

However I guess you use VSCode and it already does what you want.

It doesn't work if you have a preceding JSDoc comment declared using a @typedef or an @overload tag.

/** @typedef {string} Id */

/**<- No comment scaffolding here
function foo(x, y, z) {
}

@DanielRosenwasser
Copy link
Member Author

Actually, that is itself TypeScript bug on the docCommentTemplate command - I likely wouldn't have filed this issue if TypeScript actually provided that.

@DanielRosenwasser
Copy link
Member Author

I still think things like the @type tag and @typedef tag would be good as snippets, because I can never remember the names of these things.

@ufukbakan
Copy link

ufukbakan commented Feb 14, 2023

snippet completors related to IDEs, not directly to typescript.

TypeScript provides certain snippet completions for IDEs, such as object and class member completions and switch/case completions.

However I guess you use VSCode and it already does what you want.

It doesn't work if you have a preceding JSDoc comment declared using a @typedef or an @overload tag.

/** @typedef {string} Id */

/**<- No comment scaffolding here
function foo(x, y, z) {
}

Best thing you can do right now is inserting the line _; after your type def. For example:

/** @typedef {string} Id */
_;
/** <- will autocomplete
function foo(x, y, z) {
}

When finished coding you can replace _; lines with empty string using CTRL+H, I still think its about vscode not typescript

@DanielRosenwasser
Copy link
Member Author

Thank you for the suggestions; however, I am a maintainer of the product and am aware of the workarounds.

@DanielRosenwasser
Copy link
Member Author

Things like

  • @type
  • @satisfies

and more might be worthwhile to offer as snippet completions here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Domain: JSDoc Relates to JSDoc parsing and type generation Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fix Available A PR has been opened for this issue Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants