Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Do there exist examples that use IAsyncQuickInfoBroker? #10

Closed
HJLebbink opened this issue Jun 23, 2018 · 5 comments
Closed

Do there exist examples that use IAsyncQuickInfoBroker? #10

HJLebbink opened this issue Jun 23, 2018 · 5 comments

Comments

@HJLebbink
Copy link

HJLebbink commented Jun 23, 2018

I like to migrate to the new IAsync* QuickInfo api, but I can't find any examples that use this new API. I'm a bit confused how to migrate the following piece of code. Is the IntellisenseController still part of the new API? Where do I call the AsyncQuickInfoBroker?

internal sealed class QuickInfoController : IIntellisenseController
    {
        private readonly IList<ITextBuffer> _subjectBuffers;
        private readonly IAsyncQuickInfoBroker _quickInfoBroker;
        private ITextView _textView;

        internal QuickInfoController(
            ITextView textView,
            IList<ITextBuffer> subjectBuffers,
            IAsyncQuickInfoBroker quickInfoBroker)
        {
            this._textView = textView;
            this._subjectBuffers = subjectBuffers;
            this._quickInfoBroker = quickInfoBroker;
            
            this._textView.MouseHover += (o, e) => {
                SnapshotPoint? point = GetMousePosition(new SnapshotPoint(this._textView.TextSnapshot, e.Position));
                if (point.HasValue)
                {
                    ITrackingPoint triggerPoint = point.Value.Snapshot.CreateTrackingPoint(point.Value.Position, PointTrackingMode.Positive);
                    if (!this._quickInfoBroker.IsQuickInfoActive(this._textView))
                    {
                        this._quickInfoBroker.TriggerQuickInfoAsync(this._textView, triggerPoint);
                    }
                }
            };
        }
@olegtk
Copy link
Member

olegtk commented Jun 23, 2018

@gundermanc to answer the question, but a sample can be found at https://github.com/Microsoft/VSSDK-Extensibility-Samples/tree/master/AsyncQuickInfo

@gundermanc
Copy link
Member

Turns out the intellisense controller was never needed for quick info because the IDE provides one. Simply implementing the quick info source is enough. You shouldn't need to call the broker at all unless you need to programmatically pop quick info for some reason.

The sample Oleg linked is the definitive sample. Note that you're called on a background thread.

@HJLebbink
Copy link
Author

Thank you for the quick reply.

@olegtk, I seemed I hadn't pulled that repo recently, AsyncQuickInfo demo is what I sought.

@gundermanc, I didn't know that I didn't need one! "Note that you're called on a background thread." Is there an simple method to add a UserControl to the QuickInfoItem that is returned by GetQuickInfoItemAsync? It is not obvious (to me) how to do that. Or is it still not advisable to add UserControls (with buttons etc) to a QuickInfoItem?

@gundermanc
Copy link
Member

Adding user controls is still supported, albeit a little bit more roundabout. My recommendation would be to use the built in data-types, but if you need a custom piece of UI, you can 1) define a custom data type and 2) define a IViewElementFactory that defines how it is rendered as UI on the UI thread. AFAIK, Visual FSharp is the only public example of this.

Keep in mind that going this route may prevent your content from working with VS Live Share and other advanced scenarios.

@HJLebbink
Copy link
Author

Yes that helped. Thanks for the info!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants