private static DocumentLine GetBeginOfTable(GherkinSimpleParser parser, TextDocument document, DocumentLine line)
        {
            Token token = parser.ParseToken(GetText(document, line));

            if (token.MatchedType != TokenType.TableRow)
            {
                return(null);
            }

            DocumentLine beginOfTable = line;

            line = line.PreviousLine;
            while (line != null)
            {
                token = parser.ParseToken(GetText(document, line));
                if (token.MatchedType == TokenType.TableRow)
                {
                    beginOfTable = line;
                    line         = line.PreviousLine;
                }
                else
                {
                    break;
                }
            }

            return(beginOfTable);
        }
        public override void IndentLines(TextDocument document, int beginLine, int endLine)
        {
            if (!SupportMultiLinesIndent(document))
            {
                base.IndentLines(document, beginLine, endLine);
                return;
            }

            DocumentLine line   = document.GetLineByNumber(beginLine);
            int          offset = line?.Offset ?? -1;
            int          length = CalcSegmentLength(line, endLine);

            if ((offset == -1) || (length == 0))
            {
                return;
            }

            IndentationCompletedArg eventArg = PrepareIndentationCompletedArg(document);

            GherkinSimpleParser parser = new GherkinSimpleParser(document);
            string formatted_text      = parser.Format(beginLine, endLine);

            if (endLine == document.LineCount)
            {
                StringBuilder sb = new StringBuilder(formatted_text);
                sb.TrimEnd().AppendLine();
                formatted_text = sb.ToString();
            }
            document.Replace(offset, length, formatted_text);

            EventAggregator <IndentationCompletedArg> .Instance.Publish(MainEditor, eventArg);
        }
示例#3
0
        private bool CanFormatTable(TextDocument document, DocumentLine line)
        {
            if (!GherkinUtil.IsFeatureFile(Document.FileName))
            {
                return(false);
            }

            GherkinSimpleParser       parser   = new GherkinSimpleParser(document);
            Tuple <TokenType, string> lineType = parser.Format(GetText(document, line));

            if (lineType.Item1 != TokenType.TableRow)
            {
                return(false);
            }

            var previousLine = line?.PreviousLine;

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

            Tuple <TokenType, string> previousLineType = parser.Format(GetText(document, previousLine));

            if (previousLineType.Item1 == TokenType.TableRow)
            {
                return(true);
            }
            else
            {
                Tuple <TokenType, string> currentLineType = parser.Format(GetText(document, line));
                return(currentLineType.Item1 == TokenType.TableRow);
            }
        }
示例#4
0
 public GherkinFoldingBuilder(TextDocument document, bool isCloseTablesFolding, bool isCloseScenarioFolding)
 {
     this.Document          = document;
     IsCloseTablesFolding   = isCloseTablesFolding;
     IsCloseScenarioFolding = isCloseScenarioFolding;
     parser = new GherkinSimpleParser(document);
 }
示例#5
0
 public GherkinCodeCompletionWordsProvider(TextDocument document, TextEnteredPosition enteredText, IAppSettings appSettings)
 {
     Document             = document;
     TextEnteredPosition  = enteredText;
     m_AppSettings        = appSettings;
     IsEditingDescription = false;
     Parser = new GherkinSimpleParser(document);
 }
        public static void ExtractTableRange(TextArea textArea, out DocumentLine beginLine, out DocumentLine endLine)
        {
            int                 offset      = textArea.Caret.Offset;
            TextDocument        document    = textArea.Document;
            DocumentLine        currentLine = document.GetLineByOffset(offset);
            GherkinSimpleParser parser      = new GherkinSimpleParser(document);

            beginLine = GetBeginOfTable(parser, document, currentLine);
            endLine   = GetEndOfTable(parser, document, beginLine);
        }
        private List <string> GetCurrentTableText()
        {
            int                 offset = Editor.TextArea.Caret.Offset;
            DocumentLine        line   = Document.GetLineByOffset(offset);
            GherkinSimpleParser parser = new GherkinSimpleParser(Document);

            DocumentLine beginOfTable = GetBeginOfTable(parser, Document, line);

            if (beginOfTable != null)
            {
                return(ExtractTableText(parser, beginOfTable));
            }
            else
            {
                return(new List <string>());
            }
        }
        private static DocumentLine GetEndOfTable(GherkinSimpleParser parser, TextDocument document, DocumentLine beginLine)
        {
            DocumentLine endLine   = beginLine;
            DocumentLine tableLine = beginLine.NextLine;

            while (tableLine != null)
            {
                Token token = parser.ParseToken(GetText(document, tableLine));
                if (token.MatchedType == TokenType.TableRow)
                {
                    endLine   = tableLine;
                    tableLine = tableLine.NextLine;
                }
                else
                {
                    break;
                }
            }

            return(endLine);
        }
        private List <string> ExtractTableText(GherkinSimpleParser parser, DocumentLine beginOfTable)
        {
            List <string> tableText = new List <string>();
            DocumentLine  line      = beginOfTable;

            while (line != null)
            {
                Token token = parser.ParseToken(GetText(Document, line));
                if (token.MatchedType == TokenType.TableRow)
                {
                    tableText.Add(GetText(Document, line).Trim());
                    line = line.NextLine;
                }
                else
                {
                    break;
                }
            }

            return(tableText);
        }
        public override void IndentLine(TextDocument document, DocumentLine line)
        {
            if (!GherkinUtil.IsFeatureFile(document?.FileName))
            {
                base.IndentLine(document, line);
                return;
            }

            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }
            if (line == null)
            {
                throw new ArgumentNullException(nameof(line));
            }

            if (string.IsNullOrEmpty(document.FileName) ||
                !GherkinUtil.IsFeatureFile(document.FileName))
            {
                return;
            }

            DocumentLine previousLine = line.PreviousLine;

            if (previousLine == null)
            {
                return;
            }

            GherkinSimpleParser       parser = new GherkinSimpleParser(document);
            Tuple <TokenType, string> result = parser.Format(GetText(document, previousLine));

            switch (result.Item1)
            {
            case TokenType.FeatureLine:
            case TokenType.BackgroundLine:
            case TokenType.ExamplesLine:
            case TokenType.StepLine:
                document.Replace(previousLine.Offset, previousLine.TotalLength,
                                 MakeTwoLines(result.Item2, GherkinSimpleParser.IDENT2));
                break;

            case TokenType.ScenarioLine:
            case TokenType.ScenarioOutlineLine:
                string guid_tag = MakeGUID(document, previousLine.PreviousLine);
                document.Replace(previousLine.Offset, previousLine.TotalLength,
                                 MakeThreeLines(guid_tag, result.Item2, GherkinSimpleParser.IDENT2));
                break;

            case TokenType.TableRow:
                if (!TableFormatter.FormatTable(line, isEnteredNewLine: true, isColumnInserted: false))
                {
                    base.IndentLine(Document, line);
                }
                break;

            default:
                base.IndentLine(document, line);
                break;
            }
        }