Beispiel #1
0
        public override bool PreExec(IWpfTextView textView, DeveroomEditorCommandTargetKey commandKey, IntPtr inArgs = default(IntPtr))
        {
            var sessionManager = GetCompletionSessionManager(textView);

            if (AutoCompleteCommands.Contains(commandKey))
            {
                return(sessionManager.TriggerCompletion());
            }

            if (commandKey.Equals(ReturnCommand))
            {
                return(sessionManager.Complete(false));
            }

            if (commandKey.Equals(TabCommand))
            {
                return(sessionManager.Complete(true));
            }

            if (commandKey.Equals(CancelCommand))
            {
                return(sessionManager.Cancel());
            }

            return(false);
        }
Beispiel #2
0
        public override bool PreExec(IWpfTextView textView, DeveroomEditorCommandTargetKey commandKey, IntPtr inArgs = default(IntPtr))
        {
            Logger.LogVerbose("Go To Step Definition");

            var textBuffer = textView.TextBuffer;

            var stepTag = GetDeveroomTagForCaret(textView, DeveroomTagTypes.StepBlock);

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

            var matchedStepTag = stepTag.ChildTags.FirstOrDefault(t => t.Type == DeveroomTagTypes.DefinedStep || t.Type == DeveroomTagTypes.UndefinedStep);

            if (matchedStepTag != null &&
                matchedStepTag.Data is MatchResult matchResult)
            {
                if (matchResult.HasSingleMatch)
                {
                    var matchResultItem = matchResult.Items.First();
                    PerformGoToDefinition(matchResultItem, textBuffer);
                }
                else
                {
                    Logger.LogVerbose($"Jump to list step: {matchResult}");
                    IdeScope.Actions.ShowSyncContextMenu(PopupHeader, matchResult.Items.Select(m =>
                                                                                               new ContextMenuItem(m.ToString(), _ => { PerformGoToDefinition(m, textBuffer); }, GetIcon(m))
                                                                                               ).ToArray());
                }
            }

            return(true);
        }
        public override bool PreExec(IWpfTextView textView, DeveroomEditorCommandTargetKey commandKey, IntPtr inArgs = default(IntPtr))
        {
            Logger.LogVerbose("Find Step Definition Usages");

            var textBuffer   = textView.TextBuffer;
            var fileName     = GetEditorDocumentPath(textView);
            var triggerPoint = textView.Caret.Position.BufferPosition;

            var project = IdeScope.GetProject(textBuffer);

            if (project == null || !project.GetProjectSettings().IsSpecFlowProject)
            {
                IdeScope.Actions.ShowProblem("Unable to find step definition usages: the project is not detected to be a SpecFlow project or it is not initialized yet.");
                return(true);
            }

            var specFlowTestProjects = IdeScope.GetProjectsWithFeatureFiles()
                                       .Where(p => p.GetProjectSettings().IsSpecFlowTestProject)
                                       .ToArray();

            if (specFlowTestProjects.Length == 0)
            {
                IdeScope.Actions.ShowProblem("Unable to find step definition usages: could not find any SpecFlow project with feature files.");
                return(true);
            }

            var asyncContextMenu = IdeScope.Actions.ShowAsyncContextMenu(PopupHeader);

            Task.Run(() => FindUsagesInProjectsAsync(specFlowTestProjects, fileName, triggerPoint, asyncContextMenu, asyncContextMenu.CancellationToken), asyncContextMenu.CancellationToken);
            return(true);
        }
        public override bool PreExec(IWpfTextView textView, DeveroomEditorCommandTargetKey commandKey, IntPtr inArgs = default(IntPtr))
        {
            MonitoringService.MonitorCommandCommentUncomment();

            var selectionSpan = GetSelectionSpan(textView);
            var lines         = GetSpanFullLines(selectionSpan).ToArray();

            Debug.Assert(lines.Length > 0);

            using (var textEdit = selectionSpan.Snapshot.TextBuffer.CreateEdit())
            {
                foreach (var line in lines)
                {
                    int commentCharPosition = line.GetText().IndexOf('#');
                    if (commentCharPosition >= 0)
                    {
                        textEdit.Delete(line.Start.Position + commentCharPosition, 1);
                    }
                }
                textEdit.Apply();
            }

            SetSelectionToChangedLines(textView, lines);

            return(true);
        }
Beispiel #5
0
        public override bool PostExec(IWpfTextView textView, DeveroomEditorCommandTargetKey commandKey, IntPtr inArgs = default(IntPtr))
        {
            var sessionManager = GetCompletionSessionManager(textView);

            if (commandKey.Equals(TypeCharCommand))
            {
                return(base.PostExec(textView, commandKey, inArgs));
            }

            if (commandKey.Equals(BackspaceCommand))
            {
                return(sessionManager.Filter());
            }

            return(false);
        }
