Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to write multi-line code in JSDoc comment in a javascript/typescript project in VSCode?

When working on a javascript/typescript project in VSCode, I want to write multi-line code in comment. Knowing that VSCode supports markdown syntax in comment, I go ahead and write:

/**
* ```ts
* { deliverQuestionClicked: { [pageNum]: false } }
* ```
*/
deliverQuestionClicked: {},

However when I hover on that variable, VSCode renders the comment in a ugly looking way:

vscode_1.png

As the screenshot shown above, there're extra * that I don't want.

So I wonder what is the correct way to write multi-line code in comment?

Update 2020/9/25

I can confirm this problem doesn't exist in VSCode 1.49.1

Code:

class TopRow extends React.Component {
    state = {
        /**
        * ```ts
        * { deliverQuestionClicked: { [pageNum]: false } }
        * ```
        */
        deliverQuestionClicked: {},
    };
}

When I hover over that class property, it shows the JSDoc perfectly:

image.png

like image 987
Bruce Sun Avatar asked Jan 17 '19 01:01

Bruce Sun


2 Answers

Must have been fixed.

In VSC 1.48 with this code

class TopRow {
  state = {
    /**
    * ```ts
    * { deliverQuestionClicked: { [pageNum]: false } }
    * ```
    */
    deliverQuestionClicked: {}
  }
}

I get

enter image description here

like image 149
rioV8 Avatar answered Nov 11 '22 01:11

rioV8


In JSDoc-format,

Basic format rules for JSDoc comments.

  • Each line contains an asterisk and asterisks must be aligned
  • Each asterisk must be followed by either a space or a newline (except for the first and the last)
  • The only characters before the asterisk on each line must be whitespace characters
  • One line comments must start with /** and end with */
  • Multiline comments don’t allow text after /** in the first line (with option "check-multiline-start")

You can optionally specify the option "check-multiline-start" to enforce the first line of a multiline JSDoc comment to be empty.

TypeScript in Visual Studio Code

To disable JSDoc comment suggestions in TypeScript,
set "typescript.suggest.completeJSDocs": false.

To add a comment

  • press Ctrl+Alt+C twice
  • or select 'Comment code' from your context menu
  • or insert /** above the line of code.

More info visit

like image 42
Rayees AC Avatar answered Nov 11 '22 02:11

Rayees AC