Exemple #1
0
        private void HandleChar(char ch)
        {
            // We trigger completions when the user types . or space.  Called via our IOleCommandTarget filter
            // on the text view.
            //
            // We trigger signature help when we receive a "(".  We update our current sig when
            // we receive a "," and we close sig help when we receive a ")".

            if (!_incSearch.IsActive)
            {
                switch (ch)
                {
                case '.':
                case ' ':
                    if (PythonToolsPackage.Instance.LangPrefs.AutoListMembers)
                    {
                        TriggerCompletionSession(false);
                    }
                    break;

                case '(':
                    if (PythonToolsPackage.Instance.LangPrefs.AutoListParams)
                    {
                        OpenParenStartSignatureSession();
                    }
                    break;

                case ')':
                    if (_sigHelpSession != null)
                    {
                        _sigHelpSession.Dismiss();
                        _sigHelpSession = null;
                    }

                    if (PythonToolsPackage.Instance.LangPrefs.AutoListParams)
                    {
                        // trigger help for outer call if there is one
                        TriggerSignatureHelp();
                    }
                    break;

                case ',':
                    if (_sigHelpSession == null)
                    {
                        if (PythonToolsPackage.Instance.LangPrefs.AutoListParams)
                        {
                            CommaStartSignatureSession();
                        }
                    }
                    else
                    {
                        UpdateCurrentParameter();
                    }
                    break;
                }
            }
        }
Exemple #2
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('('))
                {
                    //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();
                    /******************************************************************/
                    //if (word.Equals("add"))
                    if (!String.IsNullOrEmpty(word))
                    {
                        m_session = m_broker.TriggerSignatureHelp(m_textView);
                    }
                }
                else if (typedChar.Equals(')') && m_session != null)
                {
                    m_session.Dismiss();
                    m_session = null;
                }
            }
            return(m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
        /// <summary>
        /// Check if the property name in the text buffer has changed.
        /// If so, then dismiss the syntax help tip.
        /// </summary>
        private void OnTextBufferChanged(object sender, TextContentChangedEventArgs eventArgs)
        {
            if (_trackingSpan != null && _session != null)
            {
                ITextSnapshot snapshot               = _trackingSpan.TextBuffer.CurrentSnapshot;
                SnapshotPoint startPoint             = _trackingSpan.GetStartPoint(snapshot);
                bool          propertyNameStillValid = false;

                if (startPoint.Position + _propertyName.Length <= snapshot.Length)
                {
                    // Get the current text at the beginning of the tracking span.

                    string text = snapshot.GetText(startPoint.Position, _propertyName.Length);

                    char afterText = (startPoint.Position + _propertyName.Length < snapshot.Length)
                        ? snapshot.GetText(startPoint.Position + _propertyName.Length, 1)[0]
                        : '\0';

                    if (string.Equals(text, _propertyName, StringComparison.OrdinalIgnoreCase) &&
                        !char.IsLetterOrDigit(afterText) &&
                        afterText != '-')
                    {
                        // The correct property name is still in the code
                        propertyNameStillValid = true;
                    }
                }

                if (!propertyNameStillValid)
                {
                    _session.Dismiss();
                }
            }
        }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
            {
                var typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
                if (typedChar.Equals('('))
                {
                    // Move the point back so it's in the preceding word
                    var point  = _textView.Caret.Position.BufferPosition - 1;
                    var extent = _navigator.GetExtentOfWord(point);
                    var word   = extent.Span.GetText();

                    if (word.Equals("emplace") || word.Equals("emplace_back"))
                    {
                        _session = _broker.TriggerSignatureHelp(_textView);
                    }
                }
                else if (typedChar.Equals(')') && _session != null)
                {
                    _session.Dismiss();
                    _session = null;
                }
            }

            return(_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
        /// <summary>
        /// Check if the property name in the text buffer has changed.
        /// If so, then dismiss the syntax help tip.
        /// </summary>
        private void OnTextBufferChanged(object sender, TextContentChangedEventArgs eventArgs)
        {
            if (_trackingSpan != null && _session != null)
            {
                ITextSnapshot snapshot               = _trackingSpan.TextBuffer.CurrentSnapshot;
                SnapshotPoint startPoint             = _trackingSpan.GetStartPoint(snapshot);
                bool          propertyNameStillValid = false;

                if (startPoint.Position + _propertyName.Length <= snapshot.Length)
                {
                    string text = _trackingSpan.GetText(snapshot);

                    if (text.StartsWith("[", StringComparison.Ordinal))
                    {
                        // The correct property name is still in the code
                        propertyNameStillValid = true;
                        _session.Match();
                    }
                }

                if (!propertyNameStillValid)
                {
                    _session.Dismiss();
                }
            }
        }
		bool IIntellisenseCommandTarget.ExecuteKeyboardCommand(IntellisenseKeyboardCommand command) {
			switch (command) {
			case IntellisenseKeyboardCommand.Escape:
				session.Dismiss();
				return true;

			case IntellisenseKeyboardCommand.Up:
				if (session.Signatures.Count > 1) {
					IncrementSelectedSignature(-1);
					return true;
				}
				return false;

			case IntellisenseKeyboardCommand.Down:
				if (session.Signatures.Count > 1) {
					IncrementSelectedSignature(1);
					return true;
				}
				return false;

			case IntellisenseKeyboardCommand.PageUp:
			case IntellisenseKeyboardCommand.PageDown:
			case IntellisenseKeyboardCommand.Home:
			case IntellisenseKeyboardCommand.End:
			case IntellisenseKeyboardCommand.TopLine:
			case IntellisenseKeyboardCommand.BottomLine:
			case IntellisenseKeyboardCommand.Enter:
			case IntellisenseKeyboardCommand.IncreaseFilterLevel:
			case IntellisenseKeyboardCommand.DecreaseFilterLevel:
			default:
				return false;
			}
		}
Exemple #7
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));
        }
