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;
                }
            }
Пример #2
0
        private void UpdateSession()
        {
            if (_session == null)
            {
                return;
            }

            UpdateModel();
            _session.Recalculate();
            _session.Match();
        }
Пример #3
0
        private void UpdateSession()
        {
            if (_session == null)
            {
                return;
            }

            UpdateModel().ContinueWith(t =>
            {
                if (_session == null)
                {
                    return;
                }
                _session.Recalculate();
                _session.Match();
            }, CancellationToken.None,
                                       TaskContinuationOptions.OnlyOnRanToCompletion,
                                       TaskScheduler.FromCurrentSynchronizationContext());
        }
        private void ChangeParameterSignatureSession()
        {
            if (_currentSignatureSession == null)
            {
                return;
            }
            if (_currentSignatureSession.Signatures.Count == 0)
            {
                return;
            }

            // all signatures have the same applicable span
            var trackingSpan    = _currentSignatureSession.Signatures[0].ApplicableToSpan;
            var currentPosition = _textView.Caret.Position.BufferPosition;
            var trackingStart   = trackingSpan.GetStartPoint(currentPosition.Snapshot);

            // check left border of applicable span, it might be invalid token
            if (trackingStart == currentPosition)
            {
                _currentSignatureSession.Recalculate();
                // if there is no applicable token, then current signatureSession will be null
                if (_currentSignatureSession == null)
                {
                    return;
                }
            }

            var searchParam  = new SnapshotSpan(trackingStart, currentPosition);
            var currentParam = searchParam.GetCurrentParameter(_signatureConfig.TriggerParameterChar);

            foreach (var signature in _currentSignatureSession.Signatures)
            {
                if (signature is ISyntaxSignature syntaxSignature)
                {
                    syntaxSignature.SetCurrentParameter(currentParam);
                }
            }
        }
Пример #5
0
        void StartSession(SnapshotPoint triggerPosition, SignatureHelpResult signatureHelpResult)
        {
            if (isDisposed || textView.IsClosed)
            {
                Dispose();
                return;
            }

            var triggerPoint   = triggerPosition.Snapshot.CreateTrackingPoint(triggerPosition.Position, PointTrackingMode.Negative);
            var applicableSpan = signatureHelpResult.Items.ApplicableSpan;
            var trackingSpan   = CreateApplicableToSpan(triggerPosition, applicableSpan);

            InitializeSignatures(trackingSpan, signatureHelpResult);

            if (session == null)
            {
                session            = signatureHelpBroker.Value.CreateSignatureHelpSession(textView, triggerPoint, trackCaret: false);
                session.Dismissed += Session_Dismissed;
                session.Properties.AddProperty(sigHelpSessionKey, this);
            }
            session.Recalculate();

            // It's set to null if it got dismissed
            if (session == null || session.IsDismissed)
            {
                Debug.Assert(isDisposed);
                Dispose();
                return;
            }

            var selectedSig = signatures.FirstOrDefault(a => a.IsSelected);

            if (selectedSig != null)
            {
                session.SelectedSignature = selectedSig;
            }
        }
Пример #6
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));
        }