Пример #1
0
        protected override bool Run(VSConstants.VSStd2KCmdID nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            var typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
            var point     = TextView.Caret.Position.BufferPosition;

            if (typedChar == '<')
            {
                if (point.Position != 0 && TextView.TextBuffer.CurrentSnapshot.GetText(point.Position - 1, 1) == "<")
                {
                    TextView.TextBuffer.Replace(new Span(point.Position - 1, 1), "«");
                }
                else
                {
                    return(ExecuteNext(nCmdID, nCmdexecopt, pvaIn, pvaOut));
                }
            }
            else if (typedChar == '>')
            {
                if (point.Position != 0 && TextView.TextBuffer.CurrentSnapshot.GetText(point.Position - 1, 1) == ">")
                {
                    TextView.TextBuffer.Replace(new Span(point.Position - 1, 1), "»");
                }
                else
                {
                    return(ExecuteNext(nCmdID, nCmdexecopt, pvaIn, pvaOut));
                }
            }
            else
            {
                return(ExecuteNext(nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }

            return(true);
        }
Пример #2
0
        private void AssertCanConvert2K(VSConstants.VSStd2KCmdID id, KeyInput expected)
        {
            KeyInput ki;

            Assert.True(_targetRaw.TryConvert(VSConstants.VSStd2K, (uint)id, IntPtr.Zero, out ki));
            Assert.Equal(expected, ki);
        }
Пример #3
0
        public void ShowLightBulb()
        {
            InvokeSmartTasks();

            // The editor has an asynchronous background operation that dismisses the light bulb if it was shown within
            // 500ms of the operation starting. Wait 600ms and make sure the menu is still present.
            // https://devdiv.visualstudio.com/DevDiv/_git/VS-Platform/pullrequest/268277
            Thread.Sleep(600);

            if (!IsLightBulbSessionExpanded())
            {
                InvokeSmartTasks();
            }

            void InvokeSmartTasks()
            {
                InvokeOnUIThread(cancellationToken =>
                {
                    var shell      = GetGlobalService <SVsUIShell, IVsUIShell>();
                    var cmdGroup   = typeof(VSConstants.VSStd2KCmdID).GUID;
                    var cmdExecOpt = OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER;

                    const VSConstants.VSStd2KCmdID ECMD_SMARTTASKS = (VSConstants.VSStd2KCmdID) 147;
                    var cmdID  = ECMD_SMARTTASKS;
                    object obj = null;
                    shell.PostExecCommand(cmdGroup, (uint)cmdID, (uint)cmdExecOpt, ref obj);
                });
            }
        }
Пример #4
0
        public override CommandResult Invoke(Guid group, int id, object inputArg, ref object outputArg)
        {
            // CompletionController will be null in weird scenarios, such as "Open With <non-html editor>" or diff view
            if (CompletionController != null && group == VSConstants.VSStd2K)
            {
                VSConstants.VSStd2KCmdID vsCmdID = (VSConstants.VSStd2KCmdID)id;

                switch (vsCmdID)
                {
                case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST:
                    bool filterList = (inputArg is bool) && (bool)inputArg;
                    CompletionController.OnShowMemberList(filterList);
                    return(CommandResult.Executed);

                case VSConstants.VSStd2KCmdID.COMPLETEWORD:
                    CompletionController.OnCompleteWord();
                    return(CommandResult.Executed);

                case VSConstants.VSStd2KCmdID.PARAMINFO:
                    CompletionController.OnShowSignatureHelp();
                    return(CommandResult.Executed);

                case VSConstants.VSStd2KCmdID.QUICKINFO:
                    CompletionController.OnShowQuickInfo();
                    return(CommandResult.Executed);
                }
            }

            return(CommandResult.NotSupported);
        }
Пример #5
0
        internal static bool IsDebugIgnore(VSConstants.VSStd2KCmdID commandId)
        {
            switch (commandId)
            {
            // A lot of my debugging is essentially figuring out which command is messing up normal mode.
            // Unfortunately VS likes to throw a lot of commands all of the time.  I list them here so they don't
            // come through my default mode where I can then set a break point
            case VSConstants.VSStd2KCmdID.SolutionPlatform:
            case VSConstants.VSStd2KCmdID.FILESYSTEMEDITOR:
            case VSConstants.VSStd2KCmdID.REGISTRYEDITOR:
            case VSConstants.VSStd2KCmdID.FILETYPESEDITOR:
            case VSConstants.VSStd2KCmdID.USERINTERFACEEDITOR:
            case VSConstants.VSStd2KCmdID.CUSTOMACTIONSEDITOR:
            case VSConstants.VSStd2KCmdID.LAUNCHCONDITIONSEDITOR:
            case VSConstants.VSStd2KCmdID.EDITOR:
            case VSConstants.VSStd2KCmdID.VIEWDEPENDENCIES:
            case VSConstants.VSStd2KCmdID.VIEWFILTER:
            case VSConstants.VSStd2KCmdID.VIEWOUTPUTS:
            case VSConstants.VSStd2KCmdID.RENAME:
            case VSConstants.VSStd2KCmdID.ADDOUTPUT:
            case VSConstants.VSStd2KCmdID.ADDFILE:
            case VSConstants.VSStd2KCmdID.MERGEMODULE:
            case VSConstants.VSStd2KCmdID.ADDCOMPONENTS:
            case VSConstants.VSStd2KCmdID.ADDWFCFORM:
                return(true);
            }

            return(false);
        }
        public void ShowLightBulb()
        {
            // ⚠ The workarounds below (delays, retries) can be removed once integration test machines are updated to
            // 16.9 Preview 2. https://devdiv.visualstudio.com/DevDiv/_git/VS-Platform/pullrequest/283203

            // Start by sleeping 600ms to try and avoid the dismissal below
            Thread.Sleep(600);

            InvokeSmartTasks();

            // The editor has an asynchronous background operation that dismisses the light bulb if it was shown within
            // 500ms of the operation starting. Wait 1000ms and make sure the menu is still present.
            // https://devdiv.visualstudio.com/DevDiv/_git/VS-Platform/pullrequest/268277
            Thread.Sleep(1000);

            if (!IsLightBulbSessionExpanded())
            {
                InvokeSmartTasks();
            }

            void InvokeSmartTasks()
            {
                InvokeOnUIThread(cancellationToken =>
                {
                    var shell      = GetGlobalService <SVsUIShell, IVsUIShell>();
                    var cmdGroup   = typeof(VSConstants.VSStd2KCmdID).GUID;
                    var cmdExecOpt = OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER;

                    const VSConstants.VSStd2KCmdID ECMD_SMARTTASKS = (VSConstants.VSStd2KCmdID) 147;
                    var cmdID  = ECMD_SMARTTASKS;
                    object obj = null;
                    shell.PostExecCommand(cmdGroup, (uint)cmdID, (uint)cmdExecOpt, ref obj);
                });
            }
        }
Пример #7
0
 public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
 {
     if (pguidCmdGroup == typeof(VSConstants.VSStd2KCmdID).GUID)
     {
         VSConstants.VSStd2KCmdID command = (VSConstants.VSStd2KCmdID)nCmdID;
         if (command == VSConstants.VSStd2KCmdID.RETURN)
         {
             if (this.nextCommandTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut) == VSConstants.S_OK)
             {
                 FormatLine();
                 SetCaret();
                 return(VSConstants.S_OK);
             }
         }
         else if (command == VSConstants.VSStd2KCmdID.COMMENT_BLOCK)
         {
             CommentSelection();
             return(VSConstants.S_OK);
         }
         else if (command == VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK)
         {
             UncommentSelection();
             return(VSConstants.S_OK);
         }
         else if (command == VSConstants.VSStd2KCmdID.FORMATDOCUMENT)
         {
             FormatCode();
             return(VSConstants.S_OK);
         }
     }
     return(this.nextCommandTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
 }
Пример #8
0
        protected override bool Run(VSConstants.VSStd2KCmdID nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            var point = TextView.Caret.Position.BufferPosition;

            if (point.Position == 0)
            {
                return(true);
            }

            var deletedChar = point.Snapshot.GetText(point.Position - 1, 1)[0];

            string replace;

            switch (deletedChar)
            {
            case '«': replace = "<<"; break;

            case '»': replace = ">>"; break;

            default:
                return(ExecuteNext(nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }

            TextView.TextBuffer.Replace(new Span(point.Position - 1, 1), replace);
            return(true);
        }
Пример #9
0
        public override void PostProcessInvoke(CommandResult result, Guid group, int id, object inputArg, ref object outputArg)
        {
            if (result.WasExecuted)
            {
                char typedChar = '\0';

                if (group == VSConstants.VSStd2K)
                {
                    // REVIEW: Is the TAB key a trigger for any languages? Maybe this code can be deleted.

                    VSConstants.VSStd2KCmdID vsCmdID = (VSConstants.VSStd2KCmdID)id;
                    typedChar = GetTypedChar(group, id, inputArg);

                    if (vsCmdID == VSConstants.VSStd2KCmdID.TAB)
                    {
                        // Check if there is selection. If so, TAB will translate to 'indent lines' command
                        // and hence we don't want to trigger intellisense on it.
                        if (TextView.Selection.SelectedSpans.Count > 0)
                        {
                            if (TextView.Selection.SelectedSpans[0].Length > 0)
                            {
                                typedChar = '\0';
                            }
                        }
                    }
                }

                if (typedChar != '\0')
                {
                    OnPostTypeChar(typedChar);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// 指定のコマンドを実行します。
        /// コマンドが実行できなかった場合は<see langword="false"/>を返します。
        /// </summary>
        private bool ExecuteCommand(VSConstants.VSStd2KCmdID commandId)
        {
            var groupId = VSConstants.VSStd2K;
            var result  = _commandTarget.Exec(ref groupId, (uint)commandId, 0, IntPtr.Zero, IntPtr.Zero);

            return(result == VSConstants.S_OK);
        }
Пример #11
0
        /// <summary>
        /// Verify we can convert the given VimKey to the specified command id
        /// </summary>
        private void VerifyConvert(VimKey vimKey, VSConstants.VSStd2KCmdID cmd)
        {
            var keyInput = KeyInputUtil.VimKeyToKeyInput(vimKey);

            Assert.True(OleCommandUtil.TryConvert(keyInput, false, out OleCommandData oleCommandData));
            Assert.Equal(VSConstants.VSStd2K, oleCommandData.Group);
            Assert.Equal(new OleCommandData(cmd), oleCommandData);
        }
Пример #12
0
        private void VerifyConvert(VSConstants.VSStd2KCmdID cmd, KeyModifiers modifiers, KeyInput ki, EditCommandKind kind)
        {
            EditCommand command;

            Assert.True(OleCommandUtil.TryConvert(VSConstants.VSStd2K, (uint)cmd, IntPtr.Zero, modifiers, out command));
            Assert.Equal(ki, command.KeyInput);
            Assert.Equal(kind, command.EditCommandKind);
        }
Пример #13
0
        private void VerifyConvert(VSConstants.VSStd2KCmdID cmd, KeyInput ki, EditCommandKind kind)
        {
            EditCommand command;

            Assert.IsTrue(OleCommandUtil.TryConvert(VSConstants.VSStd2K, (uint)cmd, out command));
            Assert.AreEqual(ki, command.KeyInput);
            Assert.AreEqual(kind, command.EditCommandKind);
        }
Пример #14
0
        private void AddCommand(VSConstants.VSStd2KCmdID command, Action action)
        {
            var id  = new CommandID(typeof(VSConstants.VSStd2KCmdID).GUID, (int)command);
            var cmd = new OleMenuCommand(OnReturn, id);

            _commandService.AddCommand(cmd);
            _commands2k[command] = action;
        }
Пример #15
0
 private IEditorScript Execute(VSConstants.VSStd2KCmdID cmdId, int count, int msIdle)
 {
     for (var i = 0; i < count; i++)
     {
         Execute(cmdId, msIdle);
     }
     return(this);
 }
Пример #16
0
        /// <summary>
        /// Verify we can convert the given VimKey to the specified command id
        /// </summary>
        private void VerifyConvert(VimKey vimKey, VSConstants.VSStd2KCmdID cmd)
        {
            var            keyInput = KeyInputUtil.VimKeyToKeyInput(vimKey);
            Guid           commandGroup;
            OleCommandData oleCommandData;

            Assert.IsTrue(OleCommandUtil.TryConvert(keyInput, out commandGroup, out oleCommandData));
            Assert.AreEqual(VSConstants.VSStd2K, commandGroup);
            Assert.AreEqual(new OleCommandData(cmd), oleCommandData);
        }
Пример #17
0
        private VsKeyInfo GetVsKeyInfo(IntPtr pvaIn, VSConstants.VSStd2KCmdID commandID)
        {
            // catch current modifiers as early as possible
            bool capsLockToggled = Keyboard.IsKeyToggled(Key.CapsLock);
            bool numLockToggled  = Keyboard.IsKeyToggled(Key.NumLock);

            char keyChar;

            if ((commandID == VSConstants.VSStd2KCmdID.RETURN) &&
                pvaIn == IntPtr.Zero)
            {
                // <enter> pressed
                keyChar = Environment.NewLine[0]; // [CR]LF
            }
            else if ((commandID == VSConstants.VSStd2KCmdID.BACKSPACE) &&
                     pvaIn == IntPtr.Zero)
            {
                keyChar = '\b'; // backspace control character
            }
            else
            {
                Debug.Assert(pvaIn != IntPtr.Zero, "pvaIn != IntPtr.Zero");

                // 1) deref pointer to char
                keyChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
            }

            // 2) convert from char to virtual key, using current thread's input locale
            short keyScan = NativeMethods.VkKeyScanEx(keyChar, _pKeybLayout.Value);

            // 3) virtual key is in LSB, shiftstate in MSB.
            byte virtualKey = (byte)(keyScan & 0x00ff);

            keyScan = (short)(keyScan >> 8);
            byte shiftState = (byte)(keyScan & 0x00ff);

            // 4) convert from virtual key to wpf key.
            Key key = KeyInterop.KeyFromVirtualKey(virtualKey);

            // 5) create nugetconsole.vskeyinfo to marshal info to
            var keyInfo = VsKeyInfo.Create(
                key,
                keyChar,
                virtualKey,
                keyStates: KeyStates.Down,
                capsLockToggled: capsLockToggled,
                numLockToggled: numLockToggled,
                shiftPressed: ((shiftState & 1) == 1),
                controlPressed: ((shiftState & 2) == 4),
                altPressed: ((shiftState & 4) == 2));

            return(keyInfo);
        }
Пример #18
0
        private bool HandleOpeningBrace(VSConstants.VSStd2KCmdID nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut, char typedChar)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            _ = ExecuteNext(nCmdID, nCmdexecopt, pvaIn, pvaOut);

            var caretPoint = TextView.Caret.Position.BufferPosition;

            TextView.TextBuffer.Insert(TextView.Caret.Position.BufferPosition.Position, Core.ParseTree.Utils.Braces[typedChar].ToString());
            TextView.Caret.MoveTo(caretPoint.TranslateTo(TextView.TextSnapshot, PointTrackingMode.Negative));

            return(true);
        }
Пример #19
0
        public void ShowLightBulb()
        {
            InvokeOnUIThread(cancellationToken =>
            {
                var shell      = GetGlobalService <SVsUIShell, IVsUIShell>();
                var cmdGroup   = typeof(VSConstants.VSStd2KCmdID).GUID;
                var cmdExecOpt = OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER;

                const VSConstants.VSStd2KCmdID ECMD_SMARTTASKS = (VSConstants.VSStd2KCmdID) 147;
                var cmdID  = ECMD_SMARTTASKS;
                object obj = null;
                shell.PostExecCommand(cmdGroup, (uint)cmdID, (uint)cmdExecOpt, ref obj);
            });
        }
Пример #20
0
        protected override bool Run(VSConstants.VSStd2KCmdID nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            var typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);

            if (typedChar.IsOpeningBrace())
            {
                return(HandleOpeningBrace(nCmdID, nCmdexecopt, pvaIn, pvaOut, typedChar));
            }

            if (typedChar.IsClosingBrace() && IsEqualToNextCharacter(typedChar))
            {
                return(HandleClosingBrace());
            }

            return(ExecuteNext(nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Пример #21
0
        }         // func DeindentLine

        public override void OnCommand(IVsTextView textView, VSConstants.VSStd2KCmdID command, char ch)
        {
            if (command == VSConstants.VSStd2KCmdID.TYPECHAR && (ch == 'd' || ch == 'k' || ch == 'l' || ch == 'f' || ch == 'e'))
            {
                bool lHighlightBraces = LanguageService.Preferences.EnableMatchBraces && LanguageService.Preferences.EnableMatchBracesAtCaret;
                int  iLine;
                int  iColumn;
                if (!ErrorHandler.Succeeded(textView.GetCaretPos(out iLine, out iColumn)))
                {
                    return;
                }

                if (ch == 'd' && iColumn >= 3 && GetText(iLine, iColumn - 3, iLine, iColumn) == "end")
                {
                    // Deindent on single end
                    iColumn = DeindentLine(iLine, iColumn, 3);

                    // highlight
                    if (lHighlightBraces)
                    {
                        TokenInfo info = GetTokenInfo(iLine, iColumn);
                        this.MatchBraces(textView, iLine, iColumn, info);
                    }
                }
                else if (ch == 'f' && iColumn >= 6 && GetText(iLine, iColumn - 6, iLine, iColumn) == "elseif")
                {
                    iColumn = DeindentLine(iLine, iColumn, 6);
                }
                else if (ch == 'e' && iColumn >= 4 && GetText(iLine, iColumn - 4, iLine, iColumn) == "else")
                {
                    iColumn = DeindentLine(iLine, iColumn, 4);
                }
                else if (lHighlightBraces && (
                             ch == 'k' && iColumn >= 5 && GetText(iLine, iColumn - 3, iLine, iColumn) == "break" ||
                             ch == 'l' && iColumn >= 5 && GetText(iLine, iColumn - 3, iLine, iColumn) == "until"
                             ))
                {
                    TokenInfo info = GetTokenInfo(iLine, iColumn);
                    this.MatchBraces(textView, iLine, iColumn, info);
                }
            }
            else
            {
                base.OnCommand(textView, command, ch);
            }
        }         // proc OnCommand
Пример #22
0
        public override CommandStatus Status(Guid group, int id)
        {
            // CompletionController will be null in weird scenarios, such as "Open With <non-html editor>" or diff view
            if (CompletionController != null && group == VSConstants.VSStd2K)
            {
                VSConstants.VSStd2KCmdID vsCmdID = (VSConstants.VSStd2KCmdID)id;

                switch (vsCmdID)
                {
                case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST:
                case VSConstants.VSStd2KCmdID.COMPLETEWORD:
                case VSConstants.VSStd2KCmdID.PARAMINFO:
                case VSConstants.VSStd2KCmdID.QUICKINFO:
                    return(CommandStatus.SupportedAndEnabled);
                }
            }
            return(CommandStatus.NotSupported);
        }
Пример #23
0
        public override CommandResult Invoke(Guid group, int id, object inputArg, ref object outputArg)
        {
            if (group == VSConstants.GUID_VSStandardCommandSet97)
            {
                VSConstants.VSStd97CmdID vsCmdID = (VSConstants.VSStd97CmdID)id;

                switch (vsCmdID)
                {
                // If this list of commands gets large, then maybe there's a better way to know when to dismiss
                case VSConstants.VSStd97CmdID.Paste:
                    DismissAllSessions();
                    break;
                }
            }
            else if (group == VSConstants.VSStd2K)
            {
                VSConstants.VSStd2KCmdID vsCmdID = (VSConstants.VSStd2KCmdID)id;

                switch (vsCmdID)
                {
                case VSConstants.VSStd2KCmdID.PASTE:
                    DismissAllSessions();
                    break;

                case VSConstants.VSStd2KCmdID.TAB:
                    // Check if there is selection. If so, TAB will translate to 'indent lines' command
                    // and hence we don't want to trigger intellisense on it.
                    var typedChar = GetTypedChar(group, id, inputArg);
                    if (TextView.Selection.SelectedSpans.Count > 0)
                    {
                        if (TextView.Selection.SelectedSpans[0].Length > 0)
                        {
                            typedChar = '\0';
                        }
                    }
                    break;
                }
            }

            return(HandleCompletion(group, id, inputArg));
        }
Пример #24
0
        public override void OnCommand(IVsTextView textView, VSConstants.VSStd2KCmdID command, char ch)
        {
            base.OnCommand(textView, command, ch);
            //if (command == VSConstants.VSStd2KCmdID.ECMD_RENAMESYMBOL)
            //{
            //    System.Diagnostics.Debug.WriteLine(command);
            //}

/*
 *          if (command == VSConstants.VSStd2KCmdID.TYPECHAR)
 *          {
 *              int line, col;
 *              textView.GetCaretPos(out line, out col);
 *
 *              TokenInfo tokenInfo = this.GetTokenInfo(line, col);
 *
 *              if (tokenInfo.Type == TokenType.Identifier && !this.IsCompletorActive)
 *                  this.Completion(textView, tokenInfo, ParseReason.CompleteWord);
 *          }
 */
        }
Пример #25
0
 private void AssertCannotConvert2K(VSConstants.VSStd2KCmdID id)
 {
     Assert.False(_targetRaw.TryConvert(VSConstants.VSStd2K, (uint)id, IntPtr.Zero, out KeyInput ki));
 }
Пример #26
0
        /// <summary>
        /// Try and convert a Visual Studio 2000 style command into the associated KeyInput and EditCommand items
        /// </summary>
        internal static bool TryConvert(VSConstants.VSStd2KCmdID cmdId, IntPtr variantIn, out KeyInput keyInput, out EditCommandKind kind, out bool isRawText)
        {
            isRawText = false;
            switch (cmdId)
            {
            case VSConstants.VSStd2KCmdID.TYPECHAR:
                if (variantIn == IntPtr.Zero)
                {
                    keyInput = KeyInputUtil.CharToKeyInput(Char.MinValue);
                }
                else
                {
                    var obj = Marshal.GetObjectForNativeVariant(variantIn);
                    var c   = (char)(ushort)obj;
                    keyInput = KeyInputUtil.CharToKeyInput(c);
                }
                kind      = EditCommandKind.UserInput;
                isRawText = true;
                break;

            case VSConstants.VSStd2KCmdID.RETURN:
                keyInput = KeyInputUtil.EnterKey;
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.CANCEL:
                keyInput = KeyInputUtil.EscapeKey;
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.DELETE:
                keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.Delete);
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.BACKSPACE:
                keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.Back);
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.LEFT:
                keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.Left);
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.LEFT_EXT:
            case VSConstants.VSStd2KCmdID.LEFT_EXT_COL:
                keyInput = KeyInputUtil.ApplyModifiersToVimKey(VimKey.Left, KeyModifiers.Shift);
                kind     = EditCommandKind.VisualStudioCommand;
                break;

            case VSConstants.VSStd2KCmdID.RIGHT:
                keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.Right);
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.RIGHT_EXT:
            case VSConstants.VSStd2KCmdID.RIGHT_EXT_COL:
                keyInput = KeyInputUtil.ApplyModifiersToVimKey(VimKey.Right, KeyModifiers.Shift);
                kind     = EditCommandKind.VisualStudioCommand;
                break;

            case VSConstants.VSStd2KCmdID.UP:
                keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.Up);
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.UP_EXT:
            case VSConstants.VSStd2KCmdID.UP_EXT_COL:
                keyInput = KeyInputUtil.ApplyModifiersToVimKey(VimKey.Up, KeyModifiers.Shift);
                kind     = EditCommandKind.VisualStudioCommand;
                break;

            case VSConstants.VSStd2KCmdID.DOWN:
                keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.Down);
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.DOWN_EXT:
            case VSConstants.VSStd2KCmdID.DOWN_EXT_COL:
                keyInput = KeyInputUtil.ApplyModifiersToVimKey(VimKey.Down, KeyModifiers.Shift);
                kind     = EditCommandKind.VisualStudioCommand;
                break;

            case VSConstants.VSStd2KCmdID.TAB:
                keyInput = KeyInputUtil.TabKey;
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.BACKTAB:
                keyInput = KeyInputUtil.ApplyModifiersToVimKey(VimKey.Tab, KeyModifiers.Shift);
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.PAGEDN:
                keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.PageDown);
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.PAGEDN_EXT:
                keyInput = KeyInputUtil.ApplyModifiersToVimKey(VimKey.PageDown, KeyModifiers.Shift);
                kind     = EditCommandKind.VisualStudioCommand;
                break;

            case VSConstants.VSStd2KCmdID.PAGEUP:
                keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.PageUp);
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.PAGEUP_EXT:
                keyInput = KeyInputUtil.ApplyModifiersToVimKey(VimKey.PageUp, KeyModifiers.Shift);
                kind     = EditCommandKind.VisualStudioCommand;
                break;

            case VSConstants.VSStd2KCmdID.UNDO:
            case VSConstants.VSStd2KCmdID.UNDONOMOVE:
                // Visual Studio was asked to undo.  This happens when either the undo button
                // was hit or the visual studio key combination bound to the undo command
                // was executed
                keyInput = KeyInput.DefaultValue;
                kind     = EditCommandKind.Undo;
                break;

            case VSConstants.VSStd2KCmdID.REDO:
            case VSConstants.VSStd2KCmdID.REDONOMOVE:
                // Visual Studio was asked to redo.  This happens when either the redo button
                // was hit or the visual studio key combination bound to the redo command
                // was executed
                keyInput = KeyInput.DefaultValue;
                kind     = EditCommandKind.Redo;
                break;

            case VSConstants.VSStd2KCmdID.BOL:
                // Even though there as a HOME value defined, Visual Studio apparently maps the
                // Home key to BOL
                keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.Home);
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.BOL_EXT:
            case VSConstants.VSStd2KCmdID.BOL_EXT_COL:
                keyInput = KeyInputUtil.ApplyModifiersToVimKey(VimKey.Home, KeyModifiers.Shift);
                kind     = EditCommandKind.VisualStudioCommand;
                break;

            case VSConstants.VSStd2KCmdID.EOL:
                // Even though there as a END value defined, Visual Studio apparently maps the
                // Home key to EOL
                keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.End);
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.EOL_EXT:
            case VSConstants.VSStd2KCmdID.EOL_EXT_COL:
                keyInput = KeyInputUtil.ApplyModifiersToVimKey(VimKey.End, KeyModifiers.Shift);
                kind     = EditCommandKind.VisualStudioCommand;
                break;

            case VSConstants.VSStd2KCmdID.TOGGLE_OVERTYPE_MODE:
                // The <Insert> key is expressed in the toggle overtype mode flag.  In general
                // over write mode is referred to as overtype in the code / documentation
                keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.Insert);
                kind     = EditCommandKind.UserInput;
                break;

            case VSConstants.VSStd2KCmdID.PASTE:
                keyInput = KeyInput.DefaultValue;
                kind     = EditCommandKind.Paste;
                break;

            case VSConstants.VSStd2KCmdID.COMMENT_BLOCK:
            case VSConstants.VSStd2KCmdID.COMMENTBLOCK:
                keyInput = KeyInput.DefaultValue;
                kind     = EditCommandKind.Comment;
                break;

            case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK:
            case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK:
                keyInput = KeyInput.DefaultValue;
                kind     = EditCommandKind.Uncomment;
                break;

            default:
                keyInput = null;
                kind     = EditCommandKind.UserInput;
                break;
            }

            return(keyInput != null);
        }
