mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[SourceKit] Dedicated error message for 'offset' + 'length' out of range
This commit is contained in:
@@ -194,36 +194,6 @@ getMemBufferFromRope(StringRef Filename, const RewriteRope &Rope) {
|
||||
return std::move(MemBuf);
|
||||
}
|
||||
|
||||
size_t
|
||||
EditableTextBuffer::getSizeForSnapshot(const ImmutableTextSnapshot &Snap) {
|
||||
if (auto Buf = dyn_cast<ImmutableTextBuffer>(Snap.DiffEnd))
|
||||
return Buf->getText().size();
|
||||
ImmutableTextUpdateRef Next = Snap.DiffEnd->Next;
|
||||
// FIXME: dyn_cast_null does not work with IntrusiveRefCntPtr.
|
||||
if (Next)
|
||||
if (auto Buf = dyn_cast<ImmutableTextBuffer>(Next))
|
||||
return Buf->getText().size();
|
||||
|
||||
ImmutableTextBufferRef StartBuf = Snap.BufferStart;
|
||||
|
||||
// Find the last ImmutableTextBuffer.
|
||||
ImmutableTextUpdateRef Upd = StartBuf;
|
||||
while (Upd != Snap.DiffEnd) {
|
||||
Upd = Upd->Next;
|
||||
if (auto Buf = dyn_cast<ImmutableTextBuffer>(Upd))
|
||||
StartBuf = Buf;
|
||||
}
|
||||
|
||||
size_t Length = StartBuf->getText().size();
|
||||
Upd = StartBuf;
|
||||
while (Upd != Snap.DiffEnd) {
|
||||
Upd = Upd->Next;
|
||||
auto Edit = cast<ReplaceImmutableTextUpdate>(Upd);
|
||||
Length = Length - Edit->getLength() + Edit->getText().size();
|
||||
}
|
||||
return Length;
|
||||
}
|
||||
|
||||
ImmutableTextBufferRef EditableTextBuffer::getBufferForSnapshot(
|
||||
const ImmutableTextSnapshot &Snap) {
|
||||
if (auto Buf = dyn_cast<ImmutableTextBuffer>(Snap.DiffEnd))
|
||||
@@ -273,6 +243,36 @@ ImmutableTextBufferRef EditableTextBuffer::getBufferForSnapshot(
|
||||
return ImmBuf;
|
||||
}
|
||||
|
||||
size_t EditableTextBuffer::getSizeForSnapshot(
|
||||
const ImmutableTextSnapshot &Snap) const {
|
||||
if (auto Buf = dyn_cast<ImmutableTextBuffer>(Snap.DiffEnd))
|
||||
return Buf->getText().size();
|
||||
ImmutableTextUpdateRef Next = Snap.DiffEnd->Next;
|
||||
// FIXME: dyn_cast_null does not work with IntrusiveRefCntPtr.
|
||||
if (Next)
|
||||
if (auto Buf = dyn_cast<ImmutableTextBuffer>(Next))
|
||||
return Buf->getText().size();
|
||||
|
||||
ImmutableTextBufferRef StartBuf = Snap.BufferStart;
|
||||
|
||||
// Find the last ImmutableTextBuffer.
|
||||
ImmutableTextUpdateRef Upd = StartBuf;
|
||||
while (Upd != Snap.DiffEnd) {
|
||||
Upd = Upd->Next;
|
||||
if (auto Buf = dyn_cast<ImmutableTextBuffer>(Upd))
|
||||
StartBuf = Buf;
|
||||
}
|
||||
|
||||
size_t Length = StartBuf->getText().size();
|
||||
Upd = StartBuf;
|
||||
while (Upd != Snap.DiffEnd) {
|
||||
Upd = Upd->Next;
|
||||
auto Edit = cast<ReplaceImmutableTextUpdate>(Upd);
|
||||
Length = Length - Edit->getLength() + Edit->getText().size();
|
||||
}
|
||||
return Length;
|
||||
}
|
||||
|
||||
// This should always be called under the mutex lock.
|
||||
void EditableTextBuffer::refresh() {
|
||||
while (CurrUpd->Next) {
|
||||
|
||||
Reference in New Issue
Block a user