internal void TriggerCompletionSession(bool completeWord, bool?commitByDefault = null) { Dismiss(); var session = CompletionBroker.TriggerCompletion(_textView); if (session == null) { _activeSession = null; } else if (completeWord && SelectSingleBestCompletion(session)) { session.Commit(); } else { if (commitByDefault.HasValue) { foreach (var s in session.CompletionSets.OfType <FuzzyCompletionSet>()) { s.CommitByDefault = commitByDefault.GetValueOrDefault(); } } session.Filter(); session.Dismissed += OnCompletionSessionDismissedOrCommitted; session.Committed += OnCompletionSessionDismissedOrCommitted; _activeSession = session; } }
internal void TriggerCompletionSession(bool completeWord, bool commitByDefault) { Dismiss(); _activeSession = CompletionBroker.TriggerCompletion(_textView); if (_activeSession != null) { FuzzyCompletionSet set; if (completeWord && _activeSession.CompletionSets.Count == 1 && (set = _activeSession.CompletionSets[0] as FuzzyCompletionSet) != null && set.SelectSingleBest()) { _activeSession.Commit(); _activeSession = null; } else { foreach (var s in _activeSession.CompletionSets.OfType <FuzzyCompletionSet>()) { s.CommitByDefault = commitByDefault; } _activeSession.Filter(); _activeSession.Dismissed += OnCompletionSessionDismissedOrCommitted; _activeSession.Committed += OnCompletionSessionDismissedOrCommitted; } } }
// Create an IntelliSense completion session for the word at the // current caret (cursor) position private bool TriggerCompletion() { // If completion is already active, simply return if (HasCompletionSession()) { return(true); } // Get a non-projection location for the caret (cursor) SnapshotPoint?caretPoint = TextView.Caret.Position.Point.GetPoint( IsNotProjection, PositionAffinity.Predecessor); if (!caretPoint.HasValue) { return(false); } // Create a tracking point for that position ITrackingPoint trackingPoint = caretPoint.Value.Snapshot.CreateTrackingPoint( caretPoint.Value.Position, PointTrackingMode.Positive); // Create a completion session for the word at that position completionSession = CompletionBroker.CreateCompletionSession( TextView, trackingPoint, true); // Subscribe to the dismissed event. This way when the session ends we know // to create a new one the next time IntelliSense completion is triggered completionSession.Dismissed += OnSessionDismissed; // Start the IntelliSense completion session completionSession.Start(); // Indicate that we successfully triggered an IntelliSense completion session return(true); }
private bool TriggerCompletion() { if (HasCompletionSession()) { return(true); } SnapshotPoint?caretPoint = TextView.Caret.Position.Point.GetPoint( IsNotProjection, PositionAffinity.Predecessor); if (!caretPoint.HasValue) { return(false); } ITrackingPoint trackingPoint = caretPoint.Value.Snapshot.CreateTrackingPoint( caretPoint.Value.Position, PointTrackingMode.Positive); completionSession = CompletionBroker.CreateCompletionSession( TextView, trackingPoint, true); completionSession.Dismissed += OnSessionDismissed; completionSession.Start(); return(true); }
private async Task TriggerCompletionAsync() { if (CommandExpansion == null) { return; // Host CommandExpansion service not available } if (IsCompletionSessionActive) { _completionSession.Dismiss(); _completionSession = null; } string line = WpfConsole.InputLineText; int caretIndex = CaretPosition - WpfConsole.InputLineStart.Value; Debug.Assert(caretIndex >= 0); // Cancel tab expansion if it takes more than 'TabExpansionTimeout' secs (defaults to 3 secs) to get any results CancellationTokenSource ctSource = new CancellationTokenSource(TabExpansionTimeout * 1000); SimpleExpansion simpleExpansion = null; try { WpfConsole.Dispatcher.SetExecutingCommand(true); simpleExpansion = await CommandExpansion.GetExpansionsAsync(line, caretIndex, ctSource.Token); } catch (Exception x) { // Ignore exception from expansion, but write it to the activity log ExceptionHelper.WriteErrorToActivityLog(x); } finally { WpfConsole.Dispatcher.SetExecutingCommand(false); } if (simpleExpansion != null && simpleExpansion.Expansions != null) { IList <string> expansions = simpleExpansion.Expansions; if (expansions.Count == 1) // Shortcut for 1 TabExpansion candidate { ReplaceTabExpansion(simpleExpansion.Start, simpleExpansion.Length, expansions[0]); } else if (expansions.Count > 1) // Only start intellisense session for multiple expansion candidates { _completionSession = CompletionBroker.CreateCompletionSession( WpfTextView, WpfTextView.TextSnapshot.CreateTrackingPoint(CaretPosition.Position, PointTrackingMode.Positive), true); _completionSession.Properties.AddProperty("TabExpansion", simpleExpansion); _completionSession.Dismissed += CompletionSession_Dismissed; _completionSession.Start(); } } }
public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { if (pguidCmdGroup == VSConstants.VSStd2K) { switch ((VSConstants.VSStd2KCmdID)nCmdID) { case VSConstants.VSStd2KCmdID.TYPECHAR: var ch = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn); if (_curSession != null && !_curSession.IsDismissed) { if (_curSession.SelectedCompletionSet.SelectionStatus.IsSelected && IsCompletionChar(ch)) { _curSession.Commit(); } } switch (ch) { case '<': if (_curSession != null) { _curSession.Dismiss(); } int res = _oldTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut); if (ErrorHandler.Succeeded(res)) { _curSession = CompletionBroker.TriggerCompletion(_textView); if (_curSession != null) { _curSession.Dismissed += CurSessionDismissedOrCommitted; _curSession.Committed += CurSessionDismissedOrCommitted; } } return(res); } break; case VSConstants.VSStd2KCmdID.RETURN: case VSConstants.VSStd2KCmdID.TAB: if (_curSession != null && !_curSession.IsDismissed) { _curSession.Commit(); return(VSConstants.S_OK); } break; } } return(_oldTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut)); }
void TriggerCompletion() { if (CommandExpansion == null) { return; // Host CommandExpansion service not available } if (IsCompletionSessionActive) { _completionSession.Dismiss(); _completionSession = null; } string line = WpfConsole.InputLineText; int caretIndex = CaretPosition - WpfConsole.InputLineStart.Value; Debug.Assert(caretIndex >= 0); SimpleExpansion simpleExpansion = null; try { simpleExpansion = CommandExpansion.GetExpansions(line, caretIndex); } catch (Exception x) { // Ignore exception from expansion, but write it to the activity log ExceptionHelper.WriteToActivityLog(x); } if (simpleExpansion != null && simpleExpansion.Expansions != null) { IList <string> expansions = simpleExpansion.Expansions; if (expansions.Count == 1) // Shortcut for 1 TabExpansion candidate { ReplaceTabExpansion(simpleExpansion.Start, simpleExpansion.Length, expansions[0]); } else if (expansions.Count > 1) // Only start intellisense session for multiple expansion candidates { _completionSession = CompletionBroker.CreateCompletionSession( WpfTextView, WpfTextView.TextSnapshot.CreateTrackingPoint(CaretPosition.Position, PointTrackingMode.Positive), true); _completionSession.Properties.AddProperty("TabExpansion", simpleExpansion); _completionSession.Dismissed += CompletionSession_Dismissed; _completionSession.Start(); } } }
public void VsTextViewCreated(IVsTextView textViewAdapter) { ITextView textView = AdapterService.GetWpfTextView(textViewAdapter); if (textView == null) { return; } Dispatcher.CurrentDispatcher.InvokeAsync(() => { textView.Properties.GetOrCreateSingletonProperty(() => new DothtmlCompletionCommandHandler(textViewAdapter, textView, this)); textView.Properties.GetOrCreateSingletonProperty(() => new DothtmlFormatCommandHandler(textViewAdapter, textView, this)); var tempSession = CompletionBroker.CreateCompletionSession(textView, textView.TextSnapshot.CreateTrackingPoint(0, Microsoft.VisualStudio.Text.PointTrackingMode.Negative), true); tempSession.Start(); tempSession.Dismiss(); }, DispatcherPriority.ApplicationIdle); }
internal void TriggerCompletionSession(bool completeWord) { Dismiss(); _activeSession = CompletionBroker.TriggerCompletion(_textView); if (_activeSession != null) { if (completeWord && _activeSession.CompletionSets.Count == 1 && _activeSession.CompletionSets[0].Completions.Count == 1) { _activeSession.Commit(); } else { AttachKeyboardFilter(); _activeSession.Dismissed += new EventHandler(OnSessionDismissedOrCommitted); _activeSession.Committed += new EventHandler(OnSessionDismissedOrCommitted); } } }
public virtual ICompletionSession TriggerCompletion() { return(CompletionBroker.TriggerCompletion(TextView)); }
public virtual ICompletionSession TriggerCompletion() => CompletionBroker.TriggerCompletion(TextView);