public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { char typedChar = char.MinValue; if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR) { typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn); if (typedChar.Equals('(') && (m_session == null || m_session.IsDismissed)) { //move the point back so it's in the preceding word SnapshotPoint point = m_textView.Caret.Position.BufferPosition - 1; TextExtent extent = m_navigator.GetExtentOfWord(point); string word = extent.Span.GetText(); m_session = m_broker.CreateSignatureHelpSession(m_textView, m_textView.TextSnapshot.CreateTrackingPoint(point.Position, PointTrackingMode.Positive), true); m_session.Properties.AddProperty("word", word); m_session.Start(); } else if (typedChar.Equals(',') && (m_session == null || m_session.IsDismissed)) { int paramPos; int pos = m_textView.Caret.Position.BufferPosition - 1; while (pos > 0 && m_textView.TextSnapshot[pos] != '(') { pos--; } if (pos > 0) { paramPos = pos; pos--; while (pos > 0 && char.IsWhiteSpace(m_textView.TextSnapshot[pos])) { pos--; } if (pos > 0) { SnapshotPoint point = new SnapshotPoint(m_textView.TextSnapshot, pos); TextExtent extent = m_navigator.GetExtentOfWord(point); string word = extent.Span.GetText(); m_session = m_broker.CreateSignatureHelpSession(m_textView, m_textView.TextSnapshot.CreateTrackingPoint(m_textView.Caret.Position.BufferPosition - 1, PointTrackingMode.Positive), true); m_session.Properties.AddProperty("word", word); m_session.Properties.AddProperty("span", new Span(paramPos, m_textView.Caret.Position.BufferPosition - paramPos)); m_session.Start(); } } } else if (typedChar.Equals(')') && m_session != null) { m_session.Dismiss(); m_session = null; } else if (m_session != null && m_session.IsDismissed) { m_session = null; } } return(m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut)); }
public ISignatureHelpSession TriggerSignatureHelp(ITextView textView, ITrackingPoint triggerPoint, bool trackCaret) { ISignatureHelpSession session = this.CreateSignatureHelpSession(textView, triggerPoint, trackCaret); session.Start(); if (session.IsDismissed) { return(null); } return(session); }
private bool StartSignatureSession() { if (_signatureSession == null) { // Move the caret back to the preceding word SnapshotPoint caret = _textView.Caret.Position.BufferPosition - 1; TextExtent extent = _textNavigator.GetExtentOfWord(caret); string word = extent.Span.GetText(); _signatureSession = _signatureBroker.TriggerSignatureHelp(_textView); _signatureSession.Dismissed += (sender, args) => _signatureSession = null; _signatureSession.Start(); return(true); } return(false); }
private bool SigHelpTrigger() { 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_sighelp = _nsicprovider._signaturehelpbroker.CreateSignatureHelpSession(_textview, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), false); _session_sighelp.Dismissed += SigHelpDismiss; _session_sighelp.Start(); Debug.Print("NS - SigHelpTrigger"); return(true); }
private void StartSignatureSession() { if (_currentSignatureSession != null) { return; } if (_signatureHelpBroker.IsSignatureHelpActive(_textView)) { _currentSignatureSession = _signatureHelpBroker.GetSessions(_textView)[0]; } else { var point = _textView.Caret.Position.BufferPosition; var snapshot = point.Snapshot; var trackingPoint = snapshot.CreateTrackingPoint(point, PointTrackingMode.Positive); _currentSignatureSession = _signatureHelpBroker.CreateSignatureHelpSession(_textView, trackingPoint, true); _textView.TextBuffer.Properties.AddProperty(typeof(ISignatureHelpSession), _currentSignatureSession); } _currentSignatureSession.Dismissed += SignatureSessionDismissed; _currentSignatureSession.Start(); }
internal bool StartSignatureSession(bool comma, IXTypeSymbol type = null, string methodName = null, char triggerchar = '\0') { WriteOutputMessage("StartSignatureSession()"); if (_signatureSession != null) { return(false); } IXMemberSymbol currentElement = null; SnapshotPoint ssp = this._textView.Caret.Position.BufferPosition; if (triggerchar == '(' && ssp.Position < ssp.Snapshot.Length && ssp.GetChar() == ')') { ssp -= 1; } var location = _textView.FindLocation(ssp); if (location == null || location.Member == null) { return(false); } if (location.Member.Range.StartLine == location.LineNumber) { return(false); } var props = new XSharpSignatureProperties(location); props.triggerChar = triggerchar; props.triggerPosition = this._textView.Caret.Position.BufferPosition.Position; if (type != null && methodName != null) { var findStatic = triggerchar == '.'; currentElement = XSharpLookup.SearchMethod(location, type, methodName, Modifiers.Private, findStatic).FirstOrDefault(); } else { currentElement = findElementAt(comma, ssp, props); } if (currentElement == null) { return(false); } SnapshotPoint caret = _textView.Caret.Position.BufferPosition; ITextSnapshot caretsnapshot = caret.Snapshot; // if (_signatureBroker.IsSignatureHelpActive(_textView)) { _signatureSession = _signatureBroker.GetSessions(_textView)[0]; } else { _signatureSession = _signatureBroker.CreateSignatureHelpSession(_textView, caretsnapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); } _signatureSession.Properties[typeof(XSharpSignatureProperties)] = props; if (location.Member.Kind.IsGlobalTypeMember()) { props.Visibility = Modifiers.Public; } else { props.Visibility = Modifiers.Protected; } _signatureSession.Dismissed += OnSignatureSessionDismiss; props.Element = currentElement; if (comma) { var tokenList = XSharpTokenTools.GetTokenListBeforeCaret(location, out var state); bool done = false; int nested = 0; for (int i = tokenList.Count - 1; i >= 0 && !done; i--) { var token = tokenList[i]; switch (token.Type) { case XSharpLexer.LPAREN: case XSharpLexer.LCURLY: case XSharpLexer.LBRKT: done = nested == 0; if (done) { props.Start = token.Position; props.Length = _textView.Caret.Position.BufferPosition.Position - token.Position; } nested -= 1; break; case XSharpLexer.RPAREN: case XSharpLexer.RCURLY: case XSharpLexer.RBRKT: nested += 1; break; } } } else { props.Start = ssp.Position; props.Length = _textView.Caret.Position.BufferPosition.Position - ssp.Position; } try { _signatureSession.Start(); } catch (Exception e) { XSettings.LogException(e, "Start Signature session failed:"); } // return(true); }