Пример #1
0
        public void pyString(string text, int line)
        {
            FlushDelayedCalls();

            var editorLine             = GetEditorLine(line);
            GherkinBufferSpan textSpan = GetMultilineTextSpan(editorLine, text);

            UpdateLastProcessedEditorLine(textSpan.EndPosition.Line);

            gherkinListener.MultilineText(text, textSpan);
        }
        private void ColorizeLinePart(string value, GherkinBufferSpan span, IClassificationType classificationType)
        {
            var textPosition = gherkinBuffer.IndexOfTextForLine(value, span.StartPosition.Line);
            if (textPosition == null)
                return;

            var textSpan = new GherkinBufferSpan(
                textPosition,
                textPosition.ShiftByCharacters(value.Length));
            ColorizeSpan(textSpan, classificationType);
        }
Пример #3
0
        public void Examples(string keyword, string name, string description, GherkinBufferSpan headerSpan, GherkinBufferSpan descriptionSpan)
        {
            var position = GetFilePosition(headerSpan.StartPosition);
            var exampleBuilder = new ExampleBuilder(name, description, position);
            tableProcessor = exampleBuilder;

            if (exampleProcessor == null)
                throw new GherkinSemanticErrorException(
                    "Examples can only be specified for a scenario outline.", position);
            exampleProcessor.ProcessExample(exampleBuilder);
        }
        private void ColorizeSpan(GherkinBufferSpan span, IClassificationType classificationType)
        {
            if (span == null)
                return;

            var startLine = textSnapshot.GetLineFromLineNumber(span.StartPosition.Line);
            var endLine = span.StartPosition.Line == span.EndPosition.Line ? 
                startLine : textSnapshot.GetLineFromLineNumber(span.EndPosition.Line);
            var startIndex = startLine.Start + span.StartPosition.LinePosition;
            var endLinePosition = span.EndPosition.LinePosition == endLine.Length ? 
                endLine.LengthIncludingLineBreak : span.EndPosition.LinePosition;
            var length = endLine.Start + endLinePosition - startIndex;
            AddClassification(classificationType, startIndex, length);
        }
        private void ColorizeSpan(GherkinBufferSpan span, IClassificationType classificationType)
        {
            if (span == null)
                return;

            var startLine = textSnapshot.GetLineFromLineNumber(span.StartPosition.Line);
            var endLine = span.StartPosition.Line == span.EndPosition.Line ? startLine :
                textSnapshot.GetLineFromLineNumber(span.EndPosition.Line);
            var startIndex = startLine.Start + span.StartPosition.LinePosition;

            AddClassification(classificationType, 
                startIndex, 
                endLine.Start + span.EndPosition.LinePosition - startIndex);
        }
Пример #6
0
        public void Comment(string commentText, GherkinBufferSpan commentSpan)
        {
            if (GherkinDialectServices.IsLanguageLine(commentText))
                return;

            var position = GetFilePosition(commentSpan.StartPosition);
            string trimmedComment = commentText.TrimStart(' ', '#', '\t');
            position.Column += commentText.Length - trimmedComment.Length;
            trimmedComment = trimmedComment.Trim();

            if (trimmedComment.Length == 0)
                return;

            featureBuilder.AddComment(trimmedComment, position);
        }
Пример #7
0
        private GherkinBufferSpan[] GetCellSpans(int editorLine, string[] cells)
        {
            var cellSeparatorPositions =
                GherkinBuffer.GetMatchesForLine(cellSeparatorRe, editorLine).ToArray();

            var result = new GherkinBufferSpan[cells.Length];

            for (int cellIndex = 0; cellIndex < cells.Length; cellIndex++)
            {
                if (cellSeparatorPositions.Length - 1 < cellIndex + 1)
                {
                    break;
                }

                result[cellIndex] = new GherkinBufferSpan(
                    cellSeparatorPositions[cellIndex].ShiftByCharacters(1),
                    cellSeparatorPositions[cellIndex + 1]);
            }

            return(result);
        }
