将鼠标悬停在文本上时显示工具提示

ssw*_*qaa 2 visual-studio vsix visual-studio-extensions

我想创建扩展,当我将鼠标悬停在文本上时,该扩展允许显示自定义消息。

例如,“test-text”应该给出工具提示“OK”,而不是当前的“ITrackin...”

我试图遵循https://learn.microsoft.com/en-us/visualstudio/extensibility/walkthrough-displaying-quickinfo-tooltips?view=vs-2019 但人们说它不起作用,而且还有很长的路要走做这个。

我找不到更多关于此的文档。我知道如何在单击窗口中显示它/获取当前选定的文本。 在此输入图像描述

ssw*_*qaa 5

Lance Li-MSFT 发送的示例确实很有帮助,但为了使其正常工作,我必须花费一些时间。

\n

重要步骤:

\n
    \n
  • 导入 LineAsyncQuickInfoSourceProvider.cs 和 LineAsyncQuickInfoSource.cs
  • \n
  • 通过添加引用对话框添加对 System.ComponentModel.Composition 的引用(右键单击项目名称)
  • \n
  • 通过使用 NuGet 包管理器安装缺少的引用来获取它们
  • \n
  • 要初始化 MEF 组件,您\xe2\x80\x99 需要将新资产添加到 source.extension.vsixmanifest。
  • \n
\n
<Assets>\n    ...\n    <Asset Type = "Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />\n</Assets>\n
Run Code Online (Sandbox Code Playgroud)\n

LineAsyncQuickInfoSourceProvider.cs

\n

它仅用于显示快速信息/工具提示。

\n
<Assets>\n    ...\n    <Asset Type = "Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />\n</Assets>\n
Run Code Online (Sandbox Code Playgroud)\n

LineAsyncQuickInfoSource.cs

\n

在这里您可以自定义您想要显示的内容。

\n
using Microsoft.VisualStudio.Language.Intellisense;\nusing Microsoft.VisualStudio.Text;\nusing Microsoft.VisualStudio.Utilities;\nusing System.ComponentModel.Composition;\n\nnamespace JSONExtension\n{\n    [Export(typeof(IAsyncQuickInfoSourceProvider))]\n    [Name("Line Async Quick Info Provider")]\n    [ContentType("any")]\n    [Order]\n    internal sealed class LineAsyncQuickInfoSourceProvider : IAsyncQuickInfoSourceProvider\n    {\n        public IAsyncQuickInfoSource TryCreateQuickInfoSource(ITextBuffer textBuffer) //creates instance of LineAsyncQuickInfoSource for displaying Quick Info\n        {  \n            return textBuffer.Properties.GetOrCreateSingletonProperty(() => new LineAsyncQuickInfoSource(textBuffer)); //this ensures only one instance per textbuffer is created\n        }\n    }\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n