157

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?

zerefel
  • 1,699
  • 2
  • 11
  • 13

8 Answers8

286

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:

MDD
  • 147
  • 9
Dominic
  • 4,572
  • 3
  • 25
  • 36
  • 8
    Nice feature! Yet it doesn't seem to work with fat-arrow functions, and it doesn't add @returns and {type} for some reason--at least on my setup. Just a heads up that people might consider using a 3-party plugin :). – iMe Jan 10 '18 at 10:33
  • 2
    For @returns you can keep an eye on this ticket: https://github.com/Microsoft/TypeScript/issues/14248 – Dominic Jan 10 '18 at 13:33
  • 2
    My visual studio code version is 1.24.1 . Still @returns is not added. – Tanmay Patil Jul 28 '18 at 09:47
  • 1
    Is there a way to automatically add them when writing a function? – basickarl Jan 15 '20 at 13:47
  • 4
    The feature is actually triggered by typing `/** */`. This automatically happens if you have auto-closing of brackets enabled. – Oliver Salzburg Feb 17 '20 at 14:03
  • 4
    Is there a way to assign this to a keyboard shortcut? I know `/**` isn't _that_ long but it'd be nice with how many JSDoc comments I'm making nowadays. – Christian Jensen Sep 18 '20 at 16:22
  • This is a nice feature and one that is compatible many other documentation libraries like [Compodoc](https://compodoc.app/) for generating automated documentation. As @iMe mentioned, for `@param` and `@return` tags you can use this useful library [Add jsdoc comments](https://marketplace.visualstudio.com/items?itemName=stevencl.addDocComments) – Abdur Rahman Oct 14 '21 at 06:42
  • @OliverSalzburg In fact, I couldn't trigger this snippet with auto-closing brackets disabled. Guess I have to get used to those now... – Ray Jan 12 '23 at 15:53
38

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.

Jack Vial
  • 2,354
  • 1
  • 28
  • 30
  • 1
    The link is dead, now use [this](https://github.com/oouo-diogo-perdigao/vscode-docthis) fork from GitHub https://marketplace.visualstudio.com/items?itemName=oouo-diogo-perdigao.docthis – Wingjam Aug 19 '20 at 18:56
  • October 2022: The extension is called *Document This* and was written by *oouo-diogo-perdigao* . The link in this answer works. I had a fresh new laptop with the latest VS Code. This is the only extension that got JavaDoc block comments working! – Christian Oct 27 '22 at 19:17
18

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

Benjamin Pasero
  • 113,622
  • 14
  • 75
  • 54
3

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.

Corky3892
  • 485
  • 5
  • 8
2

A related one.

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

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

Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
1

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.

greuze
  • 4,250
  • 5
  • 43
  • 62
0

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.

Ashu Sahu
  • 417
  • 6
  • 7
-3

Document this has worked perfectly for me