예제 #1
0
        /// <summary>
        /// Updates the current parameter assuming the caret is at the provided position.
        ///
        /// This will analyze the buffer for where we are currently located, find the current
        /// parameter that we're entering, and then update the signature.  If our current
        /// signature does not have enough parameters we'll find a signature which does.
        /// </summary>
        private void UpdateCurrentParameter(int position)
        {
            // we advance to the next parameter
            // TODO: Take into account params arrays
            // TODO: need to parse and see if we have keyword arguments entered into the current signature yet
            PythonSignature sig = _sigHelpSession.SelectedSignature as PythonSignature;

            if (sig != null)
            {
                var textBuffer = _textView.TextBuffer;
                position = Math.Min(position, textBuffer.CurrentSnapshot.Length);
                var span = textBuffer.CurrentSnapshot.CreateTrackingSpan(position, 0, SpanTrackingMode.EdgeInclusive);

                var sigs     = _provider._Analyzer.GetSignatures(textBuffer.CurrentSnapshot, textBuffer, span);
                int curParam = sigs.ParameterIndex;

                if (curParam < sig.Parameters.Count)
                {
                    sig.SetCurrentParameter(sig.Parameters[curParam]);
                }
                else
                {
                    CommaFindBestSignature(curParam);
                }
            }
        }
예제 #2
0
        private bool Backspace()
        {
            if (_sigHelpSession != null)
            {
                if (_textView.Selection.IsActive && !_textView.Selection.IsEmpty)
                {
                    // when deleting a selection don't do anything to pop up signature help again
                    _sigHelpSession.Dismiss();
                    return(false);
                }

                SnapshotPoint?caretPoint = GetCaretPoint();
                if (caretPoint != null && caretPoint.Value.Position != 0)
                {
                    string deleting = _textView.TextSnapshot.GetText(caretPoint.Value.Position - 1, 1);
                    if (deleting == ",")
                    {
                        PythonSignature sig = _sigHelpSession.SelectedSignature as PythonSignature;
                        if (sig != null)
                        {
                            int curParam = sig.Parameters.IndexOf(sig.CurrentParameter);

                            if (curParam > 0)
                            {
                                sig.SetCurrentParameter(sig.Parameters[curParam - 1]);
                            }
                        }
                    }
                    else if (deleting == "(")
                    {
                        _sigHelpSession.Dismiss();
                        // delete the ( before triggering help again
                        _textView.TextSnapshot.TextBuffer.Delete(new Span(caretPoint.Value.Position - 1, 1));

                        //
                        // Pop to an outer nesting of signature help
                        if (IronPythonToolsPackage.Instance.LangPrefs.AutoListParams)
                        {
                            TriggerSignatureHelp();
                        }

                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #3
0
        private static ISignature[] GetLiveSignatures(string text, ICollection <OverloadDoc> liveSigs, int paramIndex, ITrackingSpan span)
        {
            ISignature[] res = new ISignature[liveSigs.Count];
            int          i   = 0;

            foreach (var sig in liveSigs)
            {
                var parameters = new ParameterResult[sig.Parameters.Count];
                int j          = 0;
                foreach (var param in sig.Parameters)
                {
                    parameters[j++] = new ParameterResult(param.Name);
                }

                res[i++] = new PythonSignature(
                    span,
                    new LiveOverloadResult(text, sig.Documentation, parameters),
                    paramIndex
                    );
            }
            return(res);
        }
예제 #4
0
        private void CommaFindBestSignature(int curParam)
        {
            // see if we have a signature which accomodates this...

            // TODO: We should also take into account param arrays
            // TODO: We should also get the types of the arguments and use that to
            // pick the best signature when the signature includes types.
            foreach (var availableSig in _sigHelpSession.Signatures)
            {
                if (availableSig.Parameters.Count > curParam)
                {
                    _sigHelpSession.SelectedSignature = availableSig;

                    PythonSignature sig = availableSig as PythonSignature;
                    if (sig != null)
                    {
                        sig.SetCurrentParameter(sig.Parameters[curParam]);
                    }
                    break;
                }
            }
        }