TL;DR: Where does the JS ment-appending behavior of the VSCode "Editor Hover" box e from and can it be adapted to use //
ments?
When editing .js/.ts files, VSCode shows a box when the mouse hovers over any reference to a variable (controlled with the Editor > Hover
settings).
/** I'm a ment */
const someVariable = 'Me';
console.log(someVariable);
results in the following when hovering over someVariable
in the last line:
The ment portion of that box only appears if it is a multi-line ment beginning with two asterisks, one or more lines above a variable, object property, or function, in line with Intellisense's use of JSDoc. Very useful, but some team members prefer to put //
ments at the end of a short line where a variable was declared. Is there any way to make VSCode take these end-of-line ments into account for variables/properties, or would I have to convert every relevant ment to /**
to see it like this?
TL;DR: Where does the JS ment-appending behavior of the VSCode "Editor Hover" box e from and can it be adapted to use //
ments?
When editing .js/.ts files, VSCode shows a box when the mouse hovers over any reference to a variable (controlled with the Editor > Hover
settings).
/** I'm a ment */
const someVariable = 'Me';
console.log(someVariable);
results in the following when hovering over someVariable
in the last line:
The ment portion of that box only appears if it is a multi-line ment beginning with two asterisks, one or more lines above a variable, object property, or function, in line with Intellisense's use of JSDoc. Very useful, but some team members prefer to put //
ments at the end of a short line where a variable was declared. Is there any way to make VSCode take these end-of-line ments into account for variables/properties, or would I have to convert every relevant ment to /**
to see it like this?
-
1
It seems that its standard to use block ments
/** */
for documentation. See jsdoc.app/about-getting-started.html – Umair Khan Commented Aug 12, 2020 at 6:32 - Why would you do that ? I don't think this is possible. '//' is already used for ment a line, use it for another purpose may cause trouble. Better keep the standard – Amadou Beye Commented Aug 12, 2020 at 6:34
- 1 @VLAZ Variables are merely easiest to demo; the most valuable use is keys on objects and TypeScript interfaces, frequently imported into other files. Most of those manage without ments, but there's always a few keys whose minimal distinct description is like "Latest line-to-neutral voltage for conductor 2 in tenths of a volt", or state machine enumerations that need to describe exactly what situation/behavior of an external device a particular number corresponds to. – MBer Commented Aug 12, 2020 at 9:02
- 1 I've created an issue on VSCode here. Please upvote it to show your support. github./microsoft/vscode/issues/215550 – V. Rubinetti Commented Jun 14, 2024 at 16:22
3 Answers
Reset to default 3This 2 minute video was pretty helpful for me to see the advantages of using the jsDoc format. Instead of Ctrl K Ctrl C in vscode I'm going to start typing /**
which autopletes the ments similar to visual studio code typing ///
in c# to autogenerate the ments template, etc. Here's the video: Quickly writing JSDoc ments in JavaScript and TypeScript
Unfortunately VSCode doesn't seem to support showing regular //
ments in the popup. I've created an issue on VSCode here to request this feature. Please upvote it to show your support. https://github./microsoft/vscode/issues/215550
In the meantime, here's a VSCode keybinding I use to conveniently add a JSDoc-style ment:
{
{
"key": "shift+cmd+/",
"mand": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "/** ${TM_SELECTED_TEXT/\\s*\\/\\/\\s*//}$1 */"
}
},
}
I also use prettier-plugin-jsdoc
to auto-wrap multi-line ments.
Why would you do that ? I don't think this is possible. '//' is already used for ment a line, use it for another purpose may cause trouble. Better keep the standard.
This is nonsense. Regular ments are used for documenting and explaining code. JSDoc is just a more well-defined menting format to include richer details. They both serve the same purpose.
Yes, regular ments are also sometimes used to temporarily remove code from execution, and that might not be something you prefer to show in the popup. But I'd gladly once in a while see a mented-out line of code in the popup if it meant I could always see documentation/descriptions too. Nothing else useful is taking up that space anyway.
Regardless of that, your opinions on the distinction between ment styles, or anything else, IDEs should at least have an option to have regular ments show in the popup.
JS/TS has these different ment syntaxes because they serve different purposes:
//
and/* */
— Commenting on code (or menting out code)/** */
— Documenting symbols
You may not like the /** */
syntax, but this is a widely understood convention in JS/TS that is understood across many different editors and tools. Better to adopt to follow these conventions than fight the language ecosystem to make this work