Пример #27
0
        public static char GetTypedChar(Guid group, int commandId, object variantIn)
        {
            char typedChar = '\0';

            if (group == VSConstants.GUID_VSStandardCommandSet97)
            {
                VSConstants.VSStd97CmdID vsCmdID = (VSConstants.VSStd97CmdID)commandId;

                switch (vsCmdID)
                {
                case VSConstants.VSStd97CmdID.Delete:
                    typedChar = '\b';
                    break;

                case VSConstants.VSStd97CmdID.Escape:
                case VSConstants.VSStd97CmdID.Cancel:
                    typedChar = (char)0x1B;     // ESC
                    break;
                }
            }
            else if (group == VSConstants.VSStd2K)
            {
                VSConstants.VSStd2KCmdID vsCmdID = (VSConstants.VSStd2KCmdID)commandId;

                switch (vsCmdID)
                {
                case VSConstants.VSStd2KCmdID.DELETE:
                    typedChar = '\b';
                    break;

                case VSConstants.VSStd2KCmdID.BACKSPACE:
                    typedChar = '\b';
                    break;

                case VSConstants.VSStd2KCmdID.RETURN:
                    typedChar = '\n';
                    break;

                case VSConstants.VSStd2KCmdID.TAB:
                    typedChar = '\t';
                    break;

                case VSConstants.VSStd2KCmdID.Cancel:
                case VSConstants.VSStd2KCmdID.CANCEL:
                    typedChar = (char)0x1B;     // ESC
                    break;

                case VSConstants.VSStd2KCmdID.TYPECHAR:
                    if (variantIn is char)
                    {
                        typedChar = (char)variantIn;
                    }
                    else
                    {
                        typedChar = (char)(ushort)variantIn;
                    }
                    break;
                }
            }

            return(typedChar);
        }
