on master help sign in
lsp: Emit didSave notifications.
commit6cbfb050e2c99acf5cdfe7d981c262fbdeaf761c authorBlaž Hrastnik <blaz@mxxn.io> dateFri 12 Mar 2021, 16:20 (6 years ago) parentb7dd731
3 files changed+36−3
TODO.md+6−1 helix-lsp/src/client.rs+20−1 helix-view/src/document.rs+10−1
TODO.md+6−1
@@ -31,9 +31,14 @@
3131- [x] q should only close the view, if all are closed, close the editor
3232- [ ] buffers should sit on editor.buffers, view simply refs them
3333
34+- [ ] pressing b at start of file needs to not crash
35+- [ ] draw separator line between views
36+- [ ] command to drop all selections except primary
37+
38+- [ ] diagnostic severity
3439
3540- [ ] lsp: signature help
36−- [ ] lsp: hover
41+- [x] lsp: hover
3742- [ ] lsp: document symbols (nested/vec)
3843- [ ] lsp: code actions
3944- [ ] lsp: formatting
helix-lsp/src/client.rs+20−1
@@ -414,10 +414,29 @@ impl Client {
414414 pub async fn text_document_did_save(
415415 &self,
416416 text_document: lsp::TextDocumentIdentifier,
417+ text: &Rope,
417418 ) -> Result<()> {
419+ let capabilities = self.capabilities.as_ref().unwrap(); // TODO: needs post init
420+
421+ let include_text = match &capabilities.text_document_sync {
422+ Some(lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions {
423+ save: Some(options),
424+ ..
425+ })) => match options {
426+ lsp::TextDocumentSyncSaveOptions::Supported(true) => false,
427+ lsp::TextDocumentSyncSaveOptions::SaveOptions(lsp_types::SaveOptions {
428+ include_text,
429+ }) => include_text.unwrap_or(false),
430+ // Supported(false)
431+ _ => return Ok(()),
432+ },
433+ // unsupported
434+ _ => return Ok(()),
435+ };
436+
418437 self.notify::<lsp::notification::DidSaveTextDocument>(lsp::DidSaveTextDocumentParams {
419438 text_document,
420− text: None, // TODO:
439+ text: include_text.then(|| text.into()),
421440 })
422441 .await
423442 }
helix-view/src/document.rs+10−1
@@ -111,10 +111,13 @@ impl Document {
111111
112112 let text = self.text().clone();
113113 let path = self.path.clone().expect("Can't save with no path set!"); // TODO: handle no path
114+ let identifier = self.identifier();
114115
115116 // TODO: mark changes up to now as saved
116117 // TODO: mark dirty false
117118
119+ let language_server = self.language_server.clone();
120+
118121 async move {
119122 use smol::{fs::File, prelude::*};
120123 let mut file = File::create(path).await?;
@@ -125,8 +128,14 @@ impl Document {
125128 }
126129 // TODO: flush?
127130
131+ if let Some(language_server) = language_server {
132+ language_server
133+ .text_document_did_save(identifier, &text)
134+ .await?;
135+ }
136+
128137 Ok(())
129− } // and_then notify save
138+ }
130139 }
131140
132141 pub fn set_language(