/// <summary> /// Triggers Statement completion when appropriate keys are pressed ('[', '{', '\', '(') /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnKeyDown(object sender, KeyEventArgs e) { // Make sure that this event happened on the same text view to which we're attached. ITextView textView = sender as ITextView; if (this.subjectTextView != textView) { return; } // Find the completion provider associated with the pressed key RegexCompletionProvider completionProvider = GetCompletionProvider(e); if (completionProvider != null) { if (activeSession != null) { activeSession.Dismiss(); } // determine which subject buffer is affected by looking at the caret position SnapshotPoint?caretPoint = textView.Caret.Position.Point.GetPoint (textBuffer => (subjectBuffers.Contains(textBuffer)), PositionAffinity.Predecessor); if (caretPoint.HasValue) { // the invocation occurred in a subject buffer of interest to us ICompletionBroker broker = completionBroker; ITrackingPoint triggerPoint = caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive); // Create a completion session activeSession = broker.CreateCompletionSession(textView, triggerPoint, true); // Set the completion provider that will be used by the completion source activeSession.Properties.AddProperty(RegexCompletionProvider.CompletionProviderSessionKey, completionProvider); // Attach to the session events activeSession.Dismissed += new System.EventHandler(OnActiveSessionDismissed); activeSession.Committed += new System.EventHandler(OnActiveSessionCommitted); this.subjectTextView.Properties.GetProperty <TextViewEventManager>(TextViewEventManager.Key).OnIntellisenseSessionStart(new EventArgs()); // Start the completion session. The intellisense will be triggered. activeSession.Start(); } } else if (e.Key == Key.Down && activeSession != null) { SelectNextCompletion(); e.Handled = true; } else if (e.Key == Key.Up && activeSession != null) { SelectPreviousCompletion(); e.Handled = true; } }
void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets) { int triggerPointPosition = session.GetTriggerPoint(session.TextView.TextBuffer).GetPosition(session.TextView.TextSnapshot); ITrackingSpan trackingSpan = session.TextView.TextSnapshot.CreateTrackingSpan( triggerPointPosition, 0, SpanTrackingMode.EdgeInclusive); RegexCompletionProvider completionProvider = session.Properties[RegexCompletionProvider.CompletionProviderSessionKey] as RegexCompletionProvider; if (completionProvider != null) { // TODO: RC1 Investigate what the moniker parameter is completionSets.Add(new CompletionSet("regex", CompletionSetName, trackingSpan, completionProvider.GetCompletions(session), null)); } }