예제 #1
0
        public static TextChangeRange GetEncompassingTextChangeRange(this SourceText newText, SourceText oldText)
        {
            var ranges = newText.GetChangeRanges(oldText);

            if (ranges.Count == 0)
            {
                return(default);
        /// <summary>
        /// Gets the minimal range of text that changed between the two versions.
        /// </summary>
        public static TextChangeRange GetEncompassingTextChangeRange(this SourceText newText, SourceText oldText)
        {
            if (newText is null)
            {
                throw new ArgumentNullException(nameof(newText));
            }

            if (oldText is null)
            {
                throw new ArgumentNullException(nameof(oldText));
            }

            var ranges = newText.GetChangeRanges(oldText);

            if (ranges.Count == 0)
            {
                return(default);
예제 #3
0
        /// <summary>
        /// Creates a new syntax based off this tree using a new source text.
        /// </summary>
        /// <remarks>
        /// If the new source text is a minor change from the current source text an incremental parse will occur
        /// reusing most of the current syntax tree internal data.  Otherwise, a full parse will occur using the new
        /// source text.
        /// </remarks>
        public override SyntaxTree WithChangedText(SourceText newText)
        {
            // try to find the changes between the old text and the new text.
            SourceText oldText;

            if (this.TryGetText(out oldText))
            {
                var changes = newText.GetChangeRanges(oldText);
                if (changes.Count == 0 && newText == oldText)
                {
                    return(this);
                }
                return(this.WithChanges(newText, changes));
            }
            // if we do not easily know the old text, then specify entire text as changed so we do a full reparse.
            return(this.WithChanges(newText, new[] { new TextChangeRange(new TextSpan(0, this.Length), newText.Length) }));
        }
예제 #4
0
        /// <summary>
        /// Creates a new syntax based off this tree using a new source text.
        /// </summary>
        /// <remarks>
        /// If the new source text is a minor change from the current source text an incremental parse will occur
        /// reusing most of the current syntax tree internal data.  Otherwise, a full parse will occur using the new
        /// source text.
        /// </remarks>
        public override SyntaxTree WithChangedText(SourceText newText)
        {
            using (Logger.LogBlock(FunctionId.CSharp_SyntaxTree_IncrementalParse, message: this.FilePath))
            {
                // try to find the changes between the old text and the new text.
                SourceText oldText;
                if (this.TryGetText(out oldText))
                {
                    var changes = newText.GetChangeRanges(oldText);

                    if (changes.Count == 0 && newText == oldText)
                    {
                        return(this);
                    }

                    return(this.WithChanges(newText, changes));
                }

                // if we do not easily know the old text, then specify entire text as changed so we do a full reparse.
                return(this.WithChanges(newText, new[] { new TextChangeRange(new TextSpan(0, this.Length), newText.Length) }));
            }
        }
        public async Task <IEnumerable <ClassifiedSpan> > GetChangedClassifiedSpansAsync()
        {
            if (documentStack.Count >= 2)
            {
                Document[] documents = documentStack.ToArray();

                Document newDocument = documents[0];
                Document oldDocument = documents[1];

                SourceText newText = await newDocument.GetTextAsync();

                var newClassifiedSpans = await Classifier.GetClassifiedSpansAsync(newDocument, new TextSpan(0, newText.Length));

                SourceText oldText = await oldDocument.GetTextAsync();

                var oldClassifiedSpans = await Classifier.GetClassifiedSpansAsync(oldDocument, new TextSpan(0, oldText.Length));

                var textChanges = newText.GetChangeRanges(oldText);

                return(GetChangedClassifiedSpans(textChanges.FirstOrDefault(), oldClassifiedSpans, newClassifiedSpans));
            }

            return(await GetClassifiedSpansAsync());
        }
예제 #6
0
 public override IReadOnlyList <TextChangeRange> GetChangeRanges(SourceText oldText)
 => _sourceText.GetChangeRanges(oldText);