@@ -1,4 +1,5 @@
1use anyhow::Error;
1use anyhow::Error;
2+use std::future::Future;
2use std::path::PathBuf;
3use std::path::PathBuf;
4use helix_core::{
5use helix_core::{
@@ -97,6 +98,30 @@ impl Document {
101+ pub fn save(&self) -> impl Future<Output = Result<(), anyhow::Error>> {
102+ // we clone and move text + path into the future so that we asynchronously save the current
103+ // state without blocking any further edits.
105+ let text = self.text().clone();
106+ let path = self.path.clone().expect("Can't save with no path set!"); // TODO: handle no path
108+ // TODO: mark changes up to now as saved
109+ // TODO: mark dirty false
112+ use smol::{fs::File, prelude::*};
113+ let mut file = File::create(path).await?;
115+ // write all the rope chunks to file
116+ for chunk in text.chunks() {
117+ file.write_all(chunk.as_bytes()).await?;
122+ } // and_then(// lsp.send_text_saved_notification())
100 pub fn set_language(&mut self, scope: &str, scopes: &[String]) {
125 pub fn set_language(&mut self, scope: &str, scopes: &[String]) {
101 if let Some(language_config) = LOADER.language_config_for_scope(scope) {
126 if let Some(language_config) = LOADER.language_config_for_scope(scope) {
102 let highlight_config = language_config.highlight_config(scopes).unwrap().unwrap();
127 let highlight_config = language_config.highlight_config(scopes).unwrap().unwrap();