Пример #28
0
        private int HandleTyping(CommandID command, uint options, IntPtr pvIn, IntPtr pvOut)
        {
            // If we're in an automation function, *don't* trigger anything as a result of typing!
            if (VsShellUtilities.IsInAutomationFunction(this.provider.ServiceProvider))
            {
                return(this.PassThrough(command, options, pvIn, pvOut));
            }

            System.Diagnostics.Debug.Assert(command.Guid == VSConstants.VSStd2K);
            System.Diagnostics.Debug.Assert(command.ID == (int)VSConstants.VSStd2KCmdID.TYPECHAR ||
                                            command.ID == (int)VSConstants.VSStd2KCmdID.RETURN ||
                                            command.ID == (int)VSConstants.VSStd2KCmdID.TAB ||
                                            command.ID == (int)VSConstants.VSStd2KCmdID.BACKSPACE ||
                                            command.ID == (int)VSConstants.VSStd2KCmdID.DELETE);

            VSConstants.VSStd2KCmdID commandId = (VSConstants.VSStd2KCmdID)command.ID;
            char typedChar = char.MinValue;

            // Make sure the input is a typed character before getting it.
            if (commandId == VSConstants.VSStd2KCmdID.TYPECHAR)
            {
                typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvIn);
            }

            // Check for a commit character, and possibly commit a selection.
            if (commandId == VSConstants.VSStd2KCmdID.RETURN ||
                commandId == VSConstants.VSStd2KCmdID.TAB ||
                (commandId == VSConstants.VSStd2KCmdID.TYPECHAR && !CompletionSource.IsTokenTermCharacter(typedChar)))
            {
                if (this.session != null && !this.session.IsDismissed)
                {
                    // if the selection is fully selected, commit the current session
                    if (this.session.SelectedCompletionSet.SelectionStatus.IsSelected)
                    {
                        ITrackingSpan applicableSpan = this.session.SelectedCompletionSet.ApplicableTo;
                        this.session.Commit();

                        // If we ended with whitespace or '=', trigger another session!
                        char ch = (applicableSpan.GetEndPoint(applicableSpan.TextBuffer.CurrentSnapshot) - 1).GetChar();
                        if (char.IsWhiteSpace(ch) || ch == '=')
                        {
                            this.TriggerCompletion();
                        }

                        return(VSConstants.S_OK);    // don't add the commit character to the buffer
                    }
                    else
                    {
                        // if there is no selection, dismiss the session
                        this.session.Dismiss();
                    }
                }
            }

            // pass the command on through to the buffer to allow typing...
            int ret = this.PassThrough(command, options, pvIn, pvOut);

            if (commandId == VSConstants.VSStd2KCmdID.TYPECHAR && !typedChar.Equals(char.MinValue))
            {
                // If there is no active session, bring up completion
                if (this.session == null || this.session.IsDismissed)
                {
                    this.TriggerCompletion();
                }

                if (this.session != null && !this.session.IsDismissed)
                {
                    // the completion session is already active, so just filter
                    this.session.Filter();
                }
            }
            // else if BACKSPACE or DELETE, redo the filter...
            else if (commandId == VSConstants.VSStd2KCmdID.BACKSPACE ||
                     commandId == VSConstants.VSStd2KCmdID.DELETE)
            {
                if (this.session != null && !this.session.IsDismissed)
                {
                    this.session.Filter();
                }
            }

            return(ret);
        }
Пример #29
0
 //public override void BeginParse()
 //{
 //    base.BeginParse();
 //}
 //public override ParseRequest BeginParse(int line, int idx, TokenInfo info, ParseReason reason, IVsTextView view, ParseResultHandler callback)
 //{
 //    return base.BeginParse(line, idx, info, reason, view, callback);
 //}
 public override void OnCommand(IVsTextView textView, VSConstants.VSStd2KCmdID command, char ch)
 {
     base.OnCommand(textView, command, ch);
     // Vulcan formats the keywords here.
 }
Пример #30
0
 protected NavigationCommandBase(ITextView textView, IRHistoryProvider historyProvider, VSConstants.VSStd2KCmdID id)
     : base(textView, VSConstants.VSStd2K, (int)id, false)
 {
     History = historyProvider.GetAssociatedRHistory(textView);
 }