Skip to content

Provide snippet completions for @param in JSDoc #52370

Description

/**
 * @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.

Activity

  1. added
    SuggestionAn idea for TypeScript
    Domain: LS: Completion ListsThe issue relates to showing completion lists in an editor
    Domain: JSDocRelates to JSDoc parsing and type generation
    Effort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".
    and removed on Jan 23, 2023
  2. ufukbakan commented on Jan 27, 2023

    @ufukbakan

    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

  3. DanielRosenwasser commented on Jan 30, 2023

    @DanielRosenwasser
    MemberAuthor

    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) {
    }
  4. DanielRosenwasser commented on Jan 30, 2023

    @DanielRosenwasser
    MemberAuthor

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

  5. DanielRosenwasser commented on Feb 4, 2023

    @DanielRosenwasser
    MemberAuthor

    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.

  6. ufukbakan commented on Feb 14, 2023

    @ufukbakan

    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

  7. DanielRosenwasser commented on Feb 14, 2023

    @DanielRosenwasser
    MemberAuthor

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

  8. DanielRosenwasser commented on Feb 24, 2023

    @DanielRosenwasser
    MemberAuthor

    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

Metadata

Metadata

Labels

Domain: JSDocRelates to JSDoc parsing and type generationDomain: LS: Completion ListsThe issue relates to showing completion lists in an editorEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Fix AvailableA PR has been opened for this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions