Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
9 changes: 5 additions & 4 deletions src/Analysis/Ast/Impl/Documents/DocumentBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Python.Core.Diagnostics;
using Microsoft.Python.Parsing;

namespace Microsoft.Python.Analysis.Documents {
internal sealed class DocumentBuffer {
private readonly StringBuilder _sb = new StringBuilder();
private readonly int _ownerThreadId = Thread.CurrentThread.ManagedThreadId;
private string _cachedText;

public int Version { get; private set; }
public string Text => _sb.ToString();
public string Text => _cachedText ?? (_cachedText = _sb.ToString());

public void Reset(int version, string content) {
Version = version;
_sb.Clear();
if (!string.IsNullOrEmpty(content)) {
_sb.Append(content);
}
_cachedText = null;
}

public void Update(IEnumerable<DocumentChange> changes) {

Comment thread
AlexanderSher marked this conversation as resolved.
var lastStart = int.MaxValue;
var lineLoc = SplitLines(_sb).ToArray();

Expand All @@ -57,6 +57,7 @@ public void Update(IEnumerable<DocumentChange> changes) {
}
}
Version++;
_cachedText = null;
}

private static IEnumerable<NewLineLocation> SplitLines(StringBuilder text) {
Expand Down