lsp: Emit didSave notifications.
This commit is contained in:
parent
b7dd7310c4
commit
6cbfb050e2
3 changed files with 36 additions and 3 deletions
7
TODO.md
7
TODO.md
|
@ -31,9 +31,14 @@
|
|||
- [x] q should only close the view, if all are closed, close the editor
|
||||
- [ ] buffers should sit on editor.buffers, view simply refs them
|
||||
|
||||
- [ ] pressing b at start of file needs to not crash
|
||||
- [ ] draw separator line between views
|
||||
- [ ] command to drop all selections except primary
|
||||
|
||||
- [ ] diagnostic severity
|
||||
|
||||
- [ ] lsp: signature help
|
||||
- [ ] lsp: hover
|
||||
- [x] lsp: hover
|
||||
- [ ] lsp: document symbols (nested/vec)
|
||||
- [ ] lsp: code actions
|
||||
- [ ] lsp: formatting
|
||||
|
|
|
@ -414,10 +414,29 @@ impl Client {
|
|||
pub async fn text_document_did_save(
|
||||
&self,
|
||||
text_document: lsp::TextDocumentIdentifier,
|
||||
text: &Rope,
|
||||
) -> Result<()> {
|
||||
let capabilities = self.capabilities.as_ref().unwrap(); // TODO: needs post init
|
||||
|
||||
let include_text = match &capabilities.text_document_sync {
|
||||
Some(lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions {
|
||||
save: Some(options),
|
||||
..
|
||||
})) => match options {
|
||||
lsp::TextDocumentSyncSaveOptions::Supported(true) => false,
|
||||
lsp::TextDocumentSyncSaveOptions::SaveOptions(lsp_types::SaveOptions {
|
||||
include_text,
|
||||
}) => include_text.unwrap_or(false),
|
||||
// Supported(false)
|
||||
_ => return Ok(()),
|
||||
},
|
||||
// unsupported
|
||||
_ => return Ok(()),
|
||||
};
|
||||
|
||||
self.notify::<lsp::notification::DidSaveTextDocument>(lsp::DidSaveTextDocumentParams {
|
||||
text_document,
|
||||
text: None, // TODO:
|
||||
text: include_text.then(|| text.into()),
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -111,10 +111,13 @@ impl Document {
|
|||
|
||||
let text = self.text().clone();
|
||||
let path = self.path.clone().expect("Can't save with no path set!"); // TODO: handle no path
|
||||
let identifier = self.identifier();
|
||||
|
||||
// TODO: mark changes up to now as saved
|
||||
// TODO: mark dirty false
|
||||
|
||||
let language_server = self.language_server.clone();
|
||||
|
||||
async move {
|
||||
use smol::{fs::File, prelude::*};
|
||||
let mut file = File::create(path).await?;
|
||||
|
@ -125,8 +128,14 @@ impl Document {
|
|||
}
|
||||
// TODO: flush?
|
||||
|
||||
if let Some(language_server) = language_server {
|
||||
language_server
|
||||
.text_document_did_save(identifier, &text)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
} // and_then notify save
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_language(
|
||||
|
|
Loading…
Reference in a new issue