zerefel
zerefel

Reputation: 1869

Is there a way to generate JSDoc comments in Visual Studio Code

I am currently developing a NodeJS project and found out that there is no built in functionality to create JSDoc comments for functions/methods.

I am aware of the TypeScript definitions that exist but I couldn't really find anything to match what I need.

WebStorm, for example, has some pretty neat JSDoc functionalities. Can one somehow achieve a similar functionality?

Upvotes: 173

Views: 160859

Answers (8)

Dominic
Dominic

Reputation: 4952

Visual Studio Code 1.10 is now able to generate JSDoc comments.

Just type /** above the function

screenshot of Visual Studio Code UI assisting with the generation of a JSDoc comment

See Also:

Upvotes: 320

greuze
greuze

Reputation: 4398

The best result for me (in 2023) was with JSDoc Generator:

https://marketplace.visualstudio.com/items?itemName=crystal-spider.jsdoc-generator

It was the only one that I found that works fine, as VS Code integrated JSDoc comment didn't add the types, oouo-diogo-perdigao.docthis didn't add the types properly in @return, several old extensions were dead, etc.

Upvotes: 3

user3511732
user3511732

Reputation: 15

Document this has worked perfectly for me

Upvotes: -3

Corky3892
Corky3892

Reputation: 535

For anyone who, like me, is to lazy to type /** every time they want to insert some JSDoc comments I found the following solution to be quite effective. Note this is implemented with code-server 3.12.0

  1. Install the macros extension https://github.com/geddski/macros
  2. Add the following block to your settings.json
"macros": {
  "JSDoc": [
    {"command": "type", "args": {"text": "/**"}},
    "insertSnippet"
  ]
} 
  1. Add the following to your keybindings.json
{
  "key": "ctrl+shift+/",
  "command": "macros.JSDoc",
  "when": "editorFocus"
}

Now whenever you type ctrl+shift+/ intellisense autocomplete will pop-up, hit enter and enjoy.

Upvotes: 4

Ashu Sahu
Ashu Sahu

Reputation: 601

https://marketplace.visualstudio.com/items?itemName=kimlimjustin.jsdoc-generator

just select the whole function till the first block { and command vscode to generate jsdoc. works with arrow functions/typescript.

Upvotes: 0

Jack Vial
Jack Vial

Reputation: 2474

I really like "Document This".

Installation

Launch VS Code Quick Open (⌘+P), paste the following command, and press enter.
ext install docthis

https://marketplace.visualstudio.com/items?itemName=oouo-diogo-perdigao.docthis

It has some nice features like adding doc blocks to an entire file.

Upvotes: 39

Manohar Reddy Poreddy
Manohar Reddy Poreddy

Reputation: 27395

A related one.

I was finding for Visual Studio 2017 Community edition, below helped:

https://marketplace.visualstudio.com/items?itemName=MichaelObermeyer.DocStubsJs2017

Upvotes: 2

Benjamin Pasero
Benjamin Pasero

Reputation: 123744

Maybe give this JSDoc extension a try: https://marketplace.visualstudio.com/items/stevencl.addDocComments

You can install extensions in VS Code from View > Command Palette

Install Extensions

Upvotes: 17

Related Questions