Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit d6260fe

Browse files
author
MikhailArkhipov
committed
Add lock
1 parent 4108948 commit d6260fe

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

src/Analysis/Ast/Impl/Documents/DocumentBuffer.cs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,34 @@ public void Update(IEnumerable<DocumentChange> changes) {
7373
}
7474

7575
public IEnumerable<NewLineLocation> GetNewLineLocations() {
76-
_sb = _sb ?? new StringBuilder(_content); // for tests
76+
lock (_lock) {
77+
_sb = _sb ?? new StringBuilder(_content); // for tests
7778

78-
if (_sb.Length == 0) {
79-
yield return new NewLineLocation(0, NewLineKind.None);
80-
}
79+
if (_sb.Length == 0) {
80+
yield return new NewLineLocation(0, NewLineKind.None);
81+
}
8182

82-
for (var i = 0; i < _sb.Length; i++) {
83-
var ch = _sb[i];
84-
var nextCh = i < _sb.Length - 1 ? _sb[i + 1] : '\0';
85-
switch (ch) {
86-
case '\r' when nextCh == '\n':
87-
i++;
88-
yield return new NewLineLocation(i + 1, NewLineKind.CarriageReturnLineFeed);
89-
break;
90-
case '\n':
91-
yield return new NewLineLocation(i + 1, NewLineKind.LineFeed);
92-
break;
93-
case '\r':
94-
yield return new NewLineLocation(i + 1, NewLineKind.CarriageReturn);
95-
break;
96-
default:
97-
if (i == _sb.Length - 1) {
98-
yield return new NewLineLocation(i + 1, NewLineKind.None);
99-
}
100-
break;
83+
for (var i = 0; i < _sb.Length; i++) {
84+
var ch = _sb[i];
85+
var nextCh = i < _sb.Length - 1 ? _sb[i + 1] : '\0';
86+
switch (ch) {
87+
case '\r' when nextCh == '\n':
88+
i++;
89+
yield return new NewLineLocation(i + 1, NewLineKind.CarriageReturnLineFeed);
90+
break;
91+
case '\n':
92+
yield return new NewLineLocation(i + 1, NewLineKind.LineFeed);
93+
break;
94+
case '\r':
95+
yield return new NewLineLocation(i + 1, NewLineKind.CarriageReturn);
96+
break;
97+
default:
98+
if (i == _sb.Length - 1) {
99+
yield return new NewLineLocation(i + 1, NewLineKind.None);
100+
}
101+
102+
break;
103+
}
101104
}
102105
}
103106
}

0 commit comments

Comments
 (0)