示例#1
0
 public EditorCommandFilter(IIdeTracer tracer, IGoToStepDefinitionCommand goToStepDefinitionCommand, FormatTableCommand formatTableCommand, CommentUncommentCommand commentUncommentCommand, RenameCommand renameCommand)
 {
     this.goToStepDefinitionCommand = goToStepDefinitionCommand;
     this.formatTableCommand        = formatTableCommand;
     this.commentUncommentCommand   = commentUncommentCommand;
     this.renameCommand             = renameCommand;
     this.tracer = tracer;
 }
示例#2
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);
        }