void OnDismissed() { Dismissed?.Invoke(); if (_subHuntWindow != null) { _subHuntWindow.Close(); } _container.LayoutUpdated -= Container_LayoutUpdated; _container.PopupOpened -= PopupOpened; _session.StateChanged -= Session_StateChanged; _wpfTextView.VisualElement.MouseWheel -= MouseWheel; _timer.Stop(); _timer.Tick -= _timer_Tick; Current = null; _container = null; Debug.WriteLine("Dismissed"); }
// This is called on a background thread. public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { Debug.WriteLine("GetQuickInfoItemAsync"); Current = this; _timer.Stop(); _activeAreaRect = default(D.Rectangle); _activeAreaRect = default(D.Rectangle); if (_subHuntWindow != null) { _subHuntWindow.Close(); } _subHuntWindow = null; _container = null; _wpfTextView = (IWpfTextView)session.TextView; var fileModel = _fileModel = VsUtils.TryGetFileModel(_textBuffer); if (_fileModel == null) // TODO: Add logging Debug.Assert(_fileModel != null); { return(null); } var snapshot = _textBuffer.CurrentSnapshot; var triggerPoint = session.GetTriggerPoint(snapshot); if (!triggerPoint.HasValue) { return(null); } var server = fileModel.Server; foreach (var projectId in fileModel.GetProjectIds()) { server.Client.Send(new ClientMessage.GetHint(projectId, fileModel.Id, triggerPoint.Value.ToVersionedPos())); break; } var hint = await fileModel.GetHintAsync(cancellationToken).ConfigureAwait(false); Hint.SetCallbacks(SubHintText, SpanClassToBrush); Hint.Click += Hint_Click; Hint.BackgroundResourceReference = EnvironmentColors.ToolTipBrushKey; Hint.ForegroundResourceReference = EnvironmentColors.ToolTipTextBrushKey; _wpfTextView = (IWpfTextView)session.TextView; var text = hint.text; if (text.All(c => char.IsWhiteSpace(c))) { return(null); } var span = new Span(hint.referenceSpan.StartPos, hint.referenceSpan.Length); var trackingSpan = snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeInclusive); await NitraCommonVsPackage.Instance.JoinableTaskFactory.SwitchToMainThreadAsync(); var rectOpt = GetViewSpanRect(trackingSpan); if (!rectOpt.HasValue) { return(null); } _wpfTextView.VisualElement.MouseWheel += MouseWheel; _activeAreaRect = rectOpt.Value.ToRectangle(); session.StateChanged += Session_StateChanged; _session = session; var container = new PopupContainer(); Subscribe(container); container.LayoutUpdated += Container_LayoutUpdated; container.PopupOpened += PopupOpened; _container = container; _container.Children.Add(Hint.ParseToFrameworkElement(text)); _timer.Tick += _timer_Tick; return(new QuickInfoItem(trackingSpan, container)); }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan) { Current = this; _timer.Stop(); _activeAreaRect = default(D.Rectangle); _activeAreaRect = default(D.Rectangle); if (_subHuntWindow != null) { _subHuntWindow.Close(); } _subHuntWindow = null; _container = null; Debug.WriteLine("AugmentQuickInfoSession"); _wpfTextView = (IWpfTextView)session.TextView; _fileModel = VsUtils.TryGetFileModel(_textBuffer); Debug.Assert(_fileModel != null); _textViewModel = VsUtils.GetOrCreateTextViewModel(_wpfTextView, _fileModel); Debug.Assert(_textViewModel != null); Hint.SetCallbacks(SubHintText, SpanClassToBrush); Hint.Click += Hint_Click; Hint.BackgroundResourceReference = EnvironmentColors.ToolTipBrushKey; Hint.ForegroundResourceReference = EnvironmentColors.ToolTipTextBrushKey; var snapshot = _textBuffer.CurrentSnapshot; var triggerPoint = session.GetTriggerPoint(snapshot); if (triggerPoint.HasValue) { _wpfTextView = (IWpfTextView)session.TextView; var extent = GetTextExtent(triggerPoint.Value); var text = extent.Span.GetText(); if (!text.All(c => char.IsLetterOrDigit(c) || c == '_')) { applicableToSpan = null; return; } var trackingSpan = snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive); applicableToSpan = trackingSpan; var rectOpt = GetViewSpanRect(trackingSpan); if (!rectOpt.HasValue) { return; } _wpfTextView.VisualElement.MouseWheel += MouseWheel; _activeAreaRect = rectOpt.Value.ToRectangle(); _session = session; session.Dismissed += OnDismissed; var container = new PopupContainer(); Subscribe(container); container.LayoutUpdated += Container_LayoutUpdated; container.PopupOpened += PopupOpened; _container = container; _container.Children.Add(new System.Windows.Controls.TextBlock() { Text = "loading.." }); quickInfoContent.Add(container); _timer.Tick += _timer_Tick; //Externals.FillRect(_activeAreaRect); return; } applicableToSpan = null; }