public void Update(DocumentChangeSet changes)
        {
            if (!changes.Changes.Any(c => c.WholeBuffer))
            {
                if (Version >= 0)
                {
                    if (changes.FromVersion < Version)
                    {
                        return;
                    }
                    else if (changes.FromVersion > Version)
                    {
                        throw new InvalidOperationException("missing prior versions");
                    }
                }
                if (changes.FromVersion >= changes.ToVersion)
                {
                    throw new InvalidOperationException("cannot reduce version without resetting buffer");
                }
            }

            int lastStart = int.MaxValue;
            var lineLoc   = SplitLines(Text).ToArray();

            foreach (var change in changes.Changes)
            {
                if (change.WholeBuffer)
                {
                    Text.Clear();
                    if (!string.IsNullOrEmpty(change.InsertedText))
                    {
                        Text.Append(change.InsertedText);
                    }
                    continue;
                }

                int start = NewLineLocation.LocationToIndex(lineLoc, change.ReplacedSpan.Start, Text.Length);
                if (start > lastStart)
                {
                    throw new InvalidOperationException("changes must be in reverse order of start location");
                }
                lastStart = start;

                int end = NewLineLocation.LocationToIndex(lineLoc, change.ReplacedSpan.End, Text.Length);
                if (end > start)
                {
                    Text.Remove(start, end - start);
                }
                if (!string.IsNullOrEmpty(change.InsertedText))
                {
                    Text.Insert(start, change.InsertedText);
                }
            }

            Version = changes.ToVersion;
        }
예제 #2
0
 public void UpdateDocument(int part, DocumentChangeSet changes)
 {
     lock (_buffers) {
         if (!_buffers.TryGetValue(part, out var buffer))
         {
             _buffers[part] = buffer = new DocumentBuffer();
         }
         buffer.Update(changes);
     }
 }
예제 #3
0
        public void UpdateDocument(int part, DocumentChangeSet changes)
        {
            lock (_buffers) {
                if (!_buffers.TryGetValue(part, out var buffer))
                {
                    _buffers[part] = buffer = new DocumentBuffer();
                }
                int versionBefore = buffer.Version;
                buffer.Update(changes);

                // Reset the current cookie if the version did not increase
                if (buffer.Version <= versionBefore)
                {
                    SetCurrentParse(Tree, null, false);
                }
            }
        }