Ejemplo n.º 1
0
        private void ReplaceStepBindingAttribute(CodeFunction codeFunction, IStepDefinitionBinding binding, string newRegex)
        {
            if (!codeFunction.ProjectItem.IsOpen)
            {
                codeFunction.ProjectItem.Open();
            }

            var formattedOldRegex = FormatRegexForDisplay(binding.Regex);

            var navigatePoint = codeFunction.GetStartPoint(vsCMPart.vsCMPartHeader);

            navigatePoint.TryToShow();
            navigatePoint.Parent.Selection.MoveToPoint(navigatePoint);

            var stepBindingEditorContext = GherkinEditorContext.FromDocument(codeFunction.DTE.ActiveDocument, _gherkinLanguageServiceFactory);
            var attributeLinesToUpdate   = stepBindingEditorContext.TextView.TextViewLines.Where(x => x.Start.GetContainingLine().GetText().Contains("\"" + formattedOldRegex + "\""));

            foreach (var attributeLineToUpdate in attributeLinesToUpdate)
            {
                using (var textEdit = attributeLineToUpdate.Snapshot.TextBuffer.CreateEdit())
                {
                    var regexStart = attributeLineToUpdate.Start.GetContainingLine().GetText().IndexOf(formattedOldRegex);
                    textEdit.Replace(attributeLineToUpdate.Start.Position + regexStart, formattedOldRegex.Length, newRegex);
                    textEdit.Apply();
                }
            }
        }
Ejemplo n.º 2
0
        private static IStepDefinitionBinding GetSingleStepDefinitionBinding(GherkinEditorContext editorContext, GherkinStep step)
        {
            var bindingMatchService = editorContext.LanguageService.ProjectScope.BindingMatchService;

            if (bindingMatchService == null)
            {
                return(null);
            }

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

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

            if (candidatingMatches.Count > 1 || !match.Success)
            {
                MessageBox.Show("Cannot rename automatically. You need to have a single and unique binding for this step.");
                return(null);
            }

            return(match.StepBinding);
        }
        /// <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;
        }
Ejemplo n.º 4
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);
        }
        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;
        }
Ejemplo n.º 7
0
        private static 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);
        }
Ejemplo n.º 8
0
        public bool Rename(GherkinEditorContext editorContext)
        {
            var step = GetCurrentStep(editorContext);

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

            var stepBinding = GetSingleStepDefinitionBinding(editorContext, step);

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

            var codeFunction = FindBindingMethodCodeFunction(editorContext, stepBinding);

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

            var newStepRegex = PromptForNewStepRegex(stepBinding.Regex);

            if (string.IsNullOrEmpty(newStepRegex))
            {
                return(false);
            }

            var stepInstancesToRename = FindAllStepMatchingStepInstances(codeFunction.DTE.ActiveDocument, stepBinding.Method);

            foreach (var stepInstanceToRename in stepInstancesToRename)
            {
                RenameStep(stepInstanceToRename, newStepRegex, stepBinding);
            }

            ReplaceStepBindingAttribute(codeFunction, stepBinding, newStepRegex);

            return(true);
        }
Ejemplo n.º 9
0
        private void RenameStep(StepInstanceWithProjectScope stepInstance, string newStepRegex, IStepDefinitionBinding binding)
        {
            var featureFileDocument = JumpToStep(stepInstance);

            if (featureFileDocument == null)
            {
                return;
            }

            var stepEditorContext = GherkinEditorContext.FromDocument(featureFileDocument, _gherkinLanguageServiceFactory);

            var stepToRename = GetCurrentStep(stepEditorContext);

            if (stepToRename == null)
            {
                return;
            }

            if (!binding.Regex.IsMatch(stepToRename.Text))
            {
                return;
            }

            var stepLineStart = stepEditorContext.TextView.Selection.Start.Position.GetContainingLine();

            using (var stepNameTextEdit = stepLineStart.Snapshot.TextBuffer.CreateEdit())
            {
                var line                  = stepLineStart.Snapshot.GetLineFromLineNumber(stepLineStart.LineNumber);
                var lineText              = line.GetText();
                var trimmedText           = lineText.Trim();
                var numLeadingWhiteSpaces = lineText.Length - trimmedText.Length;

                var actualStepName = trimmedText.Substring(stepToRename.Keyword.Length);
                var newStepName    = BuildStepNameWithNewRegex(actualStepName, newStepRegex, binding);

                var stepNamePosition = line.Start.Position + numLeadingWhiteSpaces + stepToRename.Keyword.Length;
                stepNameTextEdit.Replace(stepNamePosition, actualStepName.Length, newStepName);

                stepNameTextEdit.Apply();
            }
        }
        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 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 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)
//                    {
//                    }
//                }
        }
        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;
        }
 public EditorCommandFilterInstance(EditorCommandFilter commandFilter, GherkinEditorContext editorContext)
 {
     this.commandFilter = commandFilter;
     this.editorContext = editorContext;
 }
 public bool InvokeFromEditor(GherkinEditorContext editorContext, TestRunnerTool? runnerTool)
 {
     return testRunnerEngine.RunFromEditor(editorContext.LanguageService, false, runnerTool);
 }
        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;
        }
 public bool CanGoToDefinition(GherkinEditorContext editorContext)
 {
     return GetBindingMatchService(editorContext.LanguageService) != null && GetCurrentStep(editorContext) != null;
 }
        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;
        }
        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);
        }
Ejemplo n.º 21
0
 private static CodeFunction FindBindingMethodCodeFunction(GherkinEditorContext editorContext, IStepDefinitionBinding binding)
 {
     return(new VsBindingMethodLocator().FindCodeFunction(((VsProjectScope)editorContext.ProjectScope), binding.Method));
 }
        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);
        }
 public EditorCommandFilterInstance(EditorCommandFilter commandFilter, GherkinEditorContext editorContext)
 {
     this.commandFilter = commandFilter;
     this.editorContext = editorContext;
 }
        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)
//                    {
//                    }
//                }
        }
        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;
        }