如何为“反汇编”窗口创建弹出窗口

时间:2017-07-20 10:41:02

标签: c# visual-studio vsix disassembly

我致力于免费为VS带来改进的反汇编窗口体验。但是,与其他窗口相比,反汇编窗口是不同的。 当前 API提供了良好的示例代码(例如参见here)。遗憾的是,反汇编窗口使用较旧的遗留 API,这几乎没有记录。另请参阅MSDNGitHub上的这些问题。我甚至找不到用当前版本的VS(vs2015 / 17)编译的示例代码。

问题:如何在反汇编窗口中制作弹出窗口。

广告:您可以得到什么回报(帮助我解决这个问题;询问脾气暴躁但知识渊博的同事;将其转发给您的奶奶)? 答案:一个免费的VS扩展程序,添加:

  1. 在“反汇编”窗口中突出显示语法。
  2. 使用性能指标描述助记符的弹出窗口。
  3. 弹出窗口,其中包含Z3可以确定的注册内容。

1 个答案:

答案 0 :(得分:1)

回答并记录我的蜿蜒经历。

Extend IIntellisenseControllerProvider:

[Export(typeof(IIntellisenseControllerProvider))]
[ContentType("Disassembly")]
[TextViewRole(PredefinedTextViewRoles.Debuggable)]
internal sealed class MyInfoControllerProvider : IIntellisenseControllerProvider
{
    [Import]
    private IQuickInfoBroker _quickInfoBroker = null;
    [Import]
    private IToolTipProviderFactory _toolTipProviderFactory = null;

    public IIntellisenseController TryCreateIntellisenseController(ITextView textView, IList<ITextBuffer> subjectBuffers)
    {
        var provider = this._toolTipProviderFactory.GetToolTipProvider(textView);
        return new MyInfoController(textView, subjectBuffers, this._quickInfoBroker, provider);
    }
}

MyInfoController的构造函数如下所示:

internal MyInfoController(
    ITextView textView,
    IList<ITextBuffer> subjectBuffers,
    IQuickInfoBroker quickInfoBroker,
    IToolTipProvider toolTipProvider)
{
    this._textView = textView;
    this._subjectBuffers = subjectBuffers;
    this._quickInfoBroker = quickInfoBroker;
    this._toolTipProvider = toolTipProvider;
    this._textView.MouseHover += this.OnTextViewMouseHover;
}

OnTextViewMouseHover处理弹出窗口的创建:

private void OnTextViewMouseHover(object sender, MouseHoverEventArgs e)
{
    SnapshotPoint? point = GetMousePosition(new SnapshotPoint(this._textView.TextSnapshot, e.Position));
    if (point.HasValue)
    {
        string contentType = this._textView.TextBuffer.ContentType.DisplayName;
        if (contentType.Equals("Disassembly"))
        {
            this.ToolTipLegacy(point.Value);
        } 
        else // handle Tooltip the regular way 
        {
            if (!this._quickInfoBroker.IsQuickInfoActive(this._textView))
            {
                ITrackingPoint triggerPoint = point.Value.Snapshot.CreateTrackingPoint(point.Value.Position, PointTrackingMode.Positive);
                this._session = this._quickInfoBroker.CreateQuickInfoSession(this._textView, triggerPoint, false);
                this._session.Start();
            }
        }
    }
}

在ToolTipLegacy中处理工具提示的创建:

private void ToolTipLegacy(SnapshotPoint triggerPoint)
{
    // retrieve what is under the triggerPoint, and make a trackingSpan.
    var textBlock = new TextBlock() { Text = "Bla" };
    textBlock.Background = TODO; //do not forget to set a background
    this._toolTipProvider.ShowToolTip(trackingSpan, textBlock, PopupStyles.DismissOnMouseLeaveTextOrContent);
}