Exemplo n.º 1
0
        /// <summary>
        /// Handle the Comment Selection and Uncomment Selection editor commands.  These commands comment/uncomment
        /// the currently selected lines.
        /// </summary>
        /// <param name="editorContext">The editor context</param>
        /// <param name="action">The requested command is Comment Selection, otherwise Uncomment Selection</param>
        /// <returns>True if the operation succeeds to comment/uncomment the selected lines, false otherwise</returns>
        public bool CommentOrUncommentSelection(GherkinEditorContext editorContext, CommentUncommentAction action)
        {
            var selectionStartLine = editorContext.TextView.Selection.Start.Position.GetContainingLine();
            var selectionEndLine = GetSelectionEndLine(selectionStartLine, editorContext.TextView);

            switch (action)
            {
                case CommentUncommentAction.Comment:
                    CommentSelection(selectionStartLine, selectionEndLine);
                    break;
                case CommentUncommentAction.Uncomment:
                    UncommentSelection(selectionStartLine, selectionEndLine);
                    break;
                case CommentUncommentAction.Toggle:
                    if (IsCommented(selectionStartLine))
                        UncommentSelection(selectionStartLine, selectionEndLine);
                    else
                        CommentSelection(selectionStartLine, selectionEndLine);
                    break;
            }

            // Select the entirety of the lines that were just commented or uncommented, have to update start/end lines due to snapshot changes
            selectionStartLine = editorContext.TextView.Selection.Start.Position.GetContainingLine();
            selectionEndLine = GetSelectionEndLine(selectionStartLine, editorContext.TextView);
            editorContext.TextView.Selection.Select(new SnapshotSpan(selectionStartLine.Start, selectionEndLine.End), false);

            return true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handle the Comment Selection and Uncomment Selection editor commands.  These commands comment/uncomment
        /// the currently selected lines.
        /// </summary>
        /// <param name="editorContext">The editor context</param>
        /// <param name="action">The requested command is Comment Selection, otherwise Uncomment Selection</param>
        /// <returns>True if the operation succeeds to comment/uncomment the selected lines, false otherwise</returns>
        public bool CommentOrUncommentSelection(GherkinEditorContext editorContext, CommentUncommentAction action)
        {
            var selectionStartLine = editorContext.TextView.Selection.Start.Position.GetContainingLine();
            var selectionEndLine   = GetSelectionEndLine(selectionStartLine, editorContext.TextView);

            switch (action)
            {
            case CommentUncommentAction.Comment:
                CommentSelection(selectionStartLine, selectionEndLine);
                break;

            case CommentUncommentAction.Uncomment:
                UncommentSelection(selectionStartLine, selectionEndLine);
                break;

            case CommentUncommentAction.Toggle:
                if (IsCommented(selectionStartLine))
                {
                    UncommentSelection(selectionStartLine, selectionEndLine);
                }
                else
                {
                    CommentSelection(selectionStartLine, selectionEndLine);
                }
                break;
            }

            // Select the entirety of the lines that were just commented or uncommented, have to update start/end lines due to snapshot changes
            selectionStartLine = editorContext.TextView.Selection.Start.Position.GetContainingLine();
            selectionEndLine   = GetSelectionEndLine(selectionStartLine, editorContext.TextView);
            editorContext.TextView.Selection.Select(new SnapshotSpan(selectionStartLine.Start, selectionEndLine.End), false);

            return(true);
        }
Exemplo n.º 3
0
        public bool FormatTable(GherkinEditorContext editorContext)
        {
            if (!editorContext.LanguageService.ProjectScope.IntegrationOptionsProvider.GetOptions().EnableTableAutoFormat)
            {
                return(false);
            }

            var fileScope = editorContext.LanguageService.GetFileScope(waitForLatest: true);

            if (fileScope == null)
            {
                return(false);
            }

            SnapshotPoint caret             = editorContext.TextView.Caret.Position.BufferPosition;
            var           triggerLineNumber = caret.GetContainingLine().LineNumber;
            var           stepBlock         = fileScope.GetStepBlockFromStepPosition(triggerLineNumber);
            var           step = stepBlock.Steps.LastOrDefault(s => s.BlockRelativeLine + stepBlock.KeywordLine < triggerLineNumber);

            if (step == null)
            {
                return(false);
            }

            var stepArgStartPoint = editorContext.TextView.TextSnapshot.GetLineFromLineNumber(stepBlock.KeywordLine + step.BlockRelativeLine + 1).Start;
            var stepArgsEndPoint  = caret.GetContainingLine().End;

            // Determine what line the table starts on
            var startLine        = caret.GetContainingLine().LineNumber;
            var previousLineText = caret.Snapshot.GetLineFromLineNumber(startLine - 1).GetText();

            while (startLine > 0 && (IsTable(previousLineText) || CommentUncommentCommand.IsComment(previousLineText)))
            {
                previousLineText = caret.Snapshot.GetLineFromLineNumber(--startLine - 1).GetText();
            }

            var    start          = caret.Snapshot.GetLineFromLineNumber(startLine).Start;
            var    span           = new SnapshotSpan(start, caret);
            string oldTable       = span.GetText();
            string formattedTable = FormatTableString(oldTable);

            if (formattedTable == null || formattedTable.Equals(oldTable))
            {
                return(false);
            }
            var textEdit = span.Snapshot.TextBuffer.CreateEdit();

            textEdit.Replace(span, formattedTable);
            textEdit.Apply();
            return(true);
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView view = AdaptersFactory.GetWpfTextView(textViewAdapter);
            Debug.WriteLineIf(view != null, "No WPF editor view found");
            if (view == null)
                return;

            var languageService = GherkinLanguageServiceFactory.GetLanguageService(view.TextBuffer);
            var editorContext = new GherkinEditorContext(languageService, view);

            var editorCommandFilter = ContainerProvider.ObjectContainer.Resolve<EditorCommandFilter>();

            var commandFilter = new EditorCommandFilterInstance(editorCommandFilter, editorContext);

            IOleCommandTarget next;
            textViewAdapter.AddCommandFilter(commandFilter, out next);
            commandFilter.Next = next;
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView view = AdaptersFactory.GetWpfTextView(textViewAdapter);

            Debug.WriteLineIf(view != null, "No WPF editor view found");
            if (view == null)
            {
                return;
            }

            var languageService = GherkinLanguageServiceFactory.GetLanguageService(view.TextBuffer);
            var editorContext   = new GherkinEditorContext(languageService, view);

            var editorCommandFilter = ContainerProvider.ObjectContainer.Resolve <EditorCommandFilter>();

            var commandFilter = new EditorCommandFilterInstance(editorCommandFilter, editorContext);

            IOleCommandTarget next;

            textViewAdapter.AddCommandFilter(commandFilter, out next);
            commandFilter.Next = next;
        }
Exemplo n.º 6
0
        public bool FormatTable(GherkinEditorContext editorContext)
        {
            if (!editorContext.LanguageService.ProjectScope.IntegrationOptionsProvider.GetOptions().EnableTableAutoFormat)
                return false;

            var fileScope = editorContext.LanguageService.GetFileScope(waitForLatest: true);
            if (fileScope == null)
                return false;

            SnapshotPoint caret = editorContext.TextView.Caret.Position.BufferPosition;
            var triggerLineNumber = caret.GetContainingLine().LineNumber;
            var stepBlock = fileScope.GetStepBlockFromStepPosition(triggerLineNumber);
            var step = stepBlock.Steps.LastOrDefault(s => s.BlockRelativeLine + stepBlock.KeywordLine < triggerLineNumber);
            if (step == null)
                return false;

            var stepArgStartPoint = editorContext.TextView.TextSnapshot.GetLineFromLineNumber(stepBlock.KeywordLine + step.BlockRelativeLine + 1).Start;
            var stepArgsEndPoint = caret.GetContainingLine().End;

            // Determine what line the table starts on
            var startLine = caret.GetContainingLine().LineNumber;
            var previousLineText = caret.Snapshot.GetLineFromLineNumber(startLine - 1).GetText();
            while (startLine > 0 && (IsTable(previousLineText) || CommentUncommentCommand.IsComment(previousLineText)))
            {
                previousLineText = caret.Snapshot.GetLineFromLineNumber(--startLine - 1).GetText();
            }

            var start = caret.Snapshot.GetLineFromLineNumber(startLine).Start;
            var span = new SnapshotSpan(start, caret);
            string oldTable = span.GetText();
            string formattedTable = FormatTableString(oldTable);
            if (formattedTable == null || formattedTable.Equals(oldTable))
                return false;
            var textEdit = span.Snapshot.TextBuffer.CreateEdit();
            textEdit.Replace(span, formattedTable);
            textEdit.Apply();
            return true;
        }
Exemplo n.º 7
0
        public void PostExec(GherkinEditorContext editorContext, Guid pguidCmdGroup, uint nCmdID, IntPtr pvaIn)
        {
            if (pguidCmdGroup == VSConstants.VSStd2K)
            {
                switch ((VSConstants.VSStd2KCmdID)nCmdID)
                {
                case VSConstants.VSStd2KCmdID.TYPECHAR:
                    var ch = GetTypeChar(pvaIn);
                    if (ch == '|')
                    {
                        formatTableCommand.FormatTable(editorContext);
                    }
                    break;
                }
            }
//uncomment this to add further command handlers
//                if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
//                {
//                    switch ((VSConstants.VSStd97CmdID)nCmdID)
//                    {
//                    }
//                }
        }
Exemplo n.º 8
0
        public bool GoToDefinition(GherkinEditorContext editorContext)
        {
            var step = GetCurrentStep(editorContext);
            if (step == null)
                return false;

            var bindingMatchService = GetBindingMatchService(editorContext.LanguageService);
            if (bindingMatchService == null)
                return false;

            if (!bindingMatchService.Ready)
            {
                MessageBox.Show("Step bindings are still being analyzed. Please wait.", "Go to binding");
                return true;
            }

            List<BindingMatch> candidatingMatches;
            StepDefinitionAmbiguityReason ambiguityReason;
            CultureInfo bindingCulture = editorContext.ProjectScope.SpecFlowProjectConfiguration.RuntimeConfiguration.BindingCulture ?? step.StepContext.Language;
            var match = bindingMatchService.GetBestMatch(step, bindingCulture, out ambiguityReason, out candidatingMatches);
            var binding = match.StepBinding;

            if (!match.Success)
            {
                if (candidatingMatches.Any())
                {
                    string bindingsText = string.Join(Environment.NewLine, candidatingMatches.Select(b => b.StepBinding.Method.GetShortDisplayText()));
                    MessageBox.Show("Multiple matching bindings found. Navigating to the first match..."
                        + Environment.NewLine + Environment.NewLine + bindingsText, "Go to binding");
                    binding = candidatingMatches.First().StepBinding;
                }
                else
                {
                    var language = editorContext.ProjectScope is VsProjectScope ? VsProjectScope.GetTargetLanguage(((VsProjectScope) editorContext.ProjectScope).Project) : ProgrammingLanguage.CSharp;
                    var stepDefinitionSkeletonStyle = editorContext.ProjectScope.SpecFlowProjectConfiguration.RuntimeConfiguration.StepDefinitionSkeletonStyle;
                    string skeleton = stepDefinitionSkeletonProvider.GetStepDefinitionSkeleton(language, step, stepDefinitionSkeletonStyle, bindingCulture);

                    var result = MessageBox.Show("No matching step binding found for this step! Do you want to copy the step binding skeleton to the clipboard?"
                         + Environment.NewLine + Environment.NewLine + skeleton, "Go to binding", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                    if (result == DialogResult.Yes)
                    {
                        Clipboard.SetText(skeleton);
                    }
                    return true;
                }
            }

            var method = binding.Method;
            var codeFunction = new VsBindingMethodLocator().FindCodeFunction(((VsProjectScope) editorContext.ProjectScope), method);

            if (codeFunction != null)
            {
                if (!codeFunction.ProjectItem.IsOpen)
                {
                    codeFunction.ProjectItem.Open();
                }
                var navigatePoint = codeFunction.GetStartPoint(vsCMPart.vsCMPartHeader);
                navigatePoint.TryToShow();
                navigatePoint.Parent.Selection.MoveToPoint(navigatePoint);
            }

            return true;
        }
Exemplo n.º 9
0
        public bool PreExec(GherkinEditorContext editorContext, Guid pguidCmdGroup, uint nCmdID)
        {
            if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                var vsStd97CmdId = (VSConstants.VSStd97CmdID)nCmdID;
#if TRACE_VS_COMMANDS
                if (vsStd97CmdId != VSConstants.VSStd97CmdID.SearchCombo && vsStd97CmdId != VSConstants.VSStd97CmdID.SolutionCfg)
                    tracer.Trace("Exec/VSStd97CmdID:{0}", this, vsStd97CmdId);
#endif
                switch (vsStd97CmdId)
                {
                    case VSConstants.VSStd97CmdID.GotoDefn:
                        if (goToStepDefinitionCommand.GoToDefinition(editorContext))
                            return true;
                        break;
                }
            }
            else if (pguidCmdGroup == VSConstants.VSStd2K)
            {
                var vsStd2KCmdId = (VSConstants.VSStd2KCmdID)nCmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("Exec/VSStd2KCmdID:{0}", this, vsStd2KCmdId);
#endif
                switch (vsStd2KCmdId)
                {
                    case VSConstants.VSStd2KCmdID.COMMENT_BLOCK:
                    case VSConstants.VSStd2KCmdID.COMMENTBLOCK:
                        if (commentUncommentCommand.CommentOrUncommentSelection(editorContext, CommentUncommentAction.Comment))
                            return true;
                        break;
                    case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK:
                    case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK:
                        if (commentUncommentCommand.CommentOrUncommentSelection(editorContext, CommentUncommentAction.Uncomment))
                            return true;
                        break;
                }
            }
            else if (pguidCmdGroup == GuidList.guidSpecFlowCmdSet)
            {
                var specFlowCmdSet = (SpecFlowCmdSet)nCmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("Exec/SpecFlowCmdSet:{0}", this, specFlowCmdSet);
#endif
                switch (specFlowCmdSet)
                {
                    case SpecFlowCmdSet.RunScenarios:
                        if (runScenariosCommand.InvokeFromEditor(editorContext, null))
                            return true;
                        break;
                    case SpecFlowCmdSet.DebugScenarios:
                        if (debugScenariosCommand.InvokeFromEditor(editorContext, null))
                            return true;
                        break;
                }
            }
            else if(pguidCmdGroup == ReSharperCommandGroups.CommandGroup)
            {
                var reSharperCmd = (ReSharperCommand)nCmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("Exec/ReSharperCommand:{0}", this, reSharperCmd);
#endif
                switch (reSharperCmd)
                {
                    case ReSharperCommand.GotoDeclaration:
                        if (goToStepDefinitionCommand.GoToDefinition(editorContext))
                            return true;
                        break;
                    case ReSharperCommand.LineComment:
                        if (commentUncommentCommand.CommentOrUncommentSelection(editorContext, CommentUncommentAction.Toggle))
                            return true;
                        break;
                    case ReSharperCommand.UnitTestRunContext:
                        if (runScenariosCommand.InvokeFromEditor(editorContext, TestRunnerTool.ReSharper))
                            return true;
                        break;
                    case ReSharperCommand.UnitTestDebugContext:
                        if (debugScenariosCommand.InvokeFromEditor(editorContext, TestRunnerTool.ReSharper))
                            return true;
                        break;
                }
            }
#if TRACE_VS_COMMANDS
            else
            {
                tracer.Trace("Exec/Other:{0} / {1}", this, pguidCmdGroup, nCmdID);
            }
#endif

            return false;
        }
 public EditorCommandFilterInstance(EditorCommandFilter commandFilter, GherkinEditorContext editorContext)
 {
     this.commandFilter = commandFilter;
     this.editorContext = editorContext;
 }
Exemplo n.º 11
0
        public void PostExec(GherkinEditorContext editorContext, Guid pguidCmdGroup, uint nCmdID, IntPtr pvaIn)
        {
            if (pguidCmdGroup == VSConstants.VSStd2K)
            {
                switch ((VSConstants.VSStd2KCmdID) nCmdID)
                {
                    case VSConstants.VSStd2KCmdID.TYPECHAR:
                        var ch = GetTypeChar(pvaIn);
                        if (ch == '|')
                            formatTableCommand.FormatTable(editorContext);
                        break;
                }
            }
//TODO: uncomment this to add further command handlers
//                if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
//                {
//                    switch ((VSConstants.VSStd97CmdID)nCmdID)
//                    {
//                    }
//                }
        }
Exemplo n.º 12
0
        public bool QueryStatus(GherkinEditorContext editorContext, Guid pguidCmdGroup, OLECMD prgCmd)
        {
            if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                var vsStd97CmdId = (VSConstants.VSStd97CmdID)prgCmd.cmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("QueryStatus/VSStd97CmdID:{0}", this, vsStd97CmdId);
#endif
                switch (vsStd97CmdId)
                {
                case VSConstants.VSStd97CmdID.GotoDefn:
                    if (goToStepDefinitionCommand.CanGoToDefinition(editorContext))
                    {
                        return(true);
                    }
                    break;
                }
            }
            else if (pguidCmdGroup == VSConstants.VSStd2K)
            {
                var vsStd2KCmdId = (VSConstants.VSStd2KCmdID)prgCmd.cmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("QueryStatus/VSStd2KCmdID:{0}", this, vsStd2KCmdId);
#endif
                switch (vsStd2KCmdId)
                {
                case VSConstants.VSStd2KCmdID.COMMENT_BLOCK:
                case VSConstants.VSStd2KCmdID.COMMENTBLOCK:
                case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK:
                case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK:
                    return(true);
                }
            }
            else if (pguidCmdGroup == GuidList.guidSpecFlowCmdSet)
            {
                var specFlowCmdSet = (SpecFlowCmdSet)prgCmd.cmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("QueryStatus/SpecFlowCmdSet:{0}", this, specFlowCmdSet);
#endif
                switch (specFlowCmdSet)
                {
                case SpecFlowCmdSet.RunScenarios:
                case SpecFlowCmdSet.DebugScenarios:
                    return(true);
                }
            }
            else if (pguidCmdGroup == ReSharperCommandGroups.CommandGroup)
            {
                var reSharperCmd = (ReSharperCommand)prgCmd.cmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("QueryStatus/ReSharperCommand:{0}", this, reSharperCmd);
#endif
                switch (reSharperCmd)
                {
                case ReSharperCommand.GotoDeclaration:
                    if (goToStepDefinitionCommand.CanGoToDefinition(editorContext))
                    {
                        return(true);
                    }
                    break;

                case ReSharperCommand.LineComment:
                    return(true);

                case ReSharperCommand.UnitTestRunContext:
                case ReSharperCommand.UnitTestDebugContext:
                    return(true);
                }
            }
#if TRACE_VS_COMMANDS
            else
            {
                tracer.Trace("QueryStatus/Other:{0} / {1}", this, pguidCmdGroup, prgCmd.cmdID);
            }
#endif

            return(false);
        }
