Пример #1
0
 public EditorCommandFilter(IIdeTracer tracer, IGoToStepDefinitionCommand goToStepDefinitionCommand, DebugScenariosCommand debugScenariosCommand, RunScenariosCommand runScenariosCommand, FormatTableCommand formatTableCommand, CommentUncommentCommand commentUncommentCommand)
 {
     this.goToStepDefinitionCommand = goToStepDefinitionCommand;
     this.debugScenariosCommand     = debugScenariosCommand;
     this.runScenariosCommand       = runScenariosCommand;
     this.formatTableCommand        = formatTableCommand;
     this.commentUncommentCommand   = commentUncommentCommand;
     this.tracer = tracer;
 }
Пример #2
0
 public EditorCommandFilter(IIdeTracer tracer, GoToStepDefinitionCommand goToStepDefinitionCommand, DebugScenariosCommand debugScenariosCommand, RunScenariosCommand runScenariosCommand, FormatTableCommand formatTableCommand, CommentUncommentCommand commentUncommentCommand)
 {
     this.goToStepDefinitionCommand = goToStepDefinitionCommand;
     this.debugScenariosCommand = debugScenariosCommand;
     this.runScenariosCommand = runScenariosCommand;
     this.formatTableCommand = formatTableCommand;
     this.commentUncommentCommand = commentUncommentCommand;
     this.tracer = tracer;
 }
Пример #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);
        }