Beispiel #1
0
        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 void PresentItems(
                ITrackingSpan triggerSpan,
                IList <SignatureHelpItem> signatureHelpItems,
                SignatureHelpItem selectedItem,
                int?selectedParameter)
            {
                _signatureHelpItems = signatureHelpItems;
                _selectedItem       = selectedItem;

                // Create all the editor signatures for the sig help items we have.
                this.CreateSignatures(triggerSpan, selectedParameter);

                // It's a new list of items.  Either create the editor session if this is the
                // first time, or ask the editor session that we already have to recalculate.
                if (_editorSessionOpt == null)
                {
                    // We're tracking the caret.  Don't have the editor do it.
                    _editorSessionOpt = _sigHelpBroker.CreateSignatureHelpSession(
                        _textView,
                        triggerSpan.GetStartTrackingPoint(PointTrackingMode.Negative),
                        trackCaret: false);

                    _editorSessionOpt.Dismissed += (s, e) => OnEditorSessionDismissed();
                    _editorSessionOpt.SelectedSignatureChanged += OnSelectedSignatureChanged;
                }

                // So here's the deal.  We cannot create the editor session and give it the right
                // signatures (even though we know what they are).  Instead, the session with
                // call back into the ISignatureHelpSourceProvider (which is us) to get those
                // values. It will pass itself along with the calls back into
                // ISignatureHelpSourceProvider. So, in order to make that connection work, we
                // add properties to the session so that we can call back into ourselves, get
                // the signatures and add it to the session.
                if (!_editorSessionOpt.Properties.ContainsProperty(s_augmentSessionKey))
                {
                    _editorSessionOpt.Properties.AddProperty(s_augmentSessionKey, this);
                }

                try
                {
                    // Don't want to get any callbacks while we do this.
                    _ignoreSelectionStatusChangedEvent = true;

                    _editorSessionOpt.Recalculate();

                    // Now let the editor know what the currently selected item is.
                    Contract.Requires(_signatureMap.ContainsKey(selectedItem));
                    Contract.ThrowIfNull(_signatureMap);

                    var defaultValue = _signatureMap.GetValueOrDefault(_selectedItem);
                    if (_editorSessionOpt != null)
                    {
                        _editorSessionOpt.SelectedSignature = defaultValue;
                    }
                }
                finally
                {
                    _ignoreSelectionStatusChangedEvent = false;
                }
            }
        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();
        }
Beispiel #4
0
        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);
        }