Exemplo n.º 13
0
        public bool PreExec(GherkinEditorContext editorContext, Guid pguidCmdGroup, uint nCmdID)
        {
            if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                var vsStd97CmdId = (VSConstants.VSStd97CmdID)nCmdID;
#if TRACE_VS_COMMANDS
                if (vsStd97CmdId != VSConstants.VSStd97CmdID.SearchCombo && vsStd97CmdId != VSConstants.VSStd97CmdID.SolutionCfg)
                {
                    tracer.Trace("Exec/VSStd97CmdID:{0}", this, vsStd97CmdId);
                }
#endif
                switch (vsStd97CmdId)
                {
                case VSConstants.VSStd97CmdID.GotoDefn:
                    if (goToStepDefinitionCommand.GoToDefinition(editorContext))
                    {
                        return(true);
                    }
                    break;
                }
            }
            else if (pguidCmdGroup == VSConstants.VSStd2K)
            {
                var vsStd2KCmdId = (VSConstants.VSStd2KCmdID)nCmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("Exec/VSStd2KCmdID:{0}", this, vsStd2KCmdId);
#endif
                switch (vsStd2KCmdId)
                {
                case VSConstants.VSStd2KCmdID.COMMENT_BLOCK:
                case VSConstants.VSStd2KCmdID.COMMENTBLOCK:
                    if (commentUncommentCommand.CommentOrUncommentSelection(editorContext, CommentUncommentAction.Comment))
                    {
                        return(true);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK:
                case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK:
                    if (commentUncommentCommand.CommentOrUncommentSelection(editorContext, CommentUncommentAction.Uncomment))
                    {
                        return(true);
                    }
                    break;
                }
            }
            else if (pguidCmdGroup == GuidList.guidSpecFlowCmdSet)
            {
                var specFlowCmdSet = (SpecFlowCmdSet)nCmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("Exec/SpecFlowCmdSet:{0}", this, specFlowCmdSet);
#endif
                switch (specFlowCmdSet)
                {
                case SpecFlowCmdSet.RunScenarios:
                    if (runScenariosCommand.InvokeFromEditor(editorContext, null))
                    {
                        return(true);
                    }
                    break;

                case SpecFlowCmdSet.DebugScenarios:
                    if (debugScenariosCommand.InvokeFromEditor(editorContext, null))
                    {
                        return(true);
                    }
                    break;
                }
            }
            else if (pguidCmdGroup == ReSharperCommandGroups.CommandGroup)
            {
                var reSharperCmd = (ReSharperCommand)nCmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("Exec/ReSharperCommand:{0}", this, reSharperCmd);
#endif
                switch (reSharperCmd)
                {
                case ReSharperCommand.GotoDeclaration:
                    if (goToStepDefinitionCommand.GoToDefinition(editorContext))
                    {
                        return(true);
                    }
                    break;

                case ReSharperCommand.LineComment:
                    if (commentUncommentCommand.CommentOrUncommentSelection(editorContext, CommentUncommentAction.Toggle))
                    {
                        return(true);
                    }
                    break;

                case ReSharperCommand.UnitTestRunContext:
                    if (runScenariosCommand.InvokeFromEditor(editorContext, TestRunnerTool.ReSharper))
                    {
                        return(true);
                    }
                    break;

                case ReSharperCommand.UnitTestDebugContext:
                    if (debugScenariosCommand.InvokeFromEditor(editorContext, TestRunnerTool.ReSharper))
                    {
                        return(true);
                    }
                    break;
                }
            }
#if TRACE_VS_COMMANDS
            else
            {
                tracer.Trace("Exec/Other:{0} / {1}", this, pguidCmdGroup, nCmdID);
            }
#endif

            return(false);
        }