Beispiel #6
0
        public override bool PreExec(IWpfTextView textView, DeveroomEditorCommandTargetKey commandKey, IntPtr inArgs = default(IntPtr))
        {
            MonitoringService.MonitorCommandCommentUncomment();

            var selectionSpan = GetSelectionSpan(textView);
            var lines         = GetSpanFullLines(selectionSpan).ToArray();

            Debug.Assert(lines.Length > 0);

            int indent = lines.Min(l => l.GetText().TakeWhile(char.IsWhiteSpace).Count());

            using (var textEdit = selectionSpan.Snapshot.TextBuffer.CreateEdit())
            {
                foreach (var line in lines)
                {
                    textEdit.Insert(line.Start.Position + indent, "#");
                }
                textEdit.Apply();
            }

            SetSelectionToChangedLines(textView, lines);

            return(true);
        }
        public override bool PreExec(IWpfTextView textView, DeveroomEditorCommandTargetKey commandKey, IntPtr inArgs = default(IntPtr))
        {
            Logger.LogVerbose("Create Step Definitions");

            var projectScope    = IdeScope.GetProject(textView.TextBuffer);
            var projectSettings = projectScope?.GetProjectSettings();

            if (projectScope == null || !projectSettings.IsSpecFlowProject)
            {
                IdeScope.Actions.ShowProblem("Define steps command can only be invoked for feature files in SpecFlow projects");
                return(true);
            }

            var featureTag = GetDeveroomTagForCaret(textView, DeveroomTagTypes.FeatureBlock);

            if (featureTag == null)
            {
                Logger.LogWarning("Define steps command called for a file without feature block");
                return(true);
            }

            var snippetService = projectScope.GetSnippetService();

            if (snippetService == null)
            {
                return(true);
            }

            var undefinedStepTags = featureTag.GetDescendantsOfType(DeveroomTagTypes.UndefinedStep).ToArray();

            if (undefinedStepTags.Length == 0)
            {
                IdeScope.Actions.ShowProblem("All steps have been defined in this file already.");
                return(true);
            }

            const string indent  = "    ";
            string       newLine = Environment.NewLine;

            var feature   = (Feature)featureTag.Data;
            var viewModel = new CreateStepDefinitionsDialogViewModel();

            viewModel.ClassName = feature.Name.ToIdentifier() + "Steps";

            foreach (var undefinedStepTag in undefinedStepTags)
            {
                var matchResult = (MatchResult)undefinedStepTag.Data;
                foreach (var match in matchResult.Items.Where(mi => mi.Type == MatchResultType.Undefined))
                {
                    var snippet = snippetService.GetStepDefinitionSkeletonSnippet(match.UndefinedStep, indent, newLine);
                    if (viewModel.Items.Any(i => i.Snippet == snippet))
                    {
                        continue;
                    }

                    viewModel.Items.Add(new StepDefinitionSnippetItemViewModel {
                        Snippet = snippet
                    });
                }
            }

            IdeScope.WindowManager.ShowDialog(viewModel);

            if (viewModel.Result == CreateStepDefinitionsDialogResult.Cancel)
            {
                return(true);
            }

            if (viewModel.Items.Count(i => i.IsSelected) == 0)
            {
                IdeScope.Actions.ShowProblem("No snippet was selected");
                return(true);
            }

            var combinedSnippet = string.Join(newLine, viewModel.Items.Where(i => i.IsSelected).Select(i => i.Snippet.Indent(indent + indent)));

            MonitoringService.MonitorCommandDefineSteps(viewModel.Result, viewModel.Items.Count(i => i.IsSelected));

            switch (viewModel.Result)
            {
            case CreateStepDefinitionsDialogResult.Create:
                SaveAsStepDefinitionClass(projectScope, combinedSnippet, viewModel.ClassName, indent, newLine);
                break;

            case CreateStepDefinitionsDialogResult.CopyToClipboard:
                Logger.LogVerbose($"Copy to clipboard: {combinedSnippet}");
                IdeScope.Actions.SetClipboardText(combinedSnippet);
                break;
            }

            return(true);
        }
        public override DeveroomEditorCommandStatus QueryStatus(IWpfTextView textView, DeveroomEditorCommandTargetKey commandKey)
        {
            var projectScope    = IdeScope.GetProject(textView.TextBuffer);
            var projectSettings = projectScope?.GetProjectSettings();

            if (projectScope == null || !projectSettings.IsSpecFlowProject)
            {
                return(DeveroomEditorCommandStatus.Disabled);
            }
            return(base.QueryStatus(textView, commandKey));
        }
        public override DeveroomEditorCommandStatus QueryStatus(IWpfTextView textView, DeveroomEditorCommandTargetKey commandKey)
        {
            var status = base.QueryStatus(textView, commandKey);

            if (status != DeveroomEditorCommandStatus.NotSupported)
            {
                // very basic heuristic: if the word "SpecFlow" is in the content of the file, it might be a binding class
                status = textView.TextBuffer.CurrentSnapshot.GetText().Contains("SpecFlow")
                    ? DeveroomEditorCommandStatus.Supported
                    : DeveroomEditorCommandStatus.NotSupported;
            }

            return(status);
        }