mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 17:36:19 +04:00
ls: Refactor textDocument/didSave in a similar vein
This commit is contained in:
parent
184637c55a
commit
800d79b584
@ -490,11 +490,11 @@ pub fn text_document_did_close(
|
||||
|
||||
// will_save / will_save_wait_until
|
||||
|
||||
pub async fn text_document_did_save(
|
||||
pub fn text_document_did_save(
|
||||
&self,
|
||||
text_document: lsp::TextDocumentIdentifier,
|
||||
text: &Rope,
|
||||
) -> Result<()> {
|
||||
) -> Option<impl Future<Output = Result<()>>> {
|
||||
let capabilities = self.capabilities.get().unwrap();
|
||||
|
||||
let include_text = match &capabilities.text_document_sync {
|
||||
@ -507,17 +507,18 @@ pub async fn text_document_did_save(
|
||||
include_text,
|
||||
}) => include_text.unwrap_or(false),
|
||||
// Supported(false)
|
||||
_ => return Ok(()),
|
||||
_ => return None,
|
||||
},
|
||||
// unsupported
|
||||
_ => return Ok(()),
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
self.notify::<lsp::notification::DidSaveTextDocument>(lsp::DidSaveTextDocumentParams {
|
||||
text_document,
|
||||
text: include_text.then(|| text.into()),
|
||||
})
|
||||
.await
|
||||
Some(self.notify::<lsp::notification::DidSaveTextDocument>(
|
||||
lsp::DidSaveTextDocumentParams {
|
||||
text_document,
|
||||
text: include_text.then(|| text.into()),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn completion(
|
||||
|
@ -471,10 +471,10 @@ fn save_impl<F: Future<Output = LspFormatting>>(
|
||||
let mut file = File::create(path).await?;
|
||||
to_writer(&mut file, encoding, &text).await?;
|
||||
|
||||
if let Some(language_server) = language_server {
|
||||
language_server
|
||||
.text_document_did_save(identifier, &text)
|
||||
.await?;
|
||||
if let Some(notification) = language_server.and_then(|language_server| {
|
||||
language_server.text_document_did_save(identifier, &text)
|
||||
}) {
|
||||
notification.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user