Exemplo n.º 14
0
        public bool QueryStatus(GherkinEditorContext editorContext, Guid pguidCmdGroup, OLECMD prgCmd)
        {
            if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                var vsStd97CmdId = (VSConstants.VSStd97CmdID)prgCmd.cmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("QueryStatus/VSStd97CmdID:{0}", this, vsStd97CmdId);
#endif
                switch (vsStd97CmdId)
                {
                    case VSConstants.VSStd97CmdID.GotoDefn:
                        prgCmd.cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED;
                        if (goToStepDefinitionCommand.CanGoToDefinition(editorContext))
                            return true;
                        break;
                }
            }
            else if (pguidCmdGroup == VSConstants.VSStd2K)
            {
                var vsStd2KCmdId = (VSConstants.VSStd2KCmdID)prgCmd.cmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("QueryStatus/VSStd2KCmdID:{0}", this, vsStd2KCmdId);
#endif
                switch (vsStd2KCmdId)
                {
                    case VSConstants.VSStd2KCmdID.COMMENT_BLOCK:
                    case VSConstants.VSStd2KCmdID.COMMENTBLOCK:
                    case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK:
                    case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK:
                        prgCmd.cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED;
                        return true;
                }
            }
            else if (pguidCmdGroup == GuidList.guidSpecFlowCmdSet)
            {
                var specFlowCmdSet = (SpecFlowCmdSet)prgCmd.cmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("QueryStatus/SpecFlowCmdSet:{0}", this, specFlowCmdSet);
#endif
                switch (specFlowCmdSet)
                {
                    case SpecFlowCmdSet.RunScenarios:
                    case SpecFlowCmdSet.DebugScenarios:
                        prgCmd.cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED;
                        return true;
                }
            }
            else if(pguidCmdGroup == ReSharperCommandGroups.CommandGroup)
            {
                var reSharperCmd = (ReSharperCommand)prgCmd.cmdID;
#if TRACE_VS_COMMANDS
                tracer.Trace("QueryStatus/ReSharperCommand:{0}", this, reSharperCmd);
#endif
                switch (reSharperCmd)
                {
                    case ReSharperCommand.GotoDeclaration:
                        prgCmd.cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED;
                        if (goToStepDefinitionCommand.CanGoToDefinition(editorContext))
                            return true;
                        break;
                    case ReSharperCommand.LineComment:
                        prgCmd.cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED;
                        return true;
                    case ReSharperCommand.UnitTestRunContext:
                    case ReSharperCommand.UnitTestDebugContext:
                        prgCmd.cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED;
                        return true;
                }
            }
