-
Notifications
You must be signed in to change notification settings - Fork 37.1k
Description
TL;DR / Quick Peek / Example Screenshots
Without reading any further you can see from the screenshots, what I would like to add to VS Code. It has been implemented already. Upvote this post, if you support my merge request. Just a quick entry hint: It's about the boxes with documentation text that pop up when you hover over a symbol (as known from IntelliSense).
Motivation
The original motivation for this feature request is the treatment of documentation comments in JavaScript and TypeScript. Users of other languages providing IntelliSense quick information data could profit from this as well.
Have a look at the following JavaScript snippet.
/**
* This inverts a number.
* @param x {number} the number to invert; must not be zero
* @return x inverted
*/
function invert (x)
{ return 1 / x; }VS Code provides IntelliSense support for JavaScript and TypeScript out of the box. If the user hovers over a reference to foo somewhere in the code, a quick info box will pop up displaying the function signature and the documentation from the comment above its declaration. The documentation comment will be formatted as Markdown and some common JSDoc tags will be parsed, too, and displayed more or less fancy.
Users with other preferences for documentation comment formatting or styling may run into ugly problems because of some Markdown and HTML habits. Although they are not using JSDoc and maybe not even Markdown (completely or maybe only on the level of logical text structure, i.e. paragraphs), some might want to enjoy getting the documentation displayed when hovering over a reference.
/**
This inverts a number.
<= x : number - the number to invert; must not be zero
=> x inverted
*/
function invert (x)
{ return 1 / x; }While this looks good in the code itself, the quick info box will display a messy text, partly due to some bugs (see caveats below), mainly due to the way Markdown/HTML treat whitespace characters. HTML reduces any sequence of whitespace characters to a normal space, including tabs and newlines. Markdown only begins a new paragraph after two consecutive newlines. Thus, the above documentation will look kind of like this:
This inverts a number. <= x : number - the number to invert; must not be zero => x inverted
Solution
The proposed feature adds two new settings for the user to opt-in to for the text displayed in quick information boxes:
- Toggle usage of a monospace font.
- Setup the treatment of whitespace characters conforming to the CSS-property
white-space. This should only have an effect inside paragraphs (<p>) so basic Markdown (such as headings or lists) still works normally and doesn't insert lots of newlines.
With both features configured, the display of the documentation in the second code snippet could look kind of like this:
This inverts a number.
<= x : number - the number to invert; must not be zero
=> x invertedCaveats / Known Bugs
- TypeScript is responsible for parsing JSDoc comments. Currently there exists a bug where whitespace characters at the beginning of lines within the documentation comment get stripped away. (fix and pull request are there already)
- VS Code uses marked.js for parsing the Markdown in the documentation comments. This library unfortunately replaces all tabs by four spaces each due to some internal weaknesses. I have attempted to remove the replacement, but the linked comment left me thinking it's not a good idea. The problem are not so much the tabs used for indentation, but the tabs used for alignment, which may be less than four characters long. I'm planning to alter the replacement algorithm so mid-text tabs are replaced accordingly or not replaced at all.
Conclusion
As this is an opt-in feature it would not change the experience of users, who do not want or need it. It would, however, enrich VS Code with a new possibility to customize quick information styling.
I have implemented the feature already, so this request is merely for explanation and for linking the PR to. I am open for criticism or suggestions.