on master help sign in
lsp: Emit didSave notifications.
6cbfb05Blaž Hrastnik
TODO.md+6−1
@@ -31,9 +31,14 @@
31- [x] q should only close the view, if all are closed, close the editor
31- [x] q should only close the view, if all are closed, close the editor
32- [ ] buffers should sit on editor.buffers, view simply refs them
32- [ ] buffers should sit on editor.buffers, view simply refs them
33
33
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
34
39
35- [ ] lsp: signature help
40- [ ] lsp: signature help
36−- [ ] lsp: hover
41+- [x] lsp: hover
37- [ ] lsp: document symbols (nested/vec)
42- [ ] lsp: document symbols (nested/vec)
38- [ ] lsp: code actions
43- [ ] lsp: code actions
39- [ ] lsp: formatting
44- [ ] lsp: formatting
helix-lsp/src/client.rs+20−1
@@ -414,10 +414,29 @@ impl Client {
414 pub async fn text_document_did_save(
414 pub async fn text_document_did_save(
415 &self,
415 &self,
416 text_document: lsp::TextDocumentIdentifier,
416 text_document: lsp::TextDocumentIdentifier,
417+ text: &Rope,
417 ) -> Result<()> {
418 ) -> 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+
418 self.notify::<lsp::notification::DidSaveTextDocument>(lsp::DidSaveTextDocumentParams {
437 self.notify::<lsp::notification::DidSaveTextDocument>(lsp::DidSaveTextDocumentParams {
419 text_document,
438 text_document,
420− text: None, // TODO:
439+ text: include_text.then(|| text.into()),
421 })
440 })
422 .await
441 .await
423 }
442 }
helix-view/src/document.rs+10−1
@@ -111,10 +111,13 @@ impl Document {
111
111
112 let text = self.text().clone();
112 let text = self.text().clone();
113 let path = self.path.clone().expect("Can't save with no path set!"); // TODO: handle no path
113 let path = self.path.clone().expect("Can't save with no path set!"); // TODO: handle no path
114+ let identifier = self.identifier();
114
115
115 // TODO: mark changes up to now as saved
116 // TODO: mark changes up to now as saved
116 // TODO: mark dirty false
117 // TODO: mark dirty false
117
118
119+ let language_server = self.language_server.clone();
120+
118 async move {
121 async move {
119 use smol::{fs::File, prelude::*};
122 use smol::{fs::File, prelude::*};
120 let mut file = File::create(path).await?;
123 let mut file = File::create(path).await?;
@@ -125,8 +128,14 @@ impl Document {
125 }
128 }
126 // TODO: flush?
129 // TODO: flush?
127
130
131+ if let Some(language_server) = language_server {
132+ language_server
133+ .text_document_did_save(identifier, &text)
134+ .await?;
135+ }
136+
128 Ok(())
137 Ok(())
129− } // and_then notify save
138+ }
130 }
139 }
131
140
132 pub fn set_language(
141 pub fn set_language(