#if TRACE_VS_COMMANDS
            else
            {
                tracer.Trace("QueryStatus/Other:{0} / {1}", this, pguidCmdGroup, prgCmd.cmdID);
            }
#endif

            return false;
        }
 public EditorCommandFilterInstance(EditorCommandFilter commandFilter, GherkinEditorContext editorContext)
 {
     this.commandFilter = commandFilter;
     this.editorContext = editorContext;
 }
Exemplo n.º 16
0
 public bool CanGoToDefinition(GherkinEditorContext editorContext)
 {
     return GetBindingMatchService(editorContext.LanguageService) != null && GetCurrentStep(editorContext) != null;
 }
Exemplo n.º 17
0
        private GherkinStep GetCurrentStep(GherkinEditorContext editorContext)
        {
            var fileScope = editorContext.LanguageService.GetFileScope(waitForLatest: true);
            if (fileScope == null)
                return null;

            SnapshotPoint caret = editorContext.TextView.Caret.Position.BufferPosition;
            IStepBlock block;
            var step = fileScope.GetStepAtPosition(caret.GetContainingLine().LineNumber, out block);

            if (step != null && block is IScenarioOutlineBlock)
                step = step.GetSubstitutedStep((IScenarioOutlineBlock)block);

            return step;
        }
        private bool GenerateStepDefinitionSkeleton(GherkinEditorContext editorContext)
        {
            var bindingMatchService = GetBindingMatchService(editorContext.LanguageService);
            if (bindingMatchService == null)
                return false;

            var fileScope = editorContext.LanguageService.GetFileScope(waitForLatest: true);
            if (fileScope == null)
                return false;

            var featureTitle = GetFeatureTitle(fileScope);
            var bindingCulture = editorContext.ProjectScope.SpecFlowProjectConfiguration.RuntimeConfiguration.BindingCulture ?? fileScope.GherkinDialect.CultureInfo;
            var steps = GetUnboundSteps(bindingMatchService, fileScope, bindingCulture).ToArray();

            if (steps.Length == 0)
            {
                MessageBox.Show("All steps are bound!", "Generate step definition skeleton");
                return true;
            }

            var specFlowProject = ((VsProjectScope) editorContext.ProjectScope).Project;
            var defaultLanguage = VsProjectScope.GetTargetLanguage(specFlowProject);
            var stepDefinitionSkeletonStyle = editorContext.ProjectScope.SpecFlowProjectConfiguration.RuntimeConfiguration.StepDefinitionSkeletonStyle;

            using (var skeletonGeneratorForm = new GenerateStepDefinitionSkeletonForm(featureTitle, steps, specFlowProject, stepDefinitionSkeletonStyle, defaultLanguage, dte))
            {
                skeletonGeneratorForm.OnPreview = (form) =>
                    {
                        var skeleton = stepDefinitionSkeletonProvider.GetBindingClassSkeleton(
                            defaultLanguage, form.SelectedSteps, "MyNamespace",
                            form.ClassName, form.Style, bindingCulture);
                        MessageBox.Show(skeleton, "Step definition skeleton preview");
                    };
                skeletonGeneratorForm.OnCopy = (form) =>
                    {
                        var skeleton = string.Join(Environment.NewLine, 
                            form.SelectedSteps.Select(si => stepDefinitionSkeletonProvider.GetStepDefinitionSkeleton(
                            defaultLanguage, si, form.Style, bindingCulture)).Distinct()).Indent(StepDefinitionSkeletonProvider.METHOD_INDENT);

                        Clipboard.SetText(skeleton);
                        return true;
                    };
                skeletonGeneratorForm.OnGenerate = (form, targetPath) =>
                {
                    var project = GetTartgetProject(targetPath, specFlowProject);
                    var language = VsProjectScope.GetTargetLanguage(project);

                    var skeleton = stepDefinitionSkeletonProvider.GetBindingClassSkeleton(
                        language, form.SelectedSteps, CalculateNamespace(targetPath, project), 
                        form.ClassName, form.Style, bindingCulture);

                    string folder = Path.GetDirectoryName(targetPath);
                    if (folder != null && !Directory.Exists(folder))
                        Directory.CreateDirectory(folder);
                    File.WriteAllText(targetPath, skeleton, Encoding.UTF8);

                    var projectItem = VsxHelper.FindProjectItemByFilePath(project, targetPath);
                    if (projectItem == null)
                        projectItem = project.ProjectItems.AddFromFile(targetPath);

                    if (projectItem != null)
                        projectItem.Open();

                    return true;
                };

                skeletonGeneratorForm.ShowDialog();
            }

            return true;
        }
Exemplo n.º 19
0
 public bool InvokeFromEditor(GherkinEditorContext editorContext, TestRunnerTool? runnerTool)
 {
     return testRunnerEngine.RunFromEditor(editorContext.LanguageService, true, runnerTool);
 }
Exemplo n.º 20
0
        private GherkinStep GetCurrentStep(GherkinEditorContext editorContext)
        {
            var fileScope = editorContext.LanguageService.GetFileScope();
            if (fileScope == null)
                return null;

            SnapshotPoint caret = editorContext.TextView.Caret.Position.BufferPosition;
            return fileScope.GetStepAtPosition(caret.GetContainingLine().LineNumber);
        }