private ICollection <DeveroomTag> ParseInternal(ITextSnapshot fileSnapshot, ProjectBindingRegistry bindingRegistry, DeveroomConfiguration deveroomConfiguration)
        {
            var dialectProvider = SpecFlowGherkinDialectProvider.Get(deveroomConfiguration.DefaultFeatureLanguage);
            var parser          = new DeveroomGherkinParser(dialectProvider, _monitoringService);

            parser.ParseAndCollectErrors(fileSnapshot.GetText(), _logger,
                                         out var gherkinDocument, out var parserErrors);

            var result = new List <DeveroomTag>();

            if (gherkinDocument != null)
            {
                AddGherkinDocumentTags(fileSnapshot, bindingRegistry, gherkinDocument, result);
            }

            foreach (var parserException in parserErrors)
            {
                var line       = GetSnapshotLine(parserException.Location, fileSnapshot);
                var startPoint = GetColumnPoint(line, parserException.Location);
                var span       = new SnapshotSpan(startPoint, line.End);

                result.Add(new DeveroomTag(DeveroomTagTypes.ParserError,
                                           span, parserException.Message));
            }

            return(result);
        }
        public void Should_provide_parse_result_when_unexpected_end_of_file()
        {
            var sut = new DeveroomGherkinParser(new SpecFlowGherkinDialectProvider("en-US"),
                                                new Mock <IMonitoringService>().Object);

            var result = sut.ParseAndCollectErrors(@"
Feature: Addition
@tag
",
                                                   new DeveroomNullLogger(), out var gherkinDocument, out var errors);

            gherkinDocument.Should().NotBeNull();
            result.Should().BeFalse();
        }
        public void Should_provide_parse_result_when_file_ends_with_open_docstring()
        {
            var sut = new DeveroomGherkinParser(new SpecFlowGherkinDialectProvider("en-US"),
                                                new Mock <IMonitoringService>().Object);

            var result = sut.ParseAndCollectErrors(@"
Feature: Addition
Scenario: Add two numbers
  Given I have added
    ```
",
                                                   new DeveroomNullLogger(), out var gherkinDocument, out var errors);

            gherkinDocument.Should().NotBeNull();
            result.Should().BeFalse();
        }
        public void Should_tolerate_unfinished_DataTable()
        {
            var sut = new DeveroomGherkinParser(new SpecFlowGherkinDialectProvider("en-US"),
                                                new Mock <IMonitoringService>().Object);

            var result = sut.ParseAndCollectErrors(@"
Feature: Addition
Scenario: Add two numbers
	When I press
		| foo |
		| bar
",
                                                   new DeveroomNullLogger(), out var gherkinDocument, out var errors);

            gherkinDocument.Should().NotBeNull();
            result.Should().BeFalse();
        }
        public IEnumerable <StepDefinitionUsage> FindUsagesFromContent(ProjectStepDefinitionBinding[] stepDefinitions,
                                                                       string featureFileContent, string featureFilePath, DeveroomConfiguration configuration)
        {
            var dialectProvider = SpecFlowGherkinDialectProvider.Get(configuration.DefaultFeatureLanguage);
            var parser          = new DeveroomGherkinParser(dialectProvider, _monitoringService);

            parser.ParseAndCollectErrors(featureFileContent, _logger,
                                         out var gherkinDocument, out _);

            var featureNode = gherkinDocument?.Feature;

            if (featureNode == null)
            {
                yield break;
            }

            var dummyRegistry = new ProjectBindingRegistry
            {
                StepDefinitions = stepDefinitions
            };

            var featureContext = new UsageFinderContext(featureNode);

            foreach (var scenarioDefinition in featureNode.FlattenStepsContainers())
            {
                var context = new UsageFinderContext(scenarioDefinition, featureContext);
                foreach (var step in scenarioDefinition.Steps)
                {
                    var matchResult = dummyRegistry.MatchStep(step, context);
                    if (matchResult == null)
                    {
                        continue; // this will not happen
                    }
                    if (matchResult.HasDefined)
                    {
                        yield return(new StepDefinitionUsage(
                                         GetSourceLocation(step, featureFilePath), step));
                    }
                }
            }
        }