mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 15:45:08 +00:00
Only replace text if both rangeLength and range are not set
This commit is contained in:
parent
31d7423490
commit
3341b1f13d
@ -327,20 +327,27 @@ void WorkingFiles::OnChange(const Ipc_TextDocumentDidChange::Params& change) {
|
|||||||
for (const Ipc_TextDocumentDidChange::lsTextDocumentContentChangeEvent& diff :
|
for (const Ipc_TextDocumentDidChange::lsTextDocumentContentChangeEvent& diff :
|
||||||
change.contentChanges) {
|
change.contentChanges) {
|
||||||
// std::cerr << "|" << file->buffer_content << "|" << std::endl;
|
// std::cerr << "|" << file->buffer_content << "|" << std::endl;
|
||||||
// If range or rangeLength are emitted we replace everything, per the spec.
|
// Per the spec replace everything if the rangeLength and range are not set.
|
||||||
if (diff.rangeLength == -1) {
|
// See https://github.com/Microsoft/language-server-protocol/issues/9.
|
||||||
|
auto zeroPosition = lsPosition(0, 0);
|
||||||
|
if (diff.rangeLength == -1 && diff.range.start == zeroPosition
|
||||||
|
&& diff.range.end == zeroPosition) {
|
||||||
file->buffer_content = diff.text;
|
file->buffer_content = diff.text;
|
||||||
file->OnBufferContentUpdated();
|
file->OnBufferContentUpdated();
|
||||||
// std::cerr << "-> Replacing entire content";
|
// std::cerr << "-> Replacing entire content";
|
||||||
} else {
|
} else {
|
||||||
int start_offset =
|
int start_offset = GetOffsetForPosition(diff.range.start, file->buffer_content);
|
||||||
GetOffsetForPosition(diff.range.start, file->buffer_content);
|
int end_offset = GetOffsetForPosition(diff.range.end, file->buffer_content);
|
||||||
|
int length = diff.rangeLength;
|
||||||
|
if (length == -1) {
|
||||||
|
length = end_offset - start_offset;
|
||||||
|
}
|
||||||
// std::cerr << "-> Applying diff start=" << diff.range.start.ToString()
|
// std::cerr << "-> Applying diff start=" << diff.range.start.ToString()
|
||||||
// << ", end=" << diff.range.end.ToString() << ", start_offset=" <<
|
// << ", end=" << diff.range.end.ToString() << ", start_offset=" <<
|
||||||
// start_offset << std::endl;
|
// start_offset << std::endl;
|
||||||
file->buffer_content.replace(
|
file->buffer_content.replace(
|
||||||
file->buffer_content.begin() + start_offset,
|
file->buffer_content.begin() + start_offset,
|
||||||
file->buffer_content.begin() + start_offset + diff.rangeLength,
|
file->buffer_content.begin() + start_offset + length,
|
||||||
diff.text);
|
diff.text);
|
||||||
file->OnBufferContentUpdated();
|
file->OnBufferContentUpdated();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user