Ejemplo n.º 1
0
        private void SmartCompleteTypeFunctionRefWithParams(int positionAfter, ITextBuffer buffer, string newLineText, string indent)
        {
            var beforeCaret = "() {";
            var afterCaret  = "}";

            buffer.Insert(positionAfter, beforeCaret + afterCaret);

            _textView.Caret.MoveTo(new SnapshotPoint(buffer.CurrentSnapshot, positionAfter + 1));
            _compilerService.AfterNextCompilation(_ => _signatureHelpBroker.TriggerSignatureHelp(_textView), SynchronizationContext.Current);
        }
        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));
        }
Ejemplo n.º 3
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));
        }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            try {
                SnapshotPoint currentPoint = _textView.Caret.Position.BufferPosition;
                if ((currentPoint != null) && (currentPoint > 0))
                {
                    SnapshotPoint point = currentPoint - 1;
                    if (point.Position > 1)
                    {
                        ITextSnapshotLine line    = point.Snapshot.GetLineFromPosition(point.Position);
                        string            lineStr = line.GetText();

                        int pos = point.Position - line.Start;
                        if (!AsmSourceTools.isInRemark(pos, lineStr))   //check if current position is in a remark; if we are in a remark, no signature help

                        {
                            if ((pguidCmdGroup == VSConstants.VSStd2K) && (nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR))
                            {
                                char typedChar = this.GetTypeChar(pvaIn);
                                if (char.IsWhiteSpace(typedChar) || typedChar.Equals(','))
                                {
                                    var t = AsmSourceTools.parseLine(lineStr);
                                    if (this._session != null)
                                    {
                                        this._session.Dismiss();                        // cleanup previous session
                                    }
                                    if (t.Item2 != Mnemonic.UNKNOWN)
                                    {
                                        this._session = _broker.TriggerSignatureHelp(_textView);
                                    }
                                }
                                else if (AsmSourceTools.isRemarkChar(typedChar) && (this._session != null))
                                {
                                    this._session.Dismiss();
                                    this._session = null;
                                }
                            }
                            else
                            {
                                bool enterPressed = (nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN);
                                if (enterPressed && (this._session != null))
                                {
                                    this._session.Dismiss();
                                    this._session = null;
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                AsmDudeToolsStatic.Output(string.Format("ERROR: {0}:Exec; e={1}", this.ToString(), e.ToString()));
            }
            return(_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
 public void StartSignatureHelp(int offset)
 {
     if (!m_sh_broker.IsSignatureHelpActive(m_view))
     {
         ITrackingPoint triggerPoint = m_view.TextSnapshot.CreateTrackingPoint(offset, PointTrackingMode.Positive);
         var            session      = m_sh_broker.TriggerSignatureHelp(m_view, triggerPoint, true);
         if (session != null)
         {
             session.Start();
         }
     }
 }
        private bool StartSignatureSession()
        {
            if (_signatureSession == null)
            {
                // Move the caret back to the preceding word
                SnapshotPoint caret  = _textView.Caret.Position.BufferPosition - 1;
                TextExtent    extent = _textNavigator.GetExtentOfWord(caret);
                string        word   = extent.Span.GetText();

                _signatureSession = _signatureBroker.TriggerSignatureHelp(_textView);

                _signatureSession.Dismissed += (sender, args) => _signatureSession = null;
                _signatureSession.Start();

                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
        private void TriggerSession()
        {
            if (_session == null || _session.IsDismissed)
            {
                if (_quickInfoBroker.IsQuickInfoActive(_view))
                {
                    _quickInfoBroker.GetSessions(_view)[0].Dismiss();
                }

                Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
                {
                    _session = _signaturehelpBroker.TriggerSignatureHelp(_view);
                    if (_session != null)
                    {
                        _session.Match();
                    }
                }), DispatcherPriority.Normal, null);
            }
        }
Ejemplo n.º 8
0
        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));
        }
        private void TriggerSession()
        {
            if (_session == null || _session.IsDismissed)
            {
                if (_quickInfoBroker.IsQuickInfoActive(_view))
                {
                    _quickInfoBroker.GetSessions(_view)[0].Dismiss();
                }

                ThreadHelper.JoinableTaskFactory.StartOnIdle(
                    () =>
                {
                    _session = _signaturehelpBroker.TriggerSignatureHelp(_view);
                    if (_session != null)
                    {
                        _session.Match();
                    }

                    return(Task.CompletedTask);
                },
                    VsTaskRunContext.UIThreadNormalPriority);
            }
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
 public void TriggerSignatureSession(IEditorView view)
 => _signatureBroker.TriggerSignatureHelp(view.As <ITextView>());
        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);
        }