Add support for the TextDocumentSyncKind LSP options

This commit is contained in:
Mikayla 2023-09-29 12:05:21 -07:00
parent c379a6f2fb
commit 4887ea3563
No known key found for this signature in database

View file

@ -2231,26 +2231,48 @@ impl Project {
.get_mut(&buffer.remote_id()) .get_mut(&buffer.remote_id())
.and_then(|m| m.get_mut(&language_server.server_id()))?; .and_then(|m| m.get_mut(&language_server.server_id()))?;
let previous_snapshot = buffer_snapshots.last()?; let previous_snapshot = buffer_snapshots.last()?;
let next_version = previous_snapshot.version + 1;
let content_changes = buffer let document_sync_kind = language_server
.edits_since::<(PointUtf16, usize)>(previous_snapshot.snapshot.version()) .capabilities()
.map(|edit| { .text_document_sync
let edit_start = edit.new.start.0; .as_ref()
let edit_end = edit_start + (edit.old.end.0 - edit.old.start.0); .and_then(|sync| match sync {
let new_text = next_snapshot lsp::TextDocumentSyncCapability::Kind(kind) => Some(*kind),
.text_for_range(edit.new.start.1..edit.new.end.1) lsp::TextDocumentSyncCapability::Options(options) => options.change,
.collect(); });
lsp::TextDocumentContentChangeEvent {
range: Some(lsp::Range::new( let content_changes: Vec<_> = match document_sync_kind {
point_to_lsp(edit_start), Some(lsp::TextDocumentSyncKind::FULL) => {
point_to_lsp(edit_end), vec![lsp::TextDocumentContentChangeEvent {
)), range: None,
range_length: None, range_length: None,
text: new_text, text: next_snapshot.text(),
} }]
}) }
.collect(); Some(lsp::TextDocumentSyncKind::INCREMENTAL) => buffer
.edits_since::<(PointUtf16, usize)>(
previous_snapshot.snapshot.version(),
)
.map(|edit| {
let edit_start = edit.new.start.0;
let edit_end = edit_start + (edit.old.end.0 - edit.old.start.0);
let new_text = next_snapshot
.text_for_range(edit.new.start.1..edit.new.end.1)
.collect();
lsp::TextDocumentContentChangeEvent {
range: Some(lsp::Range::new(
point_to_lsp(edit_start),
point_to_lsp(edit_end),
)),
range_length: None,
text: new_text,
}
})
.collect(),
_ => continue,
};
let next_version = previous_snapshot.version + 1;
buffer_snapshots.push(LspBufferSnapshot { buffer_snapshots.push(LspBufferSnapshot {
version: next_version, version: next_version,