mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-04 07:29:32 +00:00
Do not send textDocument/didSave
message if server does not declare its support (#14412)
Release Notes: - Improved Zed logic for sending `textDocument/didSave` request ([14286](https://github.com/zed-industries/zed/issues/14286))
This commit is contained in:
parent
88c5eb550e
commit
f8b5e42070
3 changed files with 52 additions and 23 deletions
|
@ -658,6 +658,10 @@ impl LanguageServer {
|
||||||
}),
|
}),
|
||||||
..SignatureHelpClientCapabilities::default()
|
..SignatureHelpClientCapabilities::default()
|
||||||
}),
|
}),
|
||||||
|
synchronization: Some(TextDocumentSyncClientCapabilities {
|
||||||
|
did_save: Some(true),
|
||||||
|
..TextDocumentSyncClientCapabilities::default()
|
||||||
|
}),
|
||||||
..TextDocumentClientCapabilities::default()
|
..TextDocumentClientCapabilities::default()
|
||||||
}),
|
}),
|
||||||
experimental: Some(json!({
|
experimental: Some(json!({
|
||||||
|
|
|
@ -2547,7 +2547,12 @@ impl Project {
|
||||||
};
|
};
|
||||||
|
|
||||||
for (_, _, server) in self.language_servers_for_worktree(worktree_id) {
|
for (_, _, server) in self.language_servers_for_worktree(worktree_id) {
|
||||||
let text = include_text(server.as_ref()).then(|| buffer.read(cx).text());
|
if let Some(include_text) = include_text(server.as_ref()) {
|
||||||
|
let text = if include_text {
|
||||||
|
Some(buffer.read(cx).text())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
server
|
server
|
||||||
.notify::<lsp::notification::DidSaveTextDocument>(
|
.notify::<lsp::notification::DidSaveTextDocument>(
|
||||||
lsp::DidSaveTextDocumentParams {
|
lsp::DidSaveTextDocumentParams {
|
||||||
|
@ -2557,6 +2562,7 @@ impl Project {
|
||||||
)
|
)
|
||||||
.log_err();
|
.log_err();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for language_server_id in self.language_server_ids_for_buffer(buffer.read(cx), cx) {
|
for language_server_id in self.language_server_ids_for_buffer(buffer.read(cx), cx) {
|
||||||
self.simulate_disk_based_diagnostics_events_if_needed(language_server_id, cx);
|
self.simulate_disk_based_diagnostics_events_if_needed(language_server_id, cx);
|
||||||
|
@ -11179,20 +11185,27 @@ impl Completion {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn include_text(server: &lsp::LanguageServer) -> bool {
|
fn include_text(server: &lsp::LanguageServer) -> Option<bool> {
|
||||||
server
|
match server.capabilities().text_document_sync.as_ref()? {
|
||||||
.capabilities()
|
lsp::TextDocumentSyncCapability::Kind(kind) => match kind {
|
||||||
.text_document_sync
|
&lsp::TextDocumentSyncKind::NONE => None,
|
||||||
.as_ref()
|
&lsp::TextDocumentSyncKind::FULL => Some(true),
|
||||||
.and_then(|sync| match sync {
|
&lsp::TextDocumentSyncKind::INCREMENTAL => Some(false),
|
||||||
lsp::TextDocumentSyncCapability::Kind(_) => None,
|
_ => None,
|
||||||
lsp::TextDocumentSyncCapability::Options(options) => options.save.as_ref(),
|
},
|
||||||
})
|
lsp::TextDocumentSyncCapability::Options(options) => match options.save.as_ref()? {
|
||||||
.and_then(|save_options| match save_options {
|
lsp::TextDocumentSyncSaveOptions::Supported(supported) => {
|
||||||
lsp::TextDocumentSyncSaveOptions::Supported(_) => None,
|
if *supported {
|
||||||
lsp::TextDocumentSyncSaveOptions::SaveOptions(options) => options.include_text,
|
Some(true)
|
||||||
})
|
} else {
|
||||||
.unwrap_or(false)
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lsp::TextDocumentSyncSaveOptions::SaveOptions(save_options) => {
|
||||||
|
Some(save_options.include_text.unwrap_or(false))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn load_direnv_environment(dir: &Path) -> Result<Option<HashMap<String, String>>> {
|
async fn load_direnv_environment(dir: &Path) -> Result<Option<HashMap<String, String>>> {
|
||||||
|
|
|
@ -322,6 +322,12 @@ async fn test_managing_language_servers(cx: &mut gpui::TestAppContext) {
|
||||||
trigger_characters: Some(vec![".".to_string(), "::".to_string()]),
|
trigger_characters: Some(vec![".".to_string(), "::".to_string()]),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
text_document_sync: Some(lsp::TextDocumentSyncCapability::Options(
|
||||||
|
lsp::TextDocumentSyncOptions {
|
||||||
|
save: Some(lsp::TextDocumentSyncSaveOptions::Supported(true)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -336,6 +342,12 @@ async fn test_managing_language_servers(cx: &mut gpui::TestAppContext) {
|
||||||
trigger_characters: Some(vec![":".to_string()]),
|
trigger_characters: Some(vec![":".to_string()]),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
text_document_sync: Some(lsp::TextDocumentSyncCapability::Options(
|
||||||
|
lsp::TextDocumentSyncOptions {
|
||||||
|
save: Some(lsp::TextDocumentSyncSaveOptions::Supported(true)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
Loading…
Reference in a new issue