VS Intellisense: Show INDENTED multiline code example on hover-over
Asked Answered
U

3

7

Is such a thing possible? If it's not clear what I'm talking about, here's a detailed example:

Take this quick utility class I wrote a few weeks ago (details omitted), along with the example I want to share:

public abstract class CommonOdinAttributesForOwnedType<TProperty, TParent> : OdinAttributeProcessor<TProperty>
{
    //snip
}

//EXAMPLE IMPLEMENTATION (Recommended to be nested inside MyBaseType):
protected class BoolAttributesInsideMyBaseType : CommonOdinAttributesForOwnedType<bool, MyBaseType>
{
    protected override List<Attribute> GetAdditionalAttributes()
    {
        return new List<Attribute>()
        {
            new ToggleLeftAttribute(), //add more desired attributes here
        };
    }
}

I have the following XML above the abstract class:

/// <summary>
/// Gives ALL objects of type TProperty drawn within classes derived from TParent a requested list of 
/// Odin GUI attributes
/// <code>
/// //EXAMPLE IMPLEMENTATION (Recommended to be nested inside MyBaseType):
/// protected class BoolAttributesInsideMyBaseType : CommonOdinAttributesForOwnedType&lt;bool, MyBaseType&gt;
/// {
///     protected override List&lt;Attribute&gt; GetAdditionalAttributes()
///     {
///         return new List&lt;Attribute&gt;()
///         {
///             new ToggleLeftAttribute(), //add more desired attributes here
///         };
///     }
/// }
/// </code>
/// </summary>

Now, I could have SWORN that when I originally created the class, the tooltip looked like I wanted ... but maybe I'm hallucinating. At any rate, during this week's refactor (during which the file was moved/renamed and fed through ReSharper's cleanup), I noticed that the Intellisense tooltip now looks like hot garbage:

Intellisense with zero whitespace control

Adding <br/> to the end of each line only helps a little:

enter image description here

...and I haven't been able to find a way to manually specify indentation the way <br/> specifies new lines. I've also tried many combinations of <remarks>, <example>, <para>, and various ways to nest the blocks, but nothing worked.

So: Is there any way to (ideally) get Visual Studio 2019 to actually parse whitespace found inside an XML documentation <code></code> block, or (barring that) use some other block that manually adds indentation, the way I've manually added new lines with <br/>? I've looked and looked, and can't find a way to do either.

Uttermost answered 30/7, 2020 at 17:53 Comment(0)
T
4

For what it's worth - I have been able to indent source code in XML documentation (at least on VS 2022), by copy/pasting Unicode character u2800 (the Braille pattern blank character).

I have not tried in other versions of Visual Studio. Unfortunately, the width of the blank character is not the same width as the rest of the monospaced characters (at least with the font I normally use, which is Office CodePro Light), so you can't rely on this character to create nice looking ascii-block diagrams that look right on both the editor as well as on the hover-over Intellisense view)

For convenience, the character can be copied here (between the single quotes):

'⠀'

enter image description here

Transitive answered 31/1, 2022 at 19:22 Comment(3)
Close enough! Accepting this as the new answer. FWIW, it also works on VS 2019.Uttermost
This is a clever solution. Keep in mind that this works for Intellisense, but will probably be wonky if you actually generate XML documentation. But, does anyone actually do that anymore anyway?Jahdal
As of Visual Studio 2022 version 17.8, this hack is no longer necessary. Regular spaces will be rendered as whitespace in the hover-over.Transitive
T
4

Ok, I think I found the proper way to format code in documentation using simple spaces. The trick is in using the following XML structure:

/// <remarks>
/// <example>
/// <code>
/// private async Task SomeOperationAsync() {
///     // this will be properly indented
///     await DoAsync();
/// }
/// </code>
/// </example>
/// </remarks>

EDIT: This seems to have been introduced in an update to Visual Studio 2022 (probably v. 17.1) On my Visual Studio 2019 (last update was 16.11.6) it does not work.

Transitive answered 16/3, 2022 at 20:10 Comment(1)
I'm leaving your other answer as accepted because it still works with 2019, but this is fantastic. I may have to upgrade VS soon, after all...Uttermost
L
3

VS Intellisense: Show INDENTED multiline code example on hover-over

I am afraid that you cannot get what you want.

Actually, vs xml document does not have the ability to keep code-style format.

Under the summary xml node, it cannot keep the code format. You have to manually change the format. Use some codes to change the style as it shows.

Is there any way to (ideally) get Visual Studio 2019 to actually parse whitespace found inside an XML documentation <code></code> block

Line break can use <br/> or <para/>. But there is no way to indent the first line. Html formatting methods, spacing, spaces, etc. do not work.

In fact, this is a flaw---xml document of vs does not have the ability to indent the line and keep the code style.

So far, we can only do what you have done.

Besides, if you still want the feature, you could suggest a feature on our User Voice Forum and the Team will consider your question carefully and I hope they will give you a satisfactory reply.

Lilllie answered 31/7, 2020 at 10:0 Comment(1)
Thank you. I've done as you suggested and requested a feature.Uttermost

© 2022 - 2024 — McMap. All rights reserved.