Exemple #8
0
 private void DismissSession()
 {
     if (_session != null)
     {
         _session.Dismiss();
         _session = null;
     }
 }
        private void HandleTypeChar(char typedChar)
        {
            switch (typedChar)
            {
            case '(':
                StartSignatureSession();
                break;

            case ')':
                if (_signatureSession != null)
                {
                    _signatureSession.Dismiss();
                    _signatureSession = null;
                }
                break;
            }
        }
        /// <summary>
        /// Triggers Statement completion when appropriate keys are pressed
        /// The key combination is CTRL-J or "."
        /// The intellisense window is dismissed when one presses ESC key
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPreprocessKeyDown(object sender, TextCompositionEventArgs e)
        {
            // We should only receive pre-process events from our text view
            Debug.Assert(sender == _textView);

            // TODO: We should handle = for signature completion of keyword arguments

            // We trigger completions when the user types . or space.  Our EditFilter will
            // also trigger completions when we receive the VSConstants.VSStd2KCmdID.SHOWMEMBERLIST
            // command or the VSConstants.VSStd2KCmdID.COMPLETEWORD command.
            //
            // We trigger signature help when we receive a "(".  We update our current sig when
            // we receive a "," and we close sig help when we receive a ")".

            switch (e.Text)
            {
            case ".":
            case " ":
                //DeleteSelectedSpans();
                TriggerCompletionSession(false);
                break;

            case "(": OpenParenStartSignatureSession(); break;

            case ")":
                if (_sigHelpSession != null)
                {
                    _sigHelpSession.Dismiss();
                    _sigHelpSession = null;
                }
                break;

            case ",":
                if (_sigHelpSession == null)
                {
                    CommaStartSignatureSession();
                }
                else
                {
                    CommaAdvanceParameter();
                }
                break;
            }
        }
        public virtual void DismissSignatureHelp()
        {
            ISignatureHelpSession session = SignatureHelpSession;

            SignatureHelpSession = null;
            if (session != null && !session.IsDismissed)
            {
                session.Dismiss();
            }
        }
Exemple #12
0
 public void TriggerSignatureHelp()
 {
     if (_session != null)
     {
         _session.Dismiss();
     }
     else
     {
         UpdateModel();
     }
 }