Пример #8
0
        private void PrepareBuffer()
        {
            var newLineMatches = newLineRe.Matches(content);

            lineStarts  = new int[newLineMatches.Count + 1];
            lineLengths = new int[lineStarts.Length];

            int lineIndex = 0;

            lineStarts[0] = 0;
            foreach (Match newLineMatch in newLineMatches)
            {
                lineLengths[lineIndex] = newLineMatch.Index - lineStarts[lineIndex];
                lineIndex++;
                lineStarts[lineIndex] = newLineMatch.Index + newLineMatch.Length;
            }
            lineLengths[lineIndex] = content.Length - lineStarts[lineIndex];

            var lastLine = LineCount - 1;

            EntireContentSpan = new GherkinBufferSpan(this, 0, 0, lastLine, GetLineLength(lastLine));
        }
 public void Feature(string keyword, string name, string description, GherkinBufferSpan headerSpan, GherkinBufferSpan descriptionSpan)
 {
     ColorizeKeywordLine(keyword, headerSpan, classifications.FeatureTitle);
     ColorizeSpan(descriptionSpan, classifications.Description);
 }
 public void Comment(string commentText, GherkinBufferSpan commentSpan)
 {
     ColorizeSpan(commentSpan, classifications.Comment);
 }
        public void Step(string keyword, StepKeyword stepKeyword, Parser.Gherkin.ScenarioBlock scenarioBlock, string text, GherkinBufferSpan stepSpan)
        {
            ColorizeKeywordLine(keyword, stepSpan, classifications.StepText);

            if (CurrentFileBlockBuilder.BlockType == typeof(IScenarioOutlineBlock))
            {
                var matches = placeholderRe.Matches(text);
                foreach (Match match in matches)
                    ColorizeLinePart(match.Value, stepSpan, classifications.Placeholder);
            }

            var editorLine = stepSpan.StartPosition.Line;
            var tags = FeatureTags.Concat(CurrentFileBlockBuilder.Tags).Distinct();
            var stepScope = new StepScope(FeatureTitle, CurrentFileBlockBuilder.BlockType == typeof(IBackgroundBlock) ? null : CurrentFileBlockBuilder.Title, tags.ToArray());

            currentStep = new GherkinStep((BindingType)scenarioBlock, (StepDefinitionKeyword)stepKeyword, text, stepScope, keyword, editorLine - CurrentFileBlockBuilder.KeywordLine);
            CurrentFileBlockBuilder.Steps.Add(currentStep);
        }
        public virtual void Background(string keyword, string name, string description, GherkinBufferSpan headerSpan, GherkinBufferSpan descriptionSpan)
        {
            NewBlock(headerSpan.StartPosition.Line);
            CurrentFileBlockBuilder.SetMainData(typeof(IBackgroundBlock), headerSpan.StartPosition.Line, keyword, name);
            currentStep = null;

            RegisterKeyword(keyword, headerSpan);
            ColorizeSpan(descriptionSpan, classifications.Description);
        }
 public void TableRow(string[] cells, GherkinBufferSpan rowSpan, GherkinBufferSpan[] cellSpans)
 {
     foreach (var cellSpan in cellSpans)
     {
         ColorizeSpan(cellSpan, classifications.TableCell);
     }
 }
 public void ScenarioTag(string name, GherkinBufferSpan tagSpan)
 {
     EnsureNewScenario(tagSpan.StartPosition.Line);
     ColorizeSpan(tagSpan, classifications.Tag);
 }
        private ScenarioEditorInfo ProcessScenario(string keyword, string name, GherkinBufferSpan headerSpan, GherkinBufferSpan descriptionSpan)
        {
            EnsureNewScenario(headerSpan.StartPosition.Line);

            ColorizeKeywordLine(keyword, headerSpan, classifications.ScenarioTitle);
            ColorizeSpan(descriptionSpan, classifications.Description);

            var scenario = gherkinFileEditorInfo.ScenarioEditorInfos.Last();
            scenario.KeywordLine = headerSpan.StartPosition.Line;
            scenario.Title = name;
            scenario.Keyword = keyword;
            return scenario;
        }
        public void Step(string keyword, StepKeyword stepKeyword, Parser.Gherkin.ScenarioBlock scenarioBlock, string text, GherkinBufferSpan stepSpan)
        {
            if (CurrentFileBlockBuilder.BlockType == typeof(IScenarioOutlineBlock))
            {
                var matches = placeholderRe.Matches(text);
                foreach (Match match in matches)
                    ColorizeLinePart(match.Value, stepSpan, classifications.Placeholder);
            }

            var editorLine = stepSpan.StartPosition.Line;
            var tags = FeatureTags.Concat(CurrentFileBlockBuilder.Tags).Distinct();
            var stepContext = new StepContext(FeatureTitle, CurrentFileBlockBuilder.BlockType == typeof(IBackgroundBlock) ? null : CurrentFileBlockBuilder.Title, tags.ToArray(), gherkinFileScope.GherkinDialect.CultureInfo);

            currentStep = new GherkinStep((StepDefinitionType)scenarioBlock, (StepDefinitionKeyword)stepKeyword, text, stepContext, keyword, editorLine - CurrentFileBlockBuilder.KeywordLine);
            CurrentFileBlockBuilder.Steps.Add(currentStep);



            var bindingMatchService = projectScope.BindingMatchService;
         


            if (bindingMatchService.Ready && bindingMatchService != null)
            {
                List<BindingMatch> candidatingMatches;
                candidatingMatches = null;
                StepDefinitionAmbiguityReason ambiguityReason;
                CultureInfo bindingCulture = currentStep.StepContext.Language;
                var match = bindingMatchService.GetBestMatch(currentStep, bindingCulture, out ambiguityReason, out candidatingMatches);

                if (candidatingMatches.Count == 0)
                {
                    ColorizeKeywordLine(keyword, stepSpan, classifications.StepText);
                }
                else
                {
                    ColorizeKeywordLine(keyword, stepSpan, classifications.KnownStepText);
                    foreach (String value in candidatingMatches.First().StepBinding.Regex.Split(text))
                        ColorizeLinePart(value, stepSpan, classifications.Variable);
                }
                  

            
            }
            else
                ColorizeKeywordLine(keyword, stepSpan, classifications.StepText);

        }
 public void ScenarioTag(string name, GherkinBufferSpan tagSpan)
 {
     EnsureNewScenario(tagSpan.StartPosition.Line);
     CurrentFileBlockBuilder.Tags.Add(name.TrimStart('@'));
     ColorizeSpan(tagSpan, classifications.Tag);
 }
 public void FeatureTag(string name, GherkinBufferSpan tagSpan)
 {
     ColorizeSpan(tagSpan, classifications.Tag);
     CurrentFileBlockBuilder.Tags.Add(name.TrimStart('@'));
 }
        private void ProcessScenario(string keyword, string name, GherkinBufferSpan headerSpan, GherkinBufferSpan descriptionSpan, Type blockType)
        {
            EnsureNewScenario(headerSpan.StartPosition.Line);
            CurrentFileBlockBuilder.SetMainData(blockType, headerSpan.StartPosition.Line, keyword, name);

            ColorizeKeywordLine(keyword, headerSpan, classifications.ScenarioTitle);
            ColorizeSpan(descriptionSpan, classifications.Description);
        }
 public void ScenarioOutline(string keyword, string name, string description, GherkinBufferSpan headerSpan, GherkinBufferSpan descriptionSpan)
 {
     ProcessScenario(keyword, name, headerSpan, descriptionSpan, typeof(IScenarioOutlineBlock));
 }
        public void Examples(string keyword, string name, string description, GherkinBufferSpan headerSpan, GherkinBufferSpan descriptionSpan)
        {
            var editorLine = headerSpan.StartPosition.Line;
            OnCloseLevel2Outlinings(CalculateRegionEndLine(editorLine));

            RegisterKeyword(keyword, headerSpan);
            ColorizeSpan(descriptionSpan, classifications.Description);

            ScenarioOutlineExampleSet exampleSet = new ScenarioOutlineExampleSet(keyword, name, 
                editorLine - CurrentFileBlockBuilder.KeywordLine);
            CurrentFileBlockBuilder.ExampleSets.Add(exampleSet);

            CloseLevel2Outlinings += regionEndLine =>
                                         {
                                             if (regionEndLine > editorLine)
                                                 AddOutline(
                                                     editorLine,
                                                     regionEndLine,
                                                     exampleSet.FullTitle());
                                         };
        }
 public void Examples(string keyword, string name, string description, GherkinBufferSpan headerSpan, GherkinBufferSpan descriptionSpan)
 {
     //TODO: outline
     RegisterKeyword(keyword, headerSpan);
     ColorizeSpan(descriptionSpan, classifications.Description);
 }
 public void ScenarioOutline(string keyword, string name, string description, GherkinBufferSpan headerSpan, GherkinBufferSpan descriptionSpan)
 {
     ScenarioEditorInfo scenario = ProcessScenario(keyword, name, headerSpan, descriptionSpan);
     scenario.IsScenarioOutline = true;
 }
 public void TableRow(string[] cells, GherkinBufferSpan rowSpan, GherkinBufferSpan[] cellSpans)
 {
     foreach (var cellSpan in cellSpans)
     {
         ColorizeSpan(cellSpan, classifications.TableCell);
     }
     if (currentStep != null)
     {
         try
         {
             currentStep.TableArgument.AddRow(cells);
         }
         catch (Exception)
         {
             //TODO: shall we mark it as error?
         }
     }
     //TODO: register outline example
 }
 public void FeatureTag(string name, GherkinBufferSpan tagSpan)
 {
     ColorizeSpan(tagSpan, classifications.Tag);
 }
        public void MultilineText(string text, GherkinBufferSpan textSpan)
        {
            ColorizeSpan(textSpan, classifications.MultilineText);

            if (currentStep != null)
            {
                currentStep.MultilineTextArgument = text;
            }
            else
            {
                //TODO: shall we mark it as error?
            }
        }
        public void Step(string keyword, StepKeyword stepKeyword, ScenarioBlock scenarioBlock, string text, GherkinBufferSpan stepSpan)
        {
            RegisterKeyword(keyword, stepSpan);

            var scenario = gherkinFileEditorInfo.ScenarioEditorInfos.LastOrDefault();
            if (scenario == null)
                return;
            if (scenario.IsScenarioOutline)
            {
                var matches = placeholderRe.Matches(text);
                foreach (Match match in matches)
                    ColorizeLinePart(match.Value, stepSpan, classifications.Placeholder);
            }
        }
 private void RegisterKeyword(string keyword, GherkinBufferSpan headerSpan)
 {
     var keywordSpan = new GherkinBufferSpan(headerSpan.StartPosition,
         headerSpan.StartPosition.ShiftByCharacters(keyword.Length));
     ColorizeSpan(keywordSpan, classifications.Keyword);
 }
 public void MultilineText(string text, GherkinBufferSpan textSpan)
 {
     ColorizeSpan(textSpan, classifications.MultilineText);
 }
        public virtual void Feature(string keyword, string name, string description, GherkinBufferSpan headerSpan, GherkinBufferSpan descriptionSpan)
        {
            CurrentFileBlockBuilder.SetMainData(typeof(IHeaderBlock), headerSpan.StartPosition.Line, keyword, name);

            ColorizeKeywordLine(keyword, headerSpan, classifications.FeatureTitle);
            ColorizeSpan(descriptionSpan, classifications.Description);
        }
