mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 17:44:30 +00:00
Add support for the TextDocumentSyncKind LSP option (#3070)
fixes https://github.com/zed-industries/community/issues/2098 Release Notes: - Fixed a bug in Zed's LSP implementation when using Next LS.
This commit is contained in:
parent
348145afdf
commit
b70b856c7d
1 changed files with 53 additions and 17 deletions
|
@ -2231,26 +2231,62 @@ 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 build_incremental_change = || {
|
||||||
.edits_since::<(PointUtf16, usize)>(previous_snapshot.snapshot.version())
|
buffer
|
||||||
.map(|edit| {
|
.edits_since::<(PointUtf16, usize)>(
|
||||||
let edit_start = edit.new.start.0;
|
previous_snapshot.snapshot.version(),
|
||||||
let edit_end = edit_start + (edit.old.end.0 - edit.old.start.0);
|
)
|
||||||
let new_text = next_snapshot
|
.map(|edit| {
|
||||||
.text_for_range(edit.new.start.1..edit.new.end.1)
|
let edit_start = edit.new.start.0;
|
||||||
.collect();
|
let edit_end = edit_start + (edit.old.end.0 - edit.old.start.0);
|
||||||
lsp::TextDocumentContentChangeEvent {
|
let new_text = next_snapshot
|
||||||
range: Some(lsp::Range::new(
|
.text_for_range(edit.new.start.1..edit.new.end.1)
|
||||||
point_to_lsp(edit_start),
|
.collect();
|
||||||
point_to_lsp(edit_end),
|
lsp::TextDocumentContentChangeEvent {
|
||||||
)),
|
range: Some(lsp::Range::new(
|
||||||
|
point_to_lsp(edit_start),
|
||||||
|
point_to_lsp(edit_end),
|
||||||
|
)),
|
||||||
|
range_length: None,
|
||||||
|
text: new_text,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
};
|
||||||
|
|
||||||
|
let document_sync_kind = language_server
|
||||||
|
.capabilities()
|
||||||
|
.text_document_sync
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|sync| match sync {
|
||||||
|
lsp::TextDocumentSyncCapability::Kind(kind) => Some(*kind),
|
||||||
|
lsp::TextDocumentSyncCapability::Options(options) => options.change,
|
||||||
|
});
|
||||||
|
|
||||||
|
let content_changes: Vec<_> = match document_sync_kind {
|
||||||
|
Some(lsp::TextDocumentSyncKind::FULL) => {
|
||||||
|
vec![lsp::TextDocumentContentChangeEvent {
|
||||||
|
range: None,
|
||||||
range_length: None,
|
range_length: None,
|
||||||
text: new_text,
|
text: next_snapshot.text(),
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
Some(lsp::TextDocumentSyncKind::INCREMENTAL) => build_incremental_change(),
|
||||||
|
_ => {
|
||||||
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
|
{
|
||||||
|
build_incremental_change()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.collect();
|
#[cfg(not(any(test, feature = "test-support")))]
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let next_version = previous_snapshot.version + 1;
|
||||||
|
|
||||||
buffer_snapshots.push(LspBufferSnapshot {
|
buffer_snapshots.push(LspBufferSnapshot {
|
||||||
version: next_version,
|
version: next_version,
|
||||||
|
|
Loading…
Reference in a new issue