Exemple #13
0
            public void Dismiss()
            {
                AssertIsForeground();

                if (_editorSessionOpt == null)
                {
                    // No editor session, nothing to do here.
                    return;
                }

                _editorSessionOpt.Dismiss();
                _editorSessionOpt = null;
            }
        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('('))
                {
                    //move the point back so it's in the preceding word
                    //
                    SnapshotPoint point  = this.textView.Caret.Position.BufferPosition - 1;
                    TextExtent    extent = this.navigator.GetExtentOfWord(point);
                    string        word   = extent.Span.GetText();

                    // if have on session dialog already, dismiss it.
                    //
                    if (session != null)
                    {
                        session.Dismiss();
                    }

                    if (ShaderlabDataManager.Instance.UnityBuiltinFunctions.Any(f => f.Name.Equals(word, StringComparison.CurrentCultureIgnoreCase)) ||
                        ShaderlabDataManager.Instance.HLSLCGFunctions.Any(f => f.Name.Equals(word, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        session = this.broker.TriggerSignatureHelp(this.textView);
                    }
                }
                else if (typedChar.Equals(')') && session != null)
                {
                    session.Dismiss();
                    session = null;
                }
            }
            return(nextCommand.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
 public void Dispose()
 {
     if (isDisposed)
     {
         return;
     }
     isDisposed = true;
     CancelFetchItems();
     if (session != null)
     {
         session.Dismissed -= Session_Dismissed;
         session.Dismiss();
     }
     session = null;
     signatures.Clear();
     Disposed?.Invoke(this, EventArgs.Empty);
 }
        public int Exec(ref Guid cmdGroup, uint cmdId, uint cmdExecOpt, IntPtr pvaIn, IntPtr pvaOut)
        {
            char inputCharacter = char.MinValue;

            if (cmdGroup == VSConstants.VSStd2K && cmdId == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
            {
                inputCharacter = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
                if (inputCharacter.Equals(' '))
                {
                    SnapshotPoint currentPosition = _textView.Caret.Position.BufferPosition - 1;
                    TextExtent    extentOfWord    = _navigator.GetExtentOfWord(currentPosition);
                    string        tagName         = extentOfWord.Span.GetText();
                    _session = _broker.TriggerSignatureHelp(_textView);
                }
                else if (inputCharacter.Equals('>') && _session != null)
                {
                    _session.Dismiss();
                    _session = null;
                }
            }
            return(_nextCommand.Exec(cmdGroup, cmdId, cmdExecOpt, pvaIn, pvaOut));
        }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            Logger.Exec(pguidCmdGroup, nCmdID);
            if (VsShellUtilities.IsInAutomationFunction(Provider.ServiceProvider))
            {
                return(NextCmdHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }

            uint commandID = nCmdID;
            char typedChar = char.MinValue;

            //make sure the input is a char before getting it
            if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
            {
                typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
            }

            while (true)
            {
                //check for a commit character
                if (nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN ||
                    nCmdID == (uint)VSConstants.VSStd2KCmdID.TAB ||
                    (char.IsWhiteSpace(typedChar) ||
                     JavaSessionCompletions.AutocompleteCommitChars.Contains(typedChar)))
                {
                    if (CompletionSession != null && !CompletionSession.IsDismissed)
                    {
                        if (CompletionSession.SelectedCompletionSet.SelectionStatus.IsSelected)
                        {
                            // Only commit selection if typedChar is not part of the current selection. This will allow typing . when autocompleting package names without closing ACL
                            if (CompletionSession.SelectedCompletionSet.SelectionStatus.Completion.InsertionText.Contains(typedChar))
                            {
                                break;
                            }

                            int adjustCursor = 0;
                            if (CompletionSession.SelectedCompletionSet.SelectionStatus.Completion.InsertionText.EndsWith(")")) // Eclipse returns functions already appended with (); we'll fix up cursor position post insertion
                            {
                                adjustCursor = -1;
                            }

                            JavaSessionCompletions sessionCompletions = null;
                            if (CompletionSession.Properties.TryGetProperty <JavaSessionCompletions>(typeof(JavaSessionCompletions), out sessionCompletions))
                            {
                                sessionCompletions.Commit(CompletionSession, typedChar);
                            }

                            if (adjustCursor != 0)
                            {
                                TextView.Caret.MoveTo(TextView.Caret.Position.BufferPosition.Add(adjustCursor));
                                if (SignatureSession != null)
                                {
                                    SignatureSession.Dismiss();
                                }
                                TriggerSignatureHelp();
                            }

                            Telemetry.Client.Get().TrackTrace(String.Format("ACL Session completed on nCMDID = {0}; typedChar = {1}; adjustCursor = {2}", nCmdID, typedChar, adjustCursor));

                            if (typedChar == char.MinValue || (typedChar == '(' && adjustCursor != 0))
                            {
                                return(VSConstants.S_OK); // don't add the character to the buffer if it's an ENTER, TAB or a open-paran (in the case of a method call)
                            }
                        }
                        else
                        {
                            // If no selection, dismiss the session
                            CompletionSession.Dismiss();

                            Telemetry.Client.Get().TrackTrace(String.Format("ACL Session dismissed on nCMDID = {0}; typedChar = {1}", nCmdID, typedChar));
                        }
                    }
                }
                break;
            }

            // Update param help?
            if (commandID == (uint)VSConstants.VSStd2KCmdID.LEFT)
            {
                if (SignatureSession != null)
                {
                    UpdateCurrentParameter(TextView.Caret.Position.BufferPosition.Position - 1);
                }
            }
            else if (commandID == (uint)VSConstants.VSStd2KCmdID.RIGHT)
            {
                if (SignatureSession != null)
                {
                    UpdateCurrentParameter(TextView.Caret.Position.BufferPosition.Position + 1);
                }
            }
            else if (commandID == (uint)VSConstants.VSStd2KCmdID.BACKSPACE)
            {
                if (SignatureSession != null)
                {
                    SnapshotPoint?caretPoint = TextView.Caret.Position.Point.GetPoint(
                        textBuffer => (!textBuffer.ContentType.IsOfType("projection")),
                        PositionAffinity.Predecessor);
                    if (caretPoint.HasValue && caretPoint.Value.Position != 0)
                    {
                        var deleting = TextView.TextSnapshot.GetText(caretPoint.Value.Position - 1, 1).First();
                        if (JavaSignatureHelpSessionSignatures.ParamHelpReevaluateTriggers.Contains(deleting))
                        {
                            UpdateCurrentParameter(caretPoint.Value.Position - 1);
                        }
                        else if (JavaSignatureHelpSessionSignatures.ParamHelpTriggers.Contains(deleting))
                        {
                            SignatureSession.Dismiss();
                            // TODO: May need to launch the nested param help
                        }
                    }
                }
            }

            if (commandID == (uint)VSConstants.VSStd97CmdID.GotoDefn)
            {
                SnapshotPoint?caretPoint = TextView.Caret.Position.Point.GetPoint(
                    textBuffer => (!textBuffer.ContentType.IsOfType("projection")),
                    PositionAffinity.Predecessor);
                if (caretPoint.HasValue && caretPoint.Value.Position != 0)
                {
                    var fireAndForgetTask = new JavaGotoDefinition(TextView, Provider, caretPoint.Value).Run(Provider.EditorFactory);
                }
                return(VSConstants.S_OK);
            }

            // Pass along the command so the char is added to the buffer
            int  retVal  = NextCmdHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
            bool handled = false;

            // Trigger Param help?
            if (JavaSignatureHelpSessionSignatures.ParamHelpTriggers.Contains(typedChar) ||
                commandID == (uint)VSConstants.VSStd2KCmdID.PARAMINFO)
            {
                if (SignatureSession != null)
                {
                    SignatureSession.Dismiss();
                }
                TriggerSignatureHelp();

                Telemetry.Client.Get().TrackTrace(String.Format("ParamHelp Session started on nCMDID = {0}; typedChar = {1}", VSConstants.VSStd2KCmdID.PARAMINFO.ToString(), typedChar));
            }
            // Comma found while typing -> update paramhelp
            else if (JavaSignatureHelpSessionSignatures.ParamHelpReevaluateTriggers.Contains(typedChar))
            {
                if (SignatureSession != null)
                {
                    UpdateCurrentParameter();
                }
            }
            // End of param help?
            else if (JavaSignatureHelpSessionSignatures.ParamHelpEndTrigger.Contains(typedChar))
            {
                if (SignatureSession != null)
                {
                    SignatureSession.Dismiss();
                    TriggerSignatureHelp(); // Just in case there is a nested call

                    Telemetry.Client.Get().TrackTrace(String.Format("ParamHelp Session ended and restarted on nCMDID = {0}; typedChar = {1}", commandID, typedChar));
                }
            }
            else if (commandID == (uint)VSConstants.VSStd2KCmdID.HOME ||
                     commandID == (uint)VSConstants.VSStd2KCmdID.BOL ||
                     commandID == (uint)VSConstants.VSStd2KCmdID.BOL_EXT ||
                     commandID == (uint)VSConstants.VSStd2KCmdID.END ||
                     commandID == (uint)VSConstants.VSStd2KCmdID.WORDPREV ||
                     commandID == (uint)VSConstants.VSStd2KCmdID.WORDPREV_EXT ||
                     commandID == (uint)VSConstants.VSStd2KCmdID.DELETEWORDLEFT)
            {
                if (SignatureSession != null)
                {
                    SignatureSession.Dismiss();

                    Telemetry.Client.Get().TrackTrace(String.Format("ParamHelp Session ended on nCMDID = {0}; typedChar = {1}", commandID, typedChar));
                }
            }

            // Trigger autocomplete?
            if (JavaSessionCompletions.AutocompleteTriggers.Contains(typedChar))
            {
                if (CompletionSession == null || CompletionSession.IsDismissed)
                {
                    // If there is no active session, begin one
                    TriggerCompletion();
                    Telemetry.Client.Get().TrackTrace(String.Format("ACL Session started on nCMDID = {0}; typedChar = {1}", commandID, typedChar));
                }
                else
                {
                    CompletionSession.SelectedCompletionSet.SelectBestMatch();
                }
                handled = true;
            }
            else if (commandID == (uint)VSConstants.VSStd2KCmdID.COMPLETEWORD ||
                     commandID == (uint)VSConstants.VSStd2KCmdID.AUTOCOMPLETE)
            {
                if (CompletionSession != null)
                {
                    CompletionSession.Dismiss();
                }

                TriggerCompletion();
                Telemetry.Client.Get().TrackTrace(String.Format("ACL Session started on nCMDID = {0}; typedChar = {1}", commandID, typedChar));

                handled = true;
            }
            else if (commandID == (uint)VSConstants.VSStd2KCmdID.BACKSPACE ||
                     commandID == (uint)VSConstants.VSStd2KCmdID.DELETE)
            {
                // Redo the filter if there is a deletion
                if (CompletionSession != null && !CompletionSession.IsDismissed)
                {
                    CompletionSession.SelectedCompletionSet.SelectBestMatch();
                }
                handled = true;
            }
            // For any other char, we update the list if a session is already started
            else if (!typedChar.Equals(char.MinValue) && char.IsLetterOrDigit(typedChar))
            {
                if (CompletionSession != null && !CompletionSession.IsDismissed)
                {
                    CompletionSession.SelectedCompletionSet.SelectBestMatch();
                }
                handled = true;
            }

            if (handled)
            {
                return(VSConstants.S_OK);
            }
            return(retVal);
        }
Exemple #18
0
        private static void CommaFindBestSignature(ISignatureHelpSession sigHelpSession, int curParam, string lastKeywordArg) {
            // see if we have a signature which accomodates this...

            // TODO: We should also get the types of the arguments and use that to
            // pick the best signature when the signature includes types.
            var bestSig = sigHelpSession.SelectedSignature as PythonSignature;
            if (bestSig != null) {
                for (int i = 0; i < bestSig.Parameters.Count; ++i) {
                    if (bestSig.Parameters[i].Name == lastKeywordArg ||
                        lastKeywordArg == null && (i == curParam || PythonSignature.IsParamArray(bestSig.Parameters[i].Name))
                    ) {
                        bestSig.SetCurrentParameter(bestSig.Parameters[i]);
                        sigHelpSession.SelectedSignature = bestSig;
                        return;
                    }
                }
            }

            PythonSignature fallback = null;
            foreach (var sig in sigHelpSession.Signatures.OfType<PythonSignature>().OrderBy(s => s.Parameters.Count)) {
                fallback = sig;
                for (int i = 0; i < sig.Parameters.Count; ++i) {
                    if (sig.Parameters[i].Name == lastKeywordArg ||
                        lastKeywordArg == null && (i == curParam || PythonSignature.IsParamArray(sig.Parameters[i].Name))
                    ) {
                        sig.SetCurrentParameter(sig.Parameters[i]);
                        sigHelpSession.SelectedSignature = sig;
                        return;
                    }
                }
            }

            if (fallback != null) {
                fallback.SetCurrentParameter(null);
                sigHelpSession.SelectedSignature = fallback;
            } else {
                sigHelpSession.Dismiss();
            }
        }
 private void CancelSignatureSession() =>
 _currentSignatureSession?.Dismiss();
        private void HandleChar(char ch)
        {
            // We trigger completions when the user types . or space.  Called via our IOleCommandTarget filter
            // on the text view.
            //
            // We trigger signature help when we receive a "(".  We update our current sig when
            // we receive a "," and we close sig help when we receive a ")".

            if (!_incSearch.IsActive)
            {
                switch (ch)
                {
                case '@':
                    if (!string.IsNullOrWhiteSpace(GetTextBeforeCaret(-1)))
                    {
                        break;
                    }
                    goto case '.';

                case '.':
                case ' ':
                    if (_provider.PythonService.LangPrefs.AutoListMembers)
                    {
                        TriggerCompletionSession(false, true);
                    }
                    break;

                case '(':
                    if (_provider.PythonService.LangPrefs.AutoListParams)
                    {
                        OpenParenStartSignatureSession();
                    }
                    break;

                case ')':
                    if (_sigHelpSession != null)
                    {
                        _sigHelpSession.Dismiss();
                        _sigHelpSession = null;
                    }

                    if (_provider.PythonService.LangPrefs.AutoListParams)
                    {
                        // trigger help for outer call if there is one
                        TriggerSignatureHelp();
                    }
                    break;

                case '=':
                case ',':
                    if (_sigHelpSession == null)
                    {
                        if (_provider.PythonService.LangPrefs.AutoListParams)
                        {
                            CommaStartSignatureSession();
                        }
                    }
                    else
                    {
                        UpdateCurrentParameter();
                    }
                    break;

                default:
                    if (IsIdentifierFirstChar(ch) &&
                        (_activeSession == null || _activeSession.CompletionSets.Count == 0))
                    {
                        bool commitByDefault;
                        if (ShouldTriggerIdentifierCompletionSession(out commitByDefault))
                        {
                            TriggerCompletionSession(false, commitByDefault);
                        }
                    }
                    break;
                }
            }
        }
Exemple #21
0
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            try
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                if (VsShellUtilities.IsInAutomationFunction(_provider.ServiceProvider))
                {
                    return(_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
                }

                var commandId = nCmdID;
                var typedChar = char.MinValue;

                if (pguidCmdGroup == typeof(VSConstants.VSStd97CmdID).GUID)
                {
                    if (nCmdID == (uint)VSConstants.VSStd97CmdID.GotoDefn)
                    {
                        Navigation.GoToDefinitionHelper.TriggerGoToDefinition(_textView);
                        return(VSConstants.S_OK);
                    }
                    else if (nCmdID == (uint)VSConstants.VSStd97CmdID.FindReferences)
                    {
                        Navigation.GoToDefinitionHelper.TriggerFindReferences(_textView);
                        return(VSConstants.S_OK);
                    }
                }

                if (pguidCmdGroup == VSConstants.VSStd2K)
                {
                    if (nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
                    {
                        typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
                        if (typedChar == '(')
                        {
                            var appSettings = ProbeEnvironment.CurrentAppSettings;
                            var fileName    = VsTextUtil.TryGetDocumentFileName(_textView.TextBuffer);
                            if (_textView.Caret.Position.BufferPosition.IsInLiveCode(fileName, appSettings))
                            {
                                SnapshotPoint point    = _textView.Caret.Position.BufferPosition;
                                var           pos      = point.Position;
                                var           lineText = point.Snapshot.GetLineTextUpToPosition(pos).TrimEnd();

                                if (lineText.Length > 0 && lineText[lineText.Length - 1].IsWordChar(false))
                                {
                                    if (_session != null && !_session.IsDismissed)
                                    {
                                        _session.Dismiss();
                                    }
                                    s_typedChar = typedChar;
                                    _session    = _broker.TriggerSignatureHelp(_textView);
                                }
                            }
                        }
                        else if (typedChar == ')' && _session != null)
                        {
                            if (!_session.IsDismissed)
                            {
                                _session.Dismiss();
                            }
                            _session = null;
                        }
                        else if (typedChar == ',' && (_session == null || _session.IsDismissed))
                        {
                            var appSettings = ProbeEnvironment.CurrentAppSettings;
                            var fileName    = VsTextUtil.TryGetDocumentFileName(_textView.TextBuffer);
                            if (_textView.Caret.Position.BufferPosition.IsInLiveCode(fileName, appSettings))
                            {
                                var fileStore = CodeModel.FileStore.GetOrCreateForTextBuffer(_textView.TextBuffer);
                                if (fileStore != null)
                                {
                                    var model    = fileStore.GetMostRecentModel(appSettings, fileName, _textView.TextSnapshot, "Signature help command handler - after ','");
                                    var modelPos = _textView.Caret.Position.BufferPosition.TranslateTo(model.Snapshot, PointTrackingMode.Negative).Position;

                                    var argsToken = model.File.FindDownward <CodeModel.Tokens.ArgsToken>(modelPos).Where(t => t.Span.Start < modelPos && (t.Span.End > modelPos || !t.IsTerminated)).LastOrDefault();
                                    if (argsToken != null)
                                    {
                                        s_typedChar = typedChar;
                                        _session    = _broker.TriggerSignatureHelp(_textView);
                                    }
                                }
                            }
                        }
                    }
                    else if (nCmdID == (uint)VSConstants.VSStd2KCmdID.GOTOBRACE)
                    {
                        Navigation.GoToBraceHelper.Trigger(_textView, false);
                        return(VSConstants.S_OK);
                    }
                    else if (nCmdID == (uint)VSConstants.VSStd2KCmdID.GOTOBRACE_EXT)
                    {
                        Navigation.GoToBraceHelper.Trigger(_textView, true);
                        return(VSConstants.S_OK);
                    }
                    else if (nCmdID == (uint)VSConstants.VSStd2KCmdID.COMMENT_BLOCK)
                    {
                        Tagging.Tagger.CommentBlock();
                        return(VSConstants.S_OK);
                    }
                    else if (nCmdID == (uint)VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK)
                    {
                        Tagging.Tagger.UncommentBlock();
                        return(VSConstants.S_OK);
                    }
                }

                return(_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }
            catch (Exception ex)
            {
                Log.WriteEx(ex);
                return(VSConstants.E_FAIL);
            }
        }
Exemple #22
0
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            //if (VsShellUtilities.IsInAutomationFunction(_nsicprovider._serviceprovider_sys)) {
            //    return m_commandhandler_next.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
            //}
            uint commandID = nCmdID;
            char typedChar = char.MinValue;

            // test input is a char
            if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
            {
                typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
            }

            if (pguidCmdGroup == VSConstants.VSStd2K)
            {
                switch ((VSConstants.VSStd2KCmdID)nCmdID)
                {
                case VSConstants.VSStd2KCmdID.AUTOCOMPLETE:
                    Debug.Print("AUTOCOMPLETE");
                    break;

                case VSConstants.VSStd2KCmdID.COMPLETEWORD:
                    Debug.Print("COMPLETEWORD");
                    break;

                case VSConstants.VSStd2KCmdID.RETURN:
                    Debug.Print("RETURN");
                    break;

                case VSConstants.VSStd2KCmdID.TAB:
                    Debug.Print("TAB");
                    break;

                case VSConstants.VSStd2KCmdID.CANCEL:
                    Debug.Print("CANCEL");
                    break;

                case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST:
                    Debug.Print("SHOWMEMBERLIST");
                    NSPackage.memberlist = true;
                    break;

                case VSConstants.VSStd2KCmdID.PARAMINFO:
                    Debug.Print("PARAMINFO");
                    break;

                case VSConstants.VSStd2KCmdID.QUICKINFO:
                    Debug.Print("QUICKINFO");
                    NSPackage.quickinfo = true;
                    break;

                default:
                    break;
                }
            }
            if (pguidCmdGroup == VSStd97Cmds)
            {
                switch ((VSConstants.VSStd97CmdID)nCmdID)
                {
                case VSConstants.VSStd97CmdID.FileClose:
                    Debug.Print("Close");
                    break;

                case VSConstants.VSStd97CmdID.FileOpen:
                    Debug.Print("FileOpen");
                    break;
                }
            }

            if (_session_completion != null)
            {
                // commit
                if (nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN || nCmdID == (uint)VSConstants.VSStd2KCmdID.TAB || (char.IsWhiteSpace(typedChar) || char.IsPunctuation(typedChar)))
                {
                    if (_session_completion != null && !_session_completion.IsDismissed)
                    {
                        // if selection is fully selected, commit
                        if (_session_completion.SelectedCompletionSet.SelectionStatus.IsSelected)
                        {
                            _session_completion.Commit();
                            return(VSConstants.S_OK); // don't add to buffer
                        }
                        else
                        {
                            // no selection, dismiss
                            _session_completion.Dismiss();
                        }
                    }
                }
                return(m_commandhandler_next.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }

            if (_session_sighelp != null)
            {
                int rval = 0;
                switch ((VSConstants.VSStd2KCmdID)nCmdID)
                {
                case VSConstants.VSStd2KCmdID.BACKSPACE:
                    bool fDeleted = Backspace();
                    if (fDeleted)
                    {
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.LEFT:
                    rval = m_commandhandler_next.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);

                    //_editops.MoveToPreviousCharacter(false);
                    ((NSSigSource.NSSignature)_session_sighelp.SelectedSignature).ParamCurrentCalc();
                    return(rval);

                //return VSConstants.S_OK;
                case VSConstants.VSStd2KCmdID.RIGHT:
                    //_editops.MoveToNextCharacter(false);
                    rval = m_commandhandler_next.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                    ((NSSigSource.NSSignature)_session_sighelp.SelectedSignature).ParamCurrentCalc();
                    return(rval);

                case VSConstants.VSStd2KCmdID.DOWN:
                case VSConstants.VSStd2KCmdID.UP:
                    rval = m_commandhandler_next.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                    ((NSSigSource.NSSignature)_session_sighelp.SelectedSignature).ParamCurrentCalc();
                    return(rval);

                case VSConstants.VSStd2KCmdID.CANCEL:
                    _session_sighelp.Dismiss();
                    _session_sighelp = null;
                    break;

                case VSConstants.VSStd2KCmdID.PAGEDN:
                    _session_sighelp.Dismiss();
                    _session_sighelp = null;
                    Debug.Print("NS - sighelp dismiss");
                    break;

                case VSConstants.VSStd2KCmdID.HOME:
                case VSConstants.VSStd2KCmdID.BOL:
                case VSConstants.VSStd2KCmdID.BOL_EXT:
                case VSConstants.VSStd2KCmdID.EOL:
                case VSConstants.VSStd2KCmdID.EOL_EXT:
                case VSConstants.VSStd2KCmdID.END:
                case VSConstants.VSStd2KCmdID.WORDPREV:
                case VSConstants.VSStd2KCmdID.WORDPREV_EXT:
                case VSConstants.VSStd2KCmdID.DELETEWORDLEFT:
                    _session_sighelp.Dismiss();
                    _session_sighelp = null;
                    break;
                }
            }

            //if ((VSConstants.VSStd2KCmdID)nCmdID == VSConstants.VSStd2KCmdID.SHOWMEMBERLIST || (!typedChar.Equals(char.MinValue) && char.IsLetterOrDigit(typedChar))) {
            if ((VSConstants.VSStd2KCmdID)nCmdID == VSConstants.VSStd2KCmdID.SHOWMEMBERLIST)
            {
                if (_session_completion == null || _session_completion.IsDismissed)
                {
                    this.CompletionTrigger();
                    if (_session_completion == null)
                    {
                        Debug.Print("NimStudio - Completion session not created.");
                    }
                    else
                    {
                        Debug.Print("NimStudio - Completion session created. Tot:" + _session_completion.CompletionSets.Count.ToString());
                        _session_completion.Filter();
                        return(VSConstants.S_OK);
                    }
                }
                else
                {
                    _session_completion.Filter(); // session active
                    return(VSConstants.S_OK);
                }
            }

            if ((VSConstants.VSStd2KCmdID)nCmdID == VSConstants.VSStd2KCmdID.PARAMINFO)
            {
                if (_session_sighelp == null || _session_sighelp.IsDismissed)
                {
                    this.SigHelpTrigger();
                    if (_session_sighelp == null)
                    {
                        Debug.Print("NS - _session_sighelp not created.");
                    }
                    else
                    {
                        Debug.Print("NS - _session_sighelp created.");
                        return(VSConstants.S_OK);
                    }
                }
                else
                {
                    _session_sighelp.Recalculate(); // session active
                    return(VSConstants.S_OK);
                }
            }

            if (commandID == (uint)VSConstants.VSStd2KCmdID.BACKSPACE || commandID == (uint)VSConstants.VSStd2KCmdID.DELETE)
            {
                if (_session_completion != null && !_session_completion.IsDismissed)
                {
                    // update completion
                    _session_completion.Filter();
                    return(VSConstants.S_OK);
                }
            }

            return(m_commandhandler_next.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Exemple #23
0
        /// <summary>
        /// Triggers Statement completion when appropriate keys are pressed
        /// The key combination is CTRL-J or "."
        /// The intellisense window is dismissed when one presses ESC key
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPreprocessKeyDown(object sender, TextCompositionEventArgs e)
        {
            // We should only receive pre-process events from our text view
            Debug.Assert(sender == _textView);

            // TODO: We should handle = for signature completion of keyword arguments

            // We trigger completions when the user types . or space.  Our EditFilter will
            // also trigger completions when we receive the VSConstants.VSStd2KCmdID.SHOWMEMBERLIST
            // command or the VSConstants.VSStd2KCmdID.COMPLETEWORD command.
            //
            // We trigger signature help when we receive a "(".  We update our current sig when
            // we receive a "," and we close sig help when we receive a ")".
            if (!_incSearch.IsActive)
            {
                switch (e.Text)
                {
                case ".":
                case " ":
                    if (IronPythonToolsPackage.Instance.LangPrefs.AutoListMembers)
                    {
                        TriggerCompletionSession(false);
                    }
                    break;

                case "(":
                    if (IronPythonToolsPackage.Instance.LangPrefs.AutoListParams)
                    {
                        OpenParenStartSignatureSession();
                    }
                    break;

                case ")":
                    if (_sigHelpSession != null)
                    {
                        _sigHelpSession.Dismiss();
                        _sigHelpSession = null;
                    }

                    if (IronPythonToolsPackage.Instance.LangPrefs.AutoListParams)
                    {
                        // trigger help for outer call if there is one
                        TriggerSignatureHelp();
                    }
                    break;

                case ",":
                    if (_sigHelpSession == null)
                    {
                        if (IronPythonToolsPackage.Instance.LangPrefs.AutoListParams)
                        {
                            CommaStartSignatureSession();
                        }
                    }
                    else
                    {
                        UpdateCurrentParameter();
                    }
                    break;
                }
            }
        }
Exemple #24
0
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            char typedChar = char.MinValue;
            int  result    = VSConstants.S_OK;
            Guid cmdGroup  = pguidCmdGroup;

            ThreadHelper.ThrowIfNotOnUIThread();

            // 1. Pre-process

            if (XSettings.DisableParameterInfo)
            {
                ;
            }
            else if (pguidCmdGroup == VSConstants.VSStd2K)
            {
                switch (nCmdID)
                {
                case (int)VSConstants.VSStd2KCmdID.PARAMINFO:
                    StartSignatureSession(true);
                    break;

                case (int)VSConstants.VSStd2KCmdID.COMPLETEWORD:
                case (int)VSConstants.VSStd2KCmdID.AUTOCOMPLETE:
                case (int)VSConstants.VSStd2KCmdID.SHOWMEMBERLIST:
                    CancelSignatureSession();
                    break;

                case (int)VSConstants.VSStd2KCmdID.BACKSPACE:
                    if (_signatureSession != null)
                    {
                        int pos = _textView.Caret.Position.BufferPosition;
                        if (pos > 0)
                        {
                            // get previous char
                            var previous = _textView.TextBuffer.CurrentSnapshot.GetText().Substring(pos - 1, 1);
                            if (previous == "(" || previous == "{")
                            {
                                _signatureSession.Dismiss();
                            }
                        }
                    }
                    break;
                }
            }
            else if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                switch (nCmdID)
                {
                case (int)VSConstants.VSStd97CmdID.Undo:
                case (int)VSConstants.VSStd97CmdID.Redo:
                    CancelSignatureSession();
                    break;
                }
            }
            var completionActive = IsCompletionActive();

            // 2. Let others do their thing
            result = m_nextCommandHandler.Exec(ref cmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
            // 3. Post process
            if (ErrorHandler.Succeeded(result) && !XSettings.DisableParameterInfo)
            {
                if (pguidCmdGroup == VSConstants.VSStd2K)
                {
                    switch (nCmdID)
                    {
                    case (int)VSConstants.VSStd2KCmdID.TYPECHAR:
                        typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
                        switch (typedChar)
                        {
                        case '(':
                        case '{':
                            CancelSignatureSession();
                            StartSignatureSession(false, triggerchar: typedChar);
                            break;

                        case ')':
                        case '}':
                            CancelSignatureSession();
                            if (hasopenSignatureSession())
                            {
                                StartSignatureSession(false, triggerchar: typedChar);
                            }
                            break;

                        case ',':
                            StartSignatureSession(true, triggerchar: typedChar);
                            //MoveSignature();
                            break;

                        case ':':
                        case '.':
                            CancelSignatureSession();
                            break;
                        }
                        break;

                    case (int)VSConstants.VSStd2KCmdID.RETURN:
                        if (!completionActive)
                        {
                            CancelSignatureSession();
                        }
                        break;

                    case (int)VSConstants.VSStd2KCmdID.LEFT:
                    case (int)VSConstants.VSStd2KCmdID.RIGHT:
                        MoveSignature();
                        break;
                    }
                }
            }
            return(result);
        }
        private void HandleChar(char ch)
        {
            // We trigger completions when the user types . or space.  Called via our IOleCommandTarget filter
            // on the text view.
            //
            // We trigger signature help when we receive a "(".  We update our current sig when
            // we receive a "," and we close sig help when we receive a ")".

            if (!_incSearch.IsActive)
            {
                switch (ch)
                {
                case '.':
                case ' ':
                    if (NodejsPackage.Instance.LangPrefs.AutoListMembers)
                    {
                        TriggerCompletionSession(false);
                    }
                    break;

                case '/':
                case '\'':
                case '"':
                    if (CompletionSource.ShouldTriggerRequireIntellisense(_textView.Caret.Position.BufferPosition, _classifier, true, true))
                    {
                        TriggerCompletionSession(false);
                    }
                    break;

                case '(':
                    if (CompletionSource.ShouldTriggerRequireIntellisense(_textView.Caret.Position.BufferPosition, _classifier, true))
                    {
                        TriggerCompletionSession(false);
                    }
                    else if (NodejsPackage.Instance.LangPrefs.AutoListParams)
                    {
                        OpenParenStartSignatureSession();
                    }
                    break;

                case ')':
                    if (_sigHelpSession != null)
                    {
                        _sigHelpSession.Dismiss();
                        _sigHelpSession = null;
                    }

                    if (NodejsPackage.Instance.LangPrefs.AutoListParams)
                    {
                        // trigger help for outer call if there is one
                        TriggerSignatureHelp();
                    }
                    break;

                case '=':
                case ',':
                    if (_sigHelpSession == null)
                    {
                        if (NodejsPackage.Instance.LangPrefs.AutoListParams)
                        {
                            CommaStartSignatureSession();
                        }
                    }
                    else
                    {
                        UpdateCurrentParameter();
                    }
                    break;

                default:
                    if (IsIdentifierFirstChar(ch) && _activeSession == null &&
                        NodejsPackage.Instance.LangPrefs.AutoListMembers &&
                        NodejsPackage.Instance.IntellisenseOptionsPage.ShowCompletionListAfterCharacterTyped)
                    {
                        TriggerCompletionSession(false);
                    }
                    break;
                }
            }
        }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (VsShellUtilities.IsInAutomationFunction(m_provider.ServiceProvider))
            {
                return(m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }
            //make a copy of this so we can look at it after forwarding some commands
            uint commandID = nCmdID;
            char typedChar = char.MinValue;

            //make sure the input is a char before getting it
            if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
            {
                typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
            }

            if (typedChar.Equals('('))
            {
                m_signatureHelpSession = m_broker.TriggerSignatureHelp(m_textView);
            }
            else if (typedChar.Equals(')') && m_signatureHelpSession != null)
            {
                m_signatureHelpSession.Dismiss();
                m_signatureHelpSession = null;
            }

            //check for a commit character
            if (nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN ||
                nCmdID == (uint)VSConstants.VSStd2KCmdID.TAB)
            {
                //check for a a selection
                if (m_session != null && !m_session.IsDismissed)
                {
                    //if the selection is fully selected, commit the current session
                    if (m_session.SelectedCompletionSet.SelectionStatus.IsSelected)
                    {
                        m_session.Commit();
                        //also, don't add the character to the buffer
                        return(VSConstants.S_OK);
                    }
                    else
                    {
                        //if there is no selection, dismiss the session
                        m_session.Dismiss();
                    }
                }
            }

            //pass along the command so the char is added to the buffer
            int  retVal  = m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
            bool handled = false;

            if (!typedChar.Equals(char.MinValue) && (char.IsLetterOrDigit(typedChar) || typedChar.Equals('.')))
            {
                if (m_session == null || m_session.IsDismissed) // If there is no active session, bring up completion
                {
                    if (this.TriggerCompletion())
                    {
                        // Session can be immediately dismissed which causes it to
                        // null out here. So we need to be paranoid.
                        if (m_session != null)
                        {
                            m_session.Filter();
                        }
                    }
                }
                else    //the completion session is already active, so just filter
                {
                    m_session.Filter();
                }
                handled = true;
            }
            else if (commandID == (uint)VSConstants.VSStd2KCmdID.BACKSPACE || //redo the filter if there is a deletion
                     commandID == (uint)VSConstants.VSStd2KCmdID.DELETE)
            {
                if (m_session != null && !m_session.IsDismissed)
                {
                    m_session.Filter();
                }
                handled = true;
            }
            if (handled)
            {
                return(VSConstants.S_OK);
            }
            return(retVal);
        }
Exemple #27
0
            internal void ParamCurrentCalc()
            {
                if (m_session.IsDismissed == true || m_session == null)
                {
                    return;
                }

                NSUtil.DebugPrintAlways("NSSig - ParamCurrentCalc");
                if (m_parameters.Count == 0)
                {
                    this.CurrentParameter = null;
                    return;
                }

                //SnapshotPoint? point_trigger_null = m_session.GetTriggerPoint(m_subjectBuffer.CurrentSnapshot);
                SnapshotPoint point_trigger = (SnapshotPoint)m_session.GetTriggerPoint(m_subjectBuffer.CurrentSnapshot);

                var trigger_linenum = m_subjectBuffer.CurrentSnapshot.GetLineNumberFromPosition(point_trigger.Position);

                SnapshotPoint point_curr2 = m_session.TextView.Caret.Position.BufferPosition;
                SnapshotPoint point_curr  = (SnapshotPoint)m_session.TextView.BufferGraph.MapUpToBuffer(
                    point_curr2, PointTrackingMode.Positive, PositionAffinity.Successor, m_subjectBuffer.CurrentSnapshot.TextBuffer);
                //if (!point_curr2.HasValue) return;
                //SnapshotPoint point_curr = point_curr2.Value;
                var curr_linenum = m_subjectBuffer.CurrentSnapshot.GetLineNumberFromPosition(point_curr.Position);

                SnapshotPoint point_left = m_applicabletospan.GetStartPoint(m_subjectBuffer.CurrentSnapshot);

                string sig_str = m_applicabletospan.GetText(m_subjectBuffer.CurrentSnapshot);

                if (curr_linenum != trigger_linenum || point_curr < point_left)
                {
                    m_session.Dismiss();
                    return;
                }

                SnapshotPoint point_test = point_curr - 1;

                int commas_count = 0;

                while (true)
                {
                    if (point_test <= point_left)
                    {
                        break;
                    }
                    if (point_test.GetChar() == ',')
                    {
                        commas_count += 1;
                    }
                    if (point_test.GetChar() == ')')
                    {
                        m_session.Dismiss();
                        return;
                    }
                    point_test -= 1;
                }

                if (commas_count < m_parameters.Count)
                {
                    this.CurrentParameter = m_parameters[commas_count];
                }
                else
                {
                    this.CurrentParameter = m_parameters[m_parameters.Count - 1];
                }
                return;
            }