Пример #1
0
        public override CommandResult Invoke(Guid group, int id, object inputArg, ref object outputArg)
        {
            if (group == VSConstants.VSStd2K)
            {
                var controller = CompletionController.FromTextView <RCompletionController>(TextView);
                if (controller != null)
                {
                    if (id == (int)VSConstants.VSStd2KCmdID.RETURN)
                    {
                        return(HandleEnter(controller));
                    }

                    if (id == (int)VSConstants.VSStd2KCmdID.SCROLLUP)
                    {
                        return(HandleCtrlUp(controller));
                    }

                    if (id == (int)VSConstants.VSStd2KCmdID.CANCEL)
                    {
                        if (HandleCancel(controller))
                        {
                            return(CommandResult.Executed);
                        }
                    }
                }
            }
            else if (group == VSConstants.GUID_VSStandardCommandSet97)
            {
                if (id == (int)VSConstants.VSStd97CmdID.F1Help)
                {
                    var controller = CompletionController.FromTextView <RCompletionController>(TextView);
                    if (controller != null)
                    {
                        // Translate to R help
                        HandleF1Help(controller);
                        return(CommandResult.Executed);
                    }
                }
            }

            var status = _snippetController.Status(group, id);

            if (status != CommandStatus.NotSupported)
            {
                var result = _snippetController.Invoke(group, id, inputArg, ref outputArg);
                if (result.Status != CommandStatus.NotSupported)
                {
                    return(result);
                }
            }

            return(base.Invoke(group, id, inputArg, ref outputArg));
        }
Пример #2
0
        public void ExpansionControllerTest()
        {
            var textBuffer = new TextBufferMock("if", RContentTypeDefinition.ContentType);
            var textView   = new TextViewMock(textBuffer);
            var o          = new object();

            var controller = new ExpansionsController(textView, textBuffer, _expansionManager, _cache, _services);

            controller.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.INSERTSNIPPET).Should().Be(CommandStatus.SupportedAndEnabled);
            controller.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.SURROUNDWITH).Should().Be(CommandStatus.SupportedAndEnabled);

            controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.RETURN, null, ref o).Should().Be(CommandResult.NotSupported);
            controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.BACKTAB, null, ref o).Should().Be(CommandResult.NotSupported);
            controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.CANCEL, null, ref o).Should().Be(CommandResult.NotSupported);

            textView.Caret.MoveTo(new SnapshotPoint(textView.TextBuffer.CurrentSnapshot, 2));
            bool inserted;

            var client = controller.ExpansionClient as ExpansionClient;

            client.StartSnippetInsertion(out inserted);

            controller.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.INSERTSNIPPET).Should().Be(CommandStatus.SupportedAndEnabled);
            controller.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.SURROUNDWITH).Should().Be(CommandStatus.SupportedAndEnabled);

            client.Session.Should().NotBeNull();
            var session = client.Session;
            var mock    = session as VsExpansionSessionMock;

            controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.TAB, null, ref o).Should().Be(CommandResult.Executed);
            mock.ExpansionFieldIndex.Should().Be(1);

            controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.BACKTAB, null, ref o).Should().Be(CommandResult.Executed);
            mock.ExpansionFieldIndex.Should().Be(0);

            client.EndExpansion();
        }