private DeveroomTag CreateDefinitionBlockTag(IHasDescription astNode, string tagType, ITextSnapshot fileSnapshot, int lastLine, DeveroomTag parentTag = null)
        {
            var span     = GetBlockSpan(fileSnapshot, ((IHasLocation)astNode).Location, lastLine);
            var blockTag = new DeveroomTag(tagType, span, astNode);

            parentTag?.AddChild(blockTag);
            blockTag.AddChild(CreateDefinitionLineKeyword(fileSnapshot, astNode));
            if (astNode is IHasTags hasTags)
            {
                foreach (var gherkinTag in hasTags.Tags)
                {
                    blockTag.AddChild(
                        new DeveroomTag(DeveroomTagTypes.Tag,
                                        GetTextSpan(fileSnapshot, gherkinTag.Location, gherkinTag.Name),
                                        gherkinTag));
                }
            }

            if (!string.IsNullOrEmpty(astNode.Description))
            {
                var startLineNumber = ((IHasLocation)astNode).Location.Line + 1;
                while (string.IsNullOrWhiteSpace(fileSnapshot.GetLineFromLineNumber(GetSnapshotLineNumber(startLineNumber, fileSnapshot)).GetText()))
                {
                    startLineNumber++;
                }
                blockTag.AddChild(
                    new DeveroomTag(DeveroomTagTypes.Description,
                                    GetBlockSpan(fileSnapshot, startLineNumber,
                                                 CountLines(astNode.Description))));
            }

            return(blockTag);
        }
 private void TagRowCells(ITextSnapshot fileSnapshot, TableRow row, DeveroomTag parentTag, string tagType)
 {
     foreach (var cell in row.Cells)
     {
         parentTag.AddChild(new DeveroomTag(tagType,
                                            GetSpan(fileSnapshot, cell.Location, cell.Value.Length),
                                            cell));
     }
 }
        private void AddPlaceholderTags(ITextSnapshot fileSnapshot, DeveroomTag stepTag, Step step)
        {
            var placeholders = MatchedScenarioOutlinePlaceholder.MatchScenarioOutlinePlaceholders(step);

            foreach (var placeholder in placeholders)
            {
                stepTag.AddChild(new DeveroomTag(DeveroomTagTypes.ScenarioOutlinePlaceholder,
                                                 GetSpan(fileSnapshot, step.Location, placeholder.Length, offset: step.Keyword.Length + placeholder.Index),
                                                 placeholder));
            }
        }
        private IEnumerable <DeveroomTag> GetAllTags(DeveroomTag tag)
        {
            yield return(tag);

            foreach (var childTag in tag.ChildTags)
            {
                foreach (var allChildTag in GetAllTags(childTag))
                {
                    yield return(allChildTag);
                }
            }
        }
        private void AddGherkinDocumentTags(ITextSnapshot fileSnapshot, ProjectBindingRegistry bindingRegistry,
                                            DeveroomGherkinDocument gherkinDocument, List <DeveroomTag> result)
        {
            var documentTag = new DeveroomTag(DeveroomTagTypes.Document, new SnapshotSpan(fileSnapshot, 0, fileSnapshot.Length), gherkinDocument);

            result.Add(documentTag);

            if (gherkinDocument.Feature != null)
            {
                var featureTag = GetFeatureTags(fileSnapshot, bindingRegistry, gherkinDocument.Feature);
                result.AddRange(GetAllTags(featureTag));
            }

            if (gherkinDocument.Comments != null)
            {
                foreach (var comment in gherkinDocument.Comments)
                {
                    result.Add(new DeveroomTag(DeveroomTagTypes.Comment,
                                               GetTextSpan(fileSnapshot, comment.Location, comment.Text)));
                }
            }
        }
 private void AddParameterTags(ITextSnapshot fileSnapshot, ParameterMatch parameterMatch, DeveroomTag stepTag, Step step)
 {
     foreach (var parameter in parameterMatch.StepTextParameters)
     {
         stepTag.AddChild(new DeveroomTag(DeveroomTagTypes.StepParameter,
                                          GetSpan(fileSnapshot, step.Location, parameter.Length, offset: step.Keyword.Length + parameter.Index),
                                          parameter));
     }
 }
        private DeveroomTag GetFeatureTags(ITextSnapshot fileSnapshot, ProjectBindingRegistry bindingRegistry, Feature feature)
        {
            var featureTag = CreateDefinitionBlockTag(feature, DeveroomTagTypes.FeatureBlock, fileSnapshot,
                                                      fileSnapshot.LineCount);

            foreach (var scenarioDefinition in feature.StepsContainers())
            {
                var scenarioDefinitionTag = CreateDefinitionBlockTag(scenarioDefinition,
                                                                     DeveroomTagTypes.ScenarioDefinitionBlock, fileSnapshot,
                                                                     GetScenarioDefinitionLastLine(scenarioDefinition), featureTag);

                foreach (var step in scenarioDefinition.Steps)
                {
                    var stepTag = scenarioDefinitionTag.AddChild(new DeveroomTag(DeveroomTagTypes.StepBlock,
                                                                                 GetBlockSpan(fileSnapshot, step.Location, GetStepLastLine(step)), step));

                    stepTag.AddChild(
                        new DeveroomTag(DeveroomTagTypes.StepKeyword,
                                        GetTextSpan(fileSnapshot, step.Location, step.Keyword),
                                        step.Keyword));

                    if (step.Argument is DataTable dataTable)
                    {
                        var dataTableBlockTag = new DeveroomTag(DeveroomTagTypes.DataTable,
                                                                GetBlockSpan(fileSnapshot, dataTable.Rows.First().Location,
                                                                             dataTable.Rows.Last().Location.Line),
                                                                dataTable);
                        stepTag.AddChild(dataTableBlockTag);
                        var dataTableHeader = dataTable.Rows.FirstOrDefault();
                        if (dataTableHeader != null)
                        {
                            TagRowCells(fileSnapshot, dataTableHeader, dataTableBlockTag, DeveroomTagTypes.DataTableHeader);
                        }
                    }
                    else if (step.Argument is DocString docString)
                    {
                        stepTag.AddChild(
                            new DeveroomTag(DeveroomTagTypes.DocString,
                                            GetBlockSpan(fileSnapshot, docString.Location,
                                                         GetStepLastLine(step)),
                                            docString));
                    }

                    if (scenarioDefinition is ScenarioOutline)
                    {
                        AddPlaceholderTags(fileSnapshot, stepTag, step);
                    }

                    var match = bindingRegistry?.MatchStep(step, scenarioDefinitionTag);
                    if (match != null)
                    {
                        if (match.HasDefined || match.HasAmbiguous)
                        {
                            stepTag.AddChild(new DeveroomTag(DeveroomTagTypes.DefinedStep,
                                                             GetTextSpan(fileSnapshot, step.Location, step.Text, offset: step.Keyword.Length),
                                                             match));
                            if (!(scenarioDefinition is ScenarioOutline) || !step.Text.Contains("<"))
                            {
                                var parameterMatch = match.Items.FirstOrDefault(m => m.ParameterMatch != null)
                                                     ?.ParameterMatch;
                                AddParameterTags(fileSnapshot, parameterMatch, stepTag, step);
                            }
                        }

                        if (match.HasUndefined)
                        {
                            stepTag.AddChild(new DeveroomTag(DeveroomTagTypes.UndefinedStep,
                                                             GetTextSpan(fileSnapshot, step.Location, step.Text, offset: step.Keyword.Length),
                                                             match));
                        }

                        if (match.HasErrors)
                        {
                            stepTag.AddChild(new DeveroomTag(DeveroomTagTypes.BindingError,
                                                             GetTextSpan(fileSnapshot, step.Location, step.Text, offset: step.Keyword.Length),
                                                             match.GetErrorMessage()));
                        }
                    }
                }

                if (scenarioDefinition is ScenarioOutline scenarioOutline)
                {
                    foreach (var scenarioOutlineExample in scenarioOutline.Examples)
                    {
                        var examplesBlockTag = CreateDefinitionBlockTag(scenarioOutlineExample,
                                                                        DeveroomTagTypes.ExamplesBlock, fileSnapshot,
                                                                        GetExamplesLastLine(scenarioOutlineExample), scenarioDefinitionTag);
                        if (scenarioOutlineExample.TableHeader != null)
                        {
                            TagRowCells(fileSnapshot, scenarioOutlineExample.TableHeader, examplesBlockTag, DeveroomTagTypes.ScenarioOutlinePlaceholder);
                        }
                    }
                }
            }

            return(featureTag);
        }
Пример #8
0
 internal DeveroomTag AddChild(DeveroomTag childTag)
 {
     childTag.ParentTag = this;
     _childTags.Add(childTag);
     return(childTag);
 }
Пример #9
0
        private void AddRuleBlockTag(ITextSnapshot fileSnapshot, ProjectBindingRegistry bindingRegistry, Rule rule, DeveroomTag featureTag)
        {
            var lastStepsContainer = rule.StepsContainers().LastOrDefault();
            var lastLine           = lastStepsContainer != null?
                                     GetScenarioDefinitionLastLine(lastStepsContainer) :
                                         rule.Location.Line;

            var ruleTag = CreateDefinitionBlockTag(rule,
                                                   DeveroomTagTypes.RuleBlock, fileSnapshot,
                                                   lastLine, featureTag);

            foreach (var stepsContainer in rule.StepsContainers())
            {
                AddScenarioDefinitionBlockTag(fileSnapshot, bindingRegistry, stepsContainer, ruleTag);
            }
        }