/// <summary> /// Display list of potential tokens /// </summary> bool StartSession() { if (_currentSession != null) { return(false); } SnapshotPoint caret = TextView.Caret.Position.BufferPosition; ITextSnapshot snapshot = caret.Snapshot; if (!Broker.IsCompletionActive(TextView)) { _currentSession = Broker.CreateCompletionSession(TextView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); } else { _currentSession = Broker.GetSessions(TextView)[0]; } _currentSession.Dismissed += (sender, args) => _currentSession = null; /// KEY: start the session and called class CompletionSourceProvider : ICompletionSourceProvider _currentSession.Start(); return(true); }
private bool StartSession() { //the caret must be in a non-projection location SnapshotPoint?caretPoint = _textView.Caret.Position.Point.GetPoint(textBuffer => (!textBuffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor); if (!caretPoint.HasValue) { return(false); } _currentSession = _provider.CompletionBroker.CreateCompletionSession(_textView, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), true); if (_currentSession != null) { _currentSession.Dismissed += this.OnSessionDismissed; //subscribe to the Dismissed event on the session _currentSession.Start(); MplPackage.completionSession = true; return(true); } else { return(false); } }
private bool TriggerCompletion() { try { if (m_session != null) { return(false); } // the caret must be in a non-projection location SnapshotPoint?caretPoint = m_textView.Caret.Position.Point.GetPoint( textBuffer => (!textBuffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor); if (!caretPoint.HasValue) { return(false); } m_session = m_provider.CompletionBroker.CreateCompletionSession( m_textView, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), true); // subscribe to the Dismissed event on the session m_session.Dismissed += this.OnSessionDismissed; m_session.Start(); return(true); } catch { } return(false); }
private bool CompletionTrigger() { if (_session_sighelp != null) { _session_sighelp.Dismiss(); } if (_session_completion != null) { _session_completion.Dismiss(); } SnapshotPoint?caretPoint = _textview.Caret.Position.Point.GetPoint(textBuffer => (!textBuffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor); CaretPosition curPosition = _textview.Caret.Position; var curTrackPoint = _textview.TextSnapshot.CreateTrackingPoint(curPosition.BufferPosition.Position, Microsoft.VisualStudio.Text.PointTrackingMode.Positive); if (!caretPoint.HasValue) { return(false); } _session_completion = _nsicprovider._completionbroker.CreateCompletionSession(_textview, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), false); _session_completion.Dismissed += CompletionDismiss; _session_completion.Committed += CompletionDismiss; _session_completion.Start(); Debug.Print("NS - CompletionTrigger"); return(true); }
public void PresentItems( ITrackingSpan triggerSpan, IList <CompletionItem> completionItems, CompletionItem selectedItem, CompletionItem suggestionModeItem, bool suggestionMode, bool isSoftSelected, ImmutableArray <CompletionItemFilter> completionItemFilters, string filterText) { AssertIsForeground(); // check if this update is still relevant if (_textView.IsClosed || _isDismissed) { return; } if (triggerSpan != null) { _completionSet.SetTrackingSpan(triggerSpan); } _ignoreSelectionStatusChangedEvent = true; try { _completionSet.SetCompletionItems( completionItems, selectedItem, suggestionModeItem, suggestionMode, isSoftSelected, completionItemFilters, filterText); } finally { _ignoreSelectionStatusChangedEvent = false; } if (_editorSessionOpt == null) { // We're tracking the caret. Don't have the editor do it. // Map the span instead of a point to avoid affinity problems. _editorSessionOpt = _completionBroker.CreateCompletionSession( _textView, triggerSpan.GetStartTrackingPoint(PointTrackingMode.Negative), trackCaret: false); _editorSessionOpt.Dismissed += (s, e) => OnEditorSessionDismissed(); // So here's the deal. We cannot create the editor session and give it the right // items (even though we know what they are). Instead, the session will call // back into the ICompletionSourceProvider (which is us) to get those values. It // will pass itself along with the calls back into ICompletionSourceProvider. // So, in order to make that connection work, we add properties to the session // so that we can call back into ourselves, get the items and add it to the // session. _editorSessionOpt.Properties.AddProperty(Key, this); _editorSessionOpt.Start(); } // Call so that the editor will refresh the completion text to embolden. _editorSessionOpt?.Match(); }
/// <summary> /// Begins a new autocomplete session when the user begins to type a Markdown header. /// </summary> /// <returns>True if the session was created successfully, false if it failed or if /// an active autocomplete session already existed.</returns> private bool StartMarkdownAutocompleteSession() { try { if (MarkdownCompletionSession != null) { return(false); } // Get the caret point in the editor and pass it to the new autocomplete session SnapshotPoint?caretPoint = TextView.Caret.Position.Point.GetPoint( textBuffer => (!textBuffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor); MarkdownCompletionSession = Provider.CompletionBroker.CreateCompletionSession( TextView, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), true); MarkdownCompletionSession.Dismissed += MarkdownCompletionSession_Dismissed; MarkdownCompletionSession.Start(); return(true); } catch (Exception ex) { Logger.Warn($"Creating an autocomplete session failed: {ex.GetType().Name} - {ex.Message}"); Logger.Trace(ex.StackTrace); return(false); } }
private bool StartSession() { if (currentSession != null) { return(false); } SnapshotPoint caret = TextView.Caret.Position.BufferPosition; ITextSnapshot snapshot = caret.Snapshot; if (!Broker.IsCompletionActive(TextView)) { currentSession = Broker.CreateCompletionSession(TextView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); } else { currentSession = Broker.GetSessions(TextView)[0]; } currentSession.Dismissed += (sender, args) => currentSession = null; if (!currentSession.IsStarted) { currentSession.Start(); } return(true); }
public bool StartSession(int offset) { if (m_session != null) { return(false); } m_session_offset = offset; SnapshotPoint caret = m_view.Caret.Position.BufferPosition; ITextSnapshot snapshot = caret.Snapshot; if (!m_broker.IsCompletionActive(m_view)) { m_session = m_broker.CreateCompletionSession(m_view, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); } else { m_session = m_broker.GetSessions(m_view)[0]; } if (m_session == null) { return(false); } m_session.Dismissed += SessionDismissed; if (!m_session.IsStarted) { m_session.Start(); } return(true); }
bool StartSession() { if (_currentSession != null) { return(false); } SnapshotPoint caret = textView.Caret.Position.BufferPosition; if (caret.Position == 0) { return(false); } ITextSnapshot snapshot = caret.Snapshot; if (!provider.CompletionBroker.IsCompletionActive(textView)) { _currentSession = provider.CompletionBroker.CreateCompletionSession(textView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); } else { _currentSession = provider.CompletionBroker.GetSessions(textView)[0]; } _currentSession.Dismissed += (sender, args) => _currentSession = null; if (!_currentSession.IsStarted) { _currentSession.Start(); } return(true); }
private void TriggerCompletion(ICompletionBroker completionBroker) { if (_session != null) { return; } var caret = _textView.Caret; var caretPosition = caret.Position; var caretPoint = caretPosition.Point.GetPoint(textBuffer => (!textBuffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor); if (!caretPoint.HasValue) { return; } var snapshot = caretPoint.Value.Snapshot; var trackingPoint = snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive); _session = completionBroker.CreateCompletionSession(_textView, trackingPoint, false); _session.Dismissed += OnSessionDismissed; _session.Start(); if (IsSessionAlive) { _session.Filter(); } }
protected bool StartAutoCompleteSession(char?ch) { if (IsAutoCompleteSessionActive) { return(false); } SnapshotPoint caret = TextView.Caret.Position.BufferPosition; ITextSnapshot snapshot = caret.Snapshot; if (!ShouldCompletionBeDiplayed(caret, ch)) { return(false); } currentAutoCompleteSession = !Broker.IsCompletionActive(TextView) ? Broker.CreateCompletionSession(TextView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true) : Broker.GetSessions(TextView)[0]; currentAutoCompleteSession.Start(); currentAutoCompleteSession.Dismissed += (sender, args) => currentAutoCompleteSession = null; currentAutoCompleteSession.SelectedCompletionSet.Filter(); currentAutoCompleteSession.SelectedCompletionSet.SelectBestMatch(); currentAutoCompleteSession.SelectedCompletionSet.Recalculate(); return(true); }
private void TriggerCompletion(bool force = false) { if (force && _currentSession != null && !_currentSession.IsDismissed) { _currentSession.Dismiss(); } var lineText = TextView.Caret.Position.BufferPosition.GetContainingLine().GetText().Trim(); if (!Parser.StepRegex.IsMatch(lineText)) { return; } var caretPoint = TextView.Caret.Position.Point.GetPoint( textBuffer => !textBuffer.ContentType.IsOfType("projection"), PositionAffinity.Predecessor); if (!caretPoint.HasValue) { return; } _currentSession = Broker.CreateCompletionSession (TextView, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), true); _currentSession.Dismissed += OnSessionDismissed; _currentSession.Start(); }
private bool TriggerCompletion( ) { // The caret must be in a non-projection location var caretPoint = m_textView.Caret.Position.Point.GetPoint(textBuffer => !textBuffer.ContentType.IsOfType("projection"), PositionAffinity.Predecessor); if (!caretPoint.HasValue) { return(false); } var trackingPoint = caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive); m_session = m_provider.CompletionBroker.CreateCompletionSession(m_textView, trackingPoint, true); // Subscribe to the Dismissed event on the session m_session.Dismissed += OnSessionDismissed; m_session.Start( ); // Wait to start while (!m_session.IsStarted && !m_session.IsDismissed) { } return(!m_session.IsStarted && !m_session.IsDismissed); }
// 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); }
/// <summary> /// Display list of potential tokens /// </summary> bool StartSession() { if (_currentSession != null) { return(false); } SnapshotPoint caret = TextView.Caret.Position.BufferPosition; ITextSnapshot snapshot = caret.Snapshot; if (!Broker.IsCompletionActive(TextView)) { // System.Diagnostics.Debug.WriteLine("OCompletion Controller NOT Broker.IsCompletionActive"); _currentSession = Broker.CreateCompletionSession(TextView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); } else { // System.Diagnostics.Debug.WriteLine("OCompletion Controller Broker.IsCompletionActive"); _currentSession = Broker.GetSessions(TextView)[0]; } _currentSession.Dismissed += (sender, args) => _currentSession = null; _currentSession.Start(); 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 bool TriggerCompletion() { if (session != null) { session.Dismiss(); } PrepareTriggerPoint(); // since we might have modified the // buffer, check if that didn't kick another session if (AnySessionsActive()) { return(false); } var caretPoint = textView.Caret.Position.BufferPosition; var snapshot = caretPoint.Snapshot; var triggerPoint = snapshot.CreateTrackingPoint( caretPoint, PointTrackingMode.Negative); session = provider.CompletionBroker.CreateCompletionSession( this.textView, triggerPoint, false); if (session != null) { session.Dismissed += this.OnSessionDismissed; PlainTextCompletionContext.Add(session); session.Start(); return(true); } return(false); }
/// <summary> /// Display list of potential tokens /// </summary> bool StartSession() { if (_currentSession != null) { return(false); } SnapshotPoint caret = TextView.Caret.Position.BufferPosition; ITextSnapshot snapshot = caret.Snapshot; if (!_emojiLocationHandler.CanHazEmoji(new SnapshotSpan(caret - 1, caret))) { return(false); } if (!Broker.IsCompletionActive(TextView)) { _currentSession = Broker.CreateCompletionSession(TextView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); } else { _currentSession = Broker.GetSessions(TextView)[0]; } _currentSession.Dismissed += (sender, args) => _currentSession = null; if (!_currentSession.IsStarted) { _currentSession.Start(); } return(true); }
private bool Start() { // Handle non-existant Sessions if (_currentSession != null) { return(false); } // Get the current position within the buffer and take a snapshot SnapshotPoint caret = _textView.Caret.Position.BufferPosition; ITextSnapshot snapshot = caret.Snapshot; // Generate a session based off of the existing broker and textview if (!_broker.IsCompletionActive(_textView)) { _currentSession = _broker.CreateCompletionSession(_textView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); } else { _currentSession = _broker.GetSessions(_textView)[0]; } // Wire up a handler to dispose of the session _currentSession.Dismissed += (sender, args) => _currentSession = null; // Start the new session _currentSession.Start(); return(true); }
bool StartSession() { if (_currentSession != null) { return(false); } SnapshotPoint caret = TextView.Caret.Position.BufferPosition; ITextSnapshot snapshot = caret.Snapshot; if (!Broker.IsCompletionActive(TextView)) { _currentSession = Broker.CreateCompletionSession(TextView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); } else { _currentSession = Broker.GetSessions(TextView)[0]; } _currentSession.Dismissed += (sender, args) => _currentSession = null; _currentSession.Start(); if (_quickInfoBroker.IsQuickInfoActive(TextView)) { foreach (IQuickInfoSession session in _quickInfoBroker.GetSessions(TextView)) { session.Dismiss(); } } return(true); }
private bool StartSession() { if (CurrentSession != null) { return(false); } var caret = TextView.Caret.Position.BufferPosition; var snapshot = caret.Snapshot; if (!Broker.IsCompletionActive(TextView)) { CurrentSession = Broker.CreateCompletionSession(TextView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); } else { CurrentSession = Broker.GetSessions(TextView)[0]; } CurrentSession.Dismissed += (_, __) => CurrentSession = null; try { CurrentSession.Start(); return(true); } catch { CurrentSession = null; return(false); } }
private void StartSession(ITrackingPoint triggerPoint) { Log.Debug("Creating new completion session..."); _activeSession = _broker.CreateCompletionSession(_textView, triggerPoint, true); _activeSession.Properties.AddProperty(BufferProperties.SessionOriginIntellisense, "Intellisense"); _activeSession.Dismissed += CompletionSession_Dismissed; _activeSession.Start(); }
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(); } } }
/// <summary> /// Triggers Statement completion when appropriate keys are pressed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void VisualElement_KeyDown(object sender, System.Windows.Input.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.textView != textView) { return; } // if there is a session already leave it be if (activeSession != null) { return; } // determine which subject buffer is affected by looking at the caret position SnapshotPoint?caret = textView.Caret.Position.Point.GetPoint (textBuffer => buffer == textBuffer, PositionAffinity.Predecessor); // return if no suitable buffer found if (!caret.HasValue) { return; } SnapshotPoint caretPoint = caret.Value; var subjectBuffer = caretPoint.Snapshot.TextBuffer; CompletionContext completionContext = AbstractCompletionSet.GetCompletionContext(e.Key, subjectBuffer, caretPoint.Position); // the invocation occurred in a subject buffer of interest to us triggerPosition = caretPoint.Position; ITrackingPoint triggerPoint = caretPoint.Snapshot.CreateTrackingPoint(triggerPosition, PointTrackingMode.Negative); completionSpan = caretPoint.Snapshot.CreateTrackingSpan(caretPoint.Position, 0, SpanTrackingMode.EdgeInclusive); // attach filter to intercept the Enter key attachKeyboardFilter(); // Create a completion session activeSession = provider.CompletionBroker.CreateCompletionSession(textView, triggerPoint, true); // Put the completion context and original (empty) completion span // on the session so that it can be used by the completion source activeSession.Properties.AddProperty(typeof(CompletionContext), completionContext); activeSession.Properties.AddProperty(typeof(Controller), completionSpan); // Attach to the session events activeSession.Dismissed += new System.EventHandler(OnActiveSessionDismissed); activeSession.Committed += new System.EventHandler(OnActiveSessionCommitted); // Start the completion session. The intellisense will be triggered. activeSession.Start(); }
void StartSession(CompletionInfo? info = null, CompletionTrigger? completionTrigger = null) { if (HasSession) return; var triggerPoint = textView.TextSnapshot.CreateTrackingPoint(textView.Caret.Position.BufferPosition.Position, PointTrackingMode.Negative, TrackingFidelityMode.Forward); completionSession = completionBroker.Value.CreateCompletionSession(textView, triggerPoint, trackCaret: true); if (completionTrigger != null) completionSession.Properties.AddProperty(typeof(CompletionTrigger), completionTrigger); completionSession.Dismissed += CompletionSession_Dismissed; completionSession.Start(); }
/// <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; } }
private void UpdateCompletions(object sender, EventArgs e) { ThreadHelper.Generic.BeginInvoke(DispatcherPriority.ApplicationIdle, () => { try { if (_currentCompletionSet == null || _currentSession == null) { return; } string displayText = _currentCompletionSet?.SelectionStatus?.Completion?.DisplayText; if (_nameSearchJob != null) { ProduceNameCompletionSet(); } else if (_versionSearchJob != null) { ProduceVersionCompletionSet(); } if (!_currentSession.IsStarted && _currentCompletionSet.Completions.Count > 0) { _isSelfTrigger = true; _currentSession = _completionBroker.CreateCompletionSession(_currentSession.TextView, _currentSession.GetTriggerPoint(_textBuffer), true); _currentSession.Start(); } if (!_currentSession.IsDismissed) { _currentSession.Filter(); if (displayText != null) { foreach (Microsoft.VisualStudio.Language.Intellisense.Completion completion in _currentSession.SelectedCompletionSet.Completions) { if (completion.DisplayText == displayText) { _currentCompletionSet.SelectionStatus = new CompletionSelectionStatus(completion, true, true); break; } } } //_currentSession.Dismiss(); //_currentSession = _completionBroker.TriggerCompletion(_currentSession.TextView); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }); }
bool StartSession() { if (Broker.IsCompletionActive(TextView)) { return(false); } else { _currentSession = null; } SnapshotPoint caret = TextView.Caret.Position.BufferPosition; if (caret.Position == 0) { return(false); } ITextSnapshot snapshot = caret.Snapshot; ICompletionSession currentSession = _currentSession; if (!Broker.IsCompletionActive(TextView)) { currentSession = Broker.CreateCompletionSession(TextView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); } else { currentSession = Broker.GetSessions(TextView)[0]; } _currentSession = currentSession; if (currentSession != null) { currentSession.Dismissed += (sender, args) => { if (sender is ICompletionSession session) { session.Committed -= HandleCompletionSessionCommit; } _currentSession = null; }; currentSession.Committed += HandleCompletionSessionCommit; if (!currentSession.IsStarted) { currentSession.Start(); } } return(true); }
private bool TriggerCompletion() { SnapshotPoint?caretPoint = textView.Caret.Position.Point.GetPoint(textBuffer => !textBuffer.ContentType.IsOfType("projection"), PositionAffinity.Predecessor); if (caretPoint.HasValue) { completionSession = completionHandlerProvider.CompletionBroker.CreateCompletionSession(textView, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), true); completionSession.Dismissed += completionSession_Dismissed; completionSession.Start(); return(true); } return(false); }
private void TriggerCompletion() { //the caret must be in a non-projection location SnapshotPoint?caretPoint = _mTextView.Caret.Position.Point.GetPoint( textBuffer => (!textBuffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor); if (!caretPoint.HasValue) { return; } var lineText = caretPoint.Value.GetContainingLine().GetText(); bool inside2String = false; bool inside1String = false; int i = caretPoint.Value.GetContainingLine().Start.Position; foreach (char c in lineText) { if (i >= caretPoint.Value.Position) { break; } if (c == '"') { inside2String = !inside2String; } if (c == '\'') { inside1String = !inside1String; } i++; } if (!inside2String && !inside1String) { return; } _mSession = _mProvider.CompletionBroker.CreateCompletionSession (_mTextView, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), true); //subscribe to the Dismissed event on the session _mSession.Dismissed += OnSessionDismissed; _mSession.Start(); }
private bool TriggerCompletion() { SnapshotPoint? caretPoint = textView.Caret.Position.Point.GetPoint(textBuffer => !textBuffer.ContentType.IsOfType("projection"), PositionAffinity.Predecessor); if (caretPoint.HasValue) { completionSession = completionHandlerProvider.CompletionBroker.CreateCompletionSession(textView, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), true); completionSession.Dismissed += completionSession_Dismissed; completionSession.Start(); return true; } return false; }
private bool TriggerCompletion() { //the caret must be in a non-projection location SnapshotPoint? caretPoint = _TextView.Caret.Position.Point .GetPoint( textBuffer => !IsProjection( textBuffer ), PositionAffinity.Predecessor ); if ( !caretPoint.HasValue ) { return false; } _Session = _CompletionHandlerProvider.CompletionBroker.CreateCompletionSession ( _TextView, caretPoint.Value.Snapshot.CreateTrackingPoint( caretPoint.Value.Position, PointTrackingMode.Positive ), true ); //subscribe to the Dismissed event on the session _Session.Dismissed += OnSessionDismissed; _Session.Start(); return true; }
/// <summary> /// Triggers Statement completion when appropriate keys are pressed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void VisualElement_KeyDown(object sender, System.Windows.Input.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; } // we only start the session when an alphanumeric key is pressed if (!(e.Key >= Key.A && e.Key <= Key.Z)) return; // if there is a session already leave it be if (activeSession != null) return; // determine which subject buffer is affected by looking at the caret position SnapshotPoint? caretPoint = textView.Caret.Position.Point.GetPoint (textBuffer => ( subjectBuffers.Contains(textBuffer) && provider.nodeProviderBroker.IsNDjango(textBuffer, context) && provider.CompletionBrokerMapService.GetBrokerForTextView(textView, textBuffer) != null ), PositionAffinity.Predecessor); // return if no suitable buffer found if (!caretPoint.HasValue) return; List<INode> completionNodes = provider.nodeProviderBroker.GetNodeProvider(caretPoint.Value.Snapshot.TextBuffer).GetNodes(caretPoint.Value) .FindAll(node => node.Values.Count() > 0); // return if there is no information to show if (completionNodes.Count == 0) return; // attach filter to intercept the Enter key attachKeyboardFilter(); // the invocation occurred in a subject buffer of interest to us ICompletionBroker broker = provider.CompletionBrokerMapService.GetBrokerForTextView(textView, caretPoint.Value.Snapshot.TextBuffer); ITrackingPoint triggerPoint = caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive); // Create a completion session activeSession = broker.CreateCompletionSession(triggerPoint, true); // Put the list of completion nodes on the session so that it can be used by the completion source activeSession.Properties.AddProperty(typeof(Source), completionNodes); // Attach to the session events activeSession.Dismissed += new System.EventHandler(OnActiveSessionDismissed); activeSession.Committed += new System.EventHandler(OnActiveSessionCommitted); // Start the completion session. The intellisense will be triggered. activeSession.Start(); }
private bool TriggerCompletion() { //the caret must be in a non-projection location SnapshotPoint? caretPoint = m_textView.Caret.Position.Point.GetPoint( textBuffer => (!textBuffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor); if (!caretPoint.HasValue) { return false; } m_session = m_provider.CompletionBroker.CreateCompletionSession (m_textView, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), true); //subscribe to the Dismissed event on the session m_session.Dismissed += this.OnSessionDismissed; m_session.Start(); return true; }
private void StartSession() { var caretPosition = wpfTextView.Caret.Position.Point.GetPoint( buffer => (!buffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor); if (!caretPosition.HasValue) { throw new InvalidOperationException("Cannot get carret point."); } session = autoCompletionHandlerProvider.CompletionBroker.CreateCompletionSession( wpfTextView, caretPosition.Value.Snapshot.CreateTrackingPoint(caretPosition.Value.Position, PointTrackingMode.Positive), true); session.Dismissed += SessionDismissed; session.Start(); if (session != null) { session.Filter(); } }
/// <summary> /// Triggers Statement completion when appropriate keys are pressed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void VisualElement_KeyDown(object sender, System.Windows.Input.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; // if there is a session already leave it be if (activeSession != null) return; // determine which subject buffer is affected by looking at the caret position SnapshotPoint? caret = textView.Caret.Position.Point.GetPoint (textBuffer => ( subjectBuffers.Contains(textBuffer) && provider.nodeProviderBroker.IsNDjango(textBuffer, context) && provider.CompletionBrokerMapService.GetBrokerForTextView(textView, textBuffer) != null ), PositionAffinity.Predecessor); // return if no suitable buffer found if (!caret.HasValue) return; SnapshotPoint caretPoint = caret.Value; var subjectBuffer = caretPoint.Snapshot.TextBuffer; CompletionContext completionContext = CompletionSet.GetCompletionContext(e.Key, subjectBuffer, caretPoint.Position); if (completionContext == CompletionContext.None) return; // the invocation occurred in a subject buffer of interest to us ICompletionBroker broker = provider.CompletionBrokerMapService.GetBrokerForTextView(textView, subjectBuffer); triggerPosition = caretPoint.Position; ITrackingPoint triggerPoint = caretPoint.Snapshot.CreateTrackingPoint(triggerPosition, PointTrackingMode.Negative); completionSpan = caretPoint.Snapshot.CreateTrackingSpan(caretPoint.Position, 0, SpanTrackingMode.EdgeInclusive); // attach filter to intercept the Enter key attachKeyboardFilter(); // Create a completion session activeSession = broker.CreateCompletionSession(triggerPoint, true); // Put the completion context and original (empty) completion span // on the session so that it can be used by the completion source activeSession.Properties.AddProperty(typeof(CompletionContext), completionContext); activeSession.Properties.AddProperty(typeof(Controller), completionSpan); // Attach to the session events activeSession.Dismissed += new System.EventHandler(OnActiveSessionDismissed); activeSession.Committed += new System.EventHandler(OnActiveSessionCommitted); // Start the completion session. The intellisense will be triggered. activeSession.Start(); }
bool StartSession() { if (_session != null) return false; var caret = _wpfTextView.Caret.Position.BufferPosition; var snapshot = caret.Snapshot; _session = _provider.CompletionBroker.CreateCompletionSession( _wpfTextView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); _session.Dismissed += _currentSession_Dismissed; _session.Start(); return true; }
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; // if there is a session already leave it be if (activeSession != null) return; // determine which subject buffer is affected by looking at the caret position SnapshotPoint? caret = textView.Caret.Position.Point.GetPoint(textBuffer => ( subjectBuffers.Contains(textBuffer)), PositionAffinity.Predecessor); // return if no suitable buffer found if (!caret.HasValue) return; SnapshotPoint caretPoint = caret.Value; ITextSnapshotLine line = caretPoint.GetContainingLine(); SnapshotSpan span = new SnapshotSpan(line.Start, line.End); if (span.IsComment() || span.IsCommand()) return; // the invocation occurred in a subject buffer of interest to us triggerPosition = caretPoint.Position; ITrackingPoint triggerPoint = caretPoint.Snapshot.CreateTrackingPoint(triggerPosition, PointTrackingMode.Negative); completionSpan = caretPoint.Snapshot.CreateTrackingSpan(caretPoint.Position, 0, SpanTrackingMode.EdgeInclusive); // Create a completion session activeSession = completionBroker.CreateCompletionSession(textView, triggerPoint, true); // Put the completion context and original (empty) completion span // on the session so that it can be used by the completion source activeSession.Properties.AddProperty(typeof(ApacheIntellisenseController), completionSpan); // Attach to the session events activeSession.Dismissed += new System.EventHandler(OnActiveSessionDismissed); activeSession.Committed += new System.EventHandler(OnActiveSessionCommitted); // Start the completion session. The intellisense will be triggered. activeSession.Start(); }
private void TriggerCompletion() { //the caret must be in a non-projection location var caretPoint = _textView.Caret.Position.Point.GetPoint(x => (true), PositionAffinity.Predecessor); if (!caretPoint.HasValue) return; _session = _provider.CompletionBroker.CreateCompletionSession (_textView, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), true); //subscribe to the Dismissed event on the session _session.Dismissed += OnSessionDismissed; _session.Start(); }
public void PresentItems( ITrackingSpan triggerSpan, IList<PresentationItem> completionItems, PresentationItem selectedItem, PresentationItem suggestionModeItem, bool suggestionMode, bool isSoftSelected, ImmutableArray<CompletionItemFilter> completionItemFilters, IReadOnlyDictionary<CompletionItem, string> completionItemToFilterText) { AssertIsForeground(); // check if this update is still relevant if (_textView.IsClosed || _isDismissed) { return; } if (triggerSpan != null) { _completionSet.SetTrackingSpan(triggerSpan); } _ignoreSelectionStatusChangedEvent = true; try { _completionSet.SetCompletionItems( completionItems, selectedItem, suggestionModeItem, suggestionMode, isSoftSelected, completionItemFilters, completionItemToFilterText); } finally { _ignoreSelectionStatusChangedEvent = false; } if (_editorSessionOpt == null) { // We're tracking the caret. Don't have the editor do it. // Map the span instead of a point to avoid affinity problems. _editorSessionOpt = _completionBroker.CreateCompletionSession( _textView, triggerSpan.GetStartTrackingPoint(PointTrackingMode.Negative), trackCaret: false); var debugTextView = _textView as IDebuggerTextView; if (debugTextView != null && !debugTextView.IsImmediateWindow) { debugTextView.HACK_StartCompletionSession(_editorSessionOpt); } _editorSessionOpt.Dismissed += (s, e) => OnEditorSessionDismissed(); // So here's the deal. We cannot create the editor session and give it the right // items (even though we know what they are). Instead, the session will call // back into the ICompletionSourceProvider (which is us) to get those values. It // will pass itself along with the calls back into ICompletionSourceProvider. // So, in order to make that connection work, we add properties to the session // so that we can call back into ourselves, get the items and add it to the // session. _editorSessionOpt.Properties.AddProperty(Key, this); _editorSessionOpt.Start(); } // Call so that the editor will refresh the completion text to embolden. _editorSessionOpt?.Match(); }
/// <summary> /// Trigger completion. /// </summary> private void TriggerCompletion() { // the caret must be in a non-projection location var caretPoint = textView.Caret.Position.Point.GetPoint(textBuffer => (!textBuffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor); if (!caretPoint.HasValue) { return; } var cp = (SnapshotPoint)caretPoint; var position = cp.Position; // check for "//" before the current cursor position in this line var line = ((SnapshotPoint)caretPoint).Snapshot.GetLineFromPosition(((SnapshotPoint)caretPoint).Position); // get the text of this line var text = line.GetText(); // get only the text portion which is left of the actual position text = text.Substring(0, position - line.Start.Position); // if there is a comment starting, don't do auto completion if (text.IndexOf("//", StringComparison.CurrentCultureIgnoreCase) != -1) { return; } var lex = new Lexer(cp.Snapshot.GetText()); lex.AnalyzeForCommentsOnly(); var res = lex.Tokens.FirstOrDefault(x => x.Position < cp.Position && x.Position + x.Length >= cp.Position); if (res != null) { return; } session = provider.CompletionBroker.CreateCompletionSession(textView, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), true); // subscribe to the Dismissed event on the session session.Dismissed += OnSessionDismissed; session.Start(); }
bool StartSession() { if (_currentSession != null) return false; SnapshotPoint caret = TextView.Caret.Position.BufferPosition; ITextSnapshot snapshot = caret.Snapshot; _currentSession = Broker.CreateCompletionSession(TextView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); _currentSession.Start(); _currentSession.Dismissed += (sender, args) => _currentSession = null; return true; }
protected bool StartAutoCompleteSession() { if (IsAutoCompleteSessionActive) return false; SnapshotPoint caret = TextView.Caret.Position.BufferPosition; ITextSnapshot snapshot = caret.Snapshot; if (!ShouldCompletionBeDiplayed(caret)) return false; currentAutoCompleteSession = !Broker.IsCompletionActive(TextView) ? Broker.CreateCompletionSession(TextView, snapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true) : Broker.GetSessions(TextView)[0]; currentAutoCompleteSession.Start(); currentAutoCompleteSession.Dismissed += (sender, args) => currentAutoCompleteSession = null; return true; }
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(); } } }
private bool TriggerCompletion() { if ( session != null ) { session.Dismiss(); } PrepareTriggerPoint(); // since we might have modified the // buffer, check if that didn't kick another session if ( AnySessionsActive() ) { return false; } var caretPoint = textView.Caret.Position.BufferPosition; var snapshot = caretPoint.Snapshot; var triggerPoint = snapshot.CreateTrackingPoint( caretPoint, PointTrackingMode.Negative); session = provider.CompletionBroker.CreateCompletionSession( this.textView, triggerPoint, false); if ( session != null ) { session.Dismissed += this.OnSessionDismissed; PlainTextCompletionContext.Add(session); session.Start(); return true; } return false; }