简体   繁体   English

VS Intellisense:在悬停时显示缩进的多行代码示例

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

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:以我几周前写的这个快速实用程序 class(细节省略),以及我想分享的例子为例:

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:我在摘要 class 上面有以下 XML:

/// <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.现在,我可以发誓,当我最初创建 class 时,工具提示看起来像我想要的......但也许我产生了幻觉。 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:无论如何,在本周的重构期间(在此期间文件被移动/重命名并通过 ReSharper 的清理提供),我注意到 Intellisense 工具提示现在看起来像热垃圾:

具有零空白控制的 Intellisense

Adding <br/> to the end of each line only helps a little:在每一行的末尾添加<br/>只会有一点帮助:

在此处输入图像描述

...and I haven't been able to find a way to manually specify indentation the way <br/> specifies new lines. ...而且我一直无法找到一种方法来手动指定缩进的方式<br/>指定新行。 I've also tried many combinations of <remarks> , <example> , <para> , and various ways to nest the blocks, but nothing worked.我还尝试了<remarks><example><para>的许多组合,以及嵌套块的各种方法,但没有任何效果。

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/> ?所以:有没有办法(理想情况下)让 Visual Studio 2019 实际解析在 XML 文档<code></code>块中找到的空白,或者(除非)使用其他手动添加缩进的块,就像我这样是否已使用<br/>手动添加新行? I've looked and looked, and can't find a way to do either.我看了又看,也找不到办法。

VS Intellisense: Show INDENTED multiline code example on hover-over VS Intellisense:在悬停时显示 INDENTED 多行代码示例

I am afraid that you cannot get what you want.恐怕你得不到你想要的。

Actually , vs xml document does not have the ability to keep code-style format.实际上,vs xml 文档不具备保持代码风格格式的能力。

Under the summary xml node , it cannot keep the code format.总结 xml 节点下,不能保持代码格式。 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有没有办法(理想情况下)让 Visual Studio 2019 实际解析 XML 文档<code></code>块中的空白

Line break can use <br/> or <para/> .换行可以使用<br/><para/> But there is no way to indent the first line.但是没有办法缩进第一行。 Html formatting methods, spacing, spaces, etc. do not work. Html 格式化方法,间距,空格等都不起作用。

In fact , this is a flaw---xml document of vs does not have the ability to indent the line and keep the code style.其实这是一个缺陷---vs的xml文档不具备缩进行和保持代码风格的能力。

So far, we can only do what you have done.到目前为止,我们只能做你所做的。

Besides , if you still want the feature, you could suggest a feature onour User Voice Forum and the Team will consider your question carefully and I hope they will give you a satisfactory reply.此外,如果您仍然想要该功能,您可以在我们的用户之声论坛suggest a feature ,团队会仔细考虑您的问题,希望他们能给您一个满意的答复。

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:诀窍在于使用以下 XML 结构:

/// <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.编辑:这似乎是在 Visual Studio 2022 的更新中引入的(可能是 v.17.1)在我的 Visual Studio 2019(上次更新是 16.11.6)上它不起作用。

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).对于它的价值 - 我已经能够在 XML 文档中缩进源代码(至少在 VS 2022 上),通过复制/粘贴 Unicode 字符 u2800(盲文模式空白字符)。

I have not tried in other versions of Visual Studio.我没有在其他版本的 Visual Studio 中尝试过。

For convenience, the character can be copied here (between the single quotes):为方便起见,可以在此处复制字符(在单引号之间):

'⠀'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM