如何为反汇编制作弹出窗口 window

How to make a popup for the Disassembly window

我致力于在 VS 中免费带来改进的反汇编 Window 体验。但是,反汇编 window 与其他 windows 不同。好的示例代码可用于 current API(例如参见 [​​=11=]。我什至找不到用当前版本的 VS 编译的示例代码(vs2015/17).

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

广告:在 return 中你能得到什么(帮助我解决了这个问题;向你脾气暴躁但知识渊博的同事请教;将其转发给你的祖母)? 答案:一个免费的 VS 扩展,添加了:

  1. 反汇编中的语法突出显示 window。
  2. 带有性能指标助记符描述的弹出窗口。
  3. 弹出Z3可以判断的寄存器内容

回答并记录我的曲折经历。

扩展 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);
}