mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-29 11:01:57 +00:00
Also make lsVersionedTextDocumentIdentifier::version optional per specification
This commit is contained in:
parent
bfccac525c
commit
20c156f71d
@ -260,7 +260,7 @@ MAKE_REFLECT_STRUCT(lsTextDocumentIdentifier, uri);
|
||||
struct lsVersionedTextDocumentIdentifier {
|
||||
lsDocumentUri uri;
|
||||
// The version number of this document.
|
||||
int version = 0;
|
||||
optional<int> version;
|
||||
|
||||
lsTextDocumentIdentifier AsTextDocumentIdentifier() const;
|
||||
};
|
||||
@ -990,9 +990,9 @@ MAKE_REFLECT_STRUCT(lsMarkedString, language, value);
|
||||
|
||||
struct lsTextDocumentContentChangeEvent {
|
||||
// The range of the document that changed.
|
||||
lsRange range;
|
||||
optional<lsRange> range;
|
||||
// The length of the range that got replaced.
|
||||
int rangeLength = -1;
|
||||
optional<int> rangeLength;
|
||||
// The new text of the range/document.
|
||||
std::string text;
|
||||
};
|
||||
|
@ -324,28 +324,25 @@ void WorkingFiles::OnChange(const lsTextDocumentDidChangeParams& change) {
|
||||
return;
|
||||
}
|
||||
|
||||
file->version = change.textDocument.version;
|
||||
if (change.textDocument.version)
|
||||
file->version = *change.textDocument.version;
|
||||
|
||||
for (const lsTextDocumentContentChangeEvent& diff : change.contentChanges) {
|
||||
// Per the spec replace everything if the rangeLength and range are not set.
|
||||
// See https://github.com/Microsoft/language-server-protocol/issues/9.
|
||||
if (diff.rangeLength == -1 &&
|
||||
diff.range.start == lsPosition::kZeroPosition &&
|
||||
diff.range.end == lsPosition::kZeroPosition) {
|
||||
if (!diff.range) {
|
||||
file->buffer_content = diff.text;
|
||||
file->OnBufferContentUpdated();
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
diff.rangeLength
|
||||
? start_offset + *diff.rangeLength
|
||||
: GetOffsetForPosition(diff.range->end, file->buffer_content);
|
||||
file->buffer_content.replace(
|
||||
file->buffer_content.begin() + start_offset,
|
||||
file->buffer_content.begin() + start_offset + length, diff.text);
|
||||
file->buffer_content.begin() + end_offset, diff.text);
|
||||
file->OnBufferContentUpdated();
|
||||
}
|
||||
}
|
||||
|
@ -103,4 +103,4 @@ struct WorkingFiles {
|
||||
// invalidated if we resize files.
|
||||
std::vector<std::unique_ptr<WorkingFile>> files;
|
||||
std::mutex files_mutex; // Protects |files|.
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user