Пример #31
0
        private GherkinBufferSpan ProcessComplexLanguageElement(int line, string description, out GherkinBufferSpan descriptionSpan)
        {
            var editorLine = GetEditorLine(line);
            var headerSpan = GetSingleLineSpanIgnoreWhitespace(editorLine);
            descriptionSpan = GetDescriptionSpan(editorLine, description);

            UpdateLastProcessedEditorLine(editorLine);
            if (descriptionSpan != null)
                UpdateLastProcessedEditorLine(descriptionSpan.EndPosition.Line);
            return headerSpan;
        }
Пример #32
0
        private GherkinBufferSpan[] GetCellSpans(int editorLine, string[] cells)
        {
            var cellSeparatorPositions = 
                GherkinBuffer.GetMatchesForLine(cellSeparatorRe, editorLine).ToArray();

            var result = new GherkinBufferSpan[cells.Length];
            for (int cellIndex = 0; cellIndex < cells.Length; cellIndex++)
            {
                if (cellSeparatorPositions.Length - 1 < cellIndex + 1)
                    break;

                result[cellIndex] = new GherkinBufferSpan(
                        cellSeparatorPositions[cellIndex].ShiftByCharacters(1),
                        cellSeparatorPositions[cellIndex + 1]);
            }

            return result;
        }
 private void ColorizeKeywordLine(string keyword, GherkinBufferSpan headerSpan, IClassificationType classificationType)
 {
     RegisterKeyword(keyword, headerSpan);
     //colorize the rest
     var textSpan = new GherkinBufferSpan(
         headerSpan.StartPosition.ShiftByCharacters(keyword.Length),
         headerSpan.EndPosition);
     ColorizeSpan(textSpan, classificationType);
 }
Пример #34
0
        private GherkinBufferSpan ProcessComplexLanguageElement(int line, string description, out GherkinBufferSpan descriptionSpan)
        {
            var editorLine = GetEditorLine(line);
            var headerSpan = GetSingleLineSpanIgnoreWhitespace(editorLine);

            descriptionSpan = GetDescriptionSpan(editorLine, description);

            UpdateLastProcessedEditorLine(editorLine);
            if (descriptionSpan != null)
            {
                UpdateLastProcessedEditorLine(descriptionSpan.EndPosition.Line);
            }
            return(headerSpan);
        }