示例#1
0
        private GherkinFileScopeChange PartialParse(GherkinTextBufferChange change, IGherkinFileScope previousScope)
        {
            _visualStudioTracer.Trace("Start incremental parsing", ParserTraceCategory);
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            _partialParseCount++;

            var textSnapshot = change.ResultTextSnapshot;

            var firstAffectedScenario = GetFirstAffectedScenario(change, previousScope);

            Asserter.Assert(firstAffectedScenario != null, "first affected scenario is null");
            int parseStartPosition = textSnapshot.GetLineFromLineNumber(firstAffectedScenario.GetStartLine()).Start;

            string fileContent = textSnapshot.GetText(parseStartPosition, textSnapshot.Length - parseStartPosition);

            var gherkinListener = new GherkinTextBufferPartialParserListener(
                previousScope.GherkinDialect,
                textSnapshot, _projectScope,
                previousScope,
                change.EndLine, change.LineCountDelta);

            var scanner = new GherkinScanner(previousScope.GherkinDialect, fileContent, firstAffectedScenario.GetStartLine());

            IScenarioBlock firstUnchangedScenario = null;

            try
            {
                scanner.Scan(gherkinListener);
            }
            catch (PartialListeningDoneException partialListeningDoneException)
            {
                firstUnchangedScenario = partialListeningDoneException.FirstUnchangedScenario;
            }

            var partialResult = gherkinListener.GetResult();

            var result = MergePartialResult(previousScope, partialResult, firstAffectedScenario, firstUnchangedScenario, change.LineCountDelta);

            stopwatch.Stop();
            TraceFinishParse(stopwatch, "incremental", result);
            return(result);
        }
示例#2
0
        public static GherkinTextBufferChange Merge(GherkinTextBufferChange change1, GherkinTextBufferChange change2)
        {
            Asserter.Assert(change1.ResultTextSnapshot.Version.VersionNumber <= change2.ResultTextSnapshot.Version.VersionNumber, "different snapshot version numbers for merging");
            if (change1.Type == GherkinTextBufferChangeType.EntireFile || change2.Type == GherkinTextBufferChangeType.EntireFile)
            {
                return(CreateEntireBufferChange(change2.ResultTextSnapshot));
            }

            return(new GherkinTextBufferChange(
                       change1.Type == GherkinTextBufferChangeType.MultiLine || change2.Type == GherkinTextBufferChangeType.MultiLine ? GherkinTextBufferChangeType.MultiLine : GherkinTextBufferChangeType.SingleLine,
                       Math.Min(change1.StartLine, change2.StartLine),
                       Math.Max(change1.EndLine, change2.EndLine),
                       Math.Min(change1.StartPosition, change2.StartPosition),
                       Math.Max(change1.EndPosition, change2.EndPosition),
                       change1.LineCountDelta + change2.LineCountDelta,
                       change1.PositionDelta + change2.PositionDelta,
                       change2.ResultTextSnapshot));
        }
 public ParsingTask(GherkinLanguageService languageService, GherkinTextBufferChange change)
 {
     this.languageService = languageService;
     this.change          = change;
 }