@@ -31,6 +31,7 @@ pub struct Document {
3131 // /// Corresponding language scope name. Usually `source.<lang>`.
3232 pub(crate) language: Option<Arc<LanguageConfiguration>>,
3333
34+ modified: bool,
3435 /// Pending changes since last history commit.
3536 changes: ChangeSet,
3637 /// State at last commit. Used for calculating reverts.
@@ -75,6 +76,7 @@ impl Document {
7576 restore_cursor: false,
7677 syntax: None,
7778 language: None,
79+ modified: false,
7880 changes,
7981 old_state,
8082 diagnostics: Vec::new(),
@@ -111,7 +113,7 @@ impl Document {
111113
112114 // TODO: do we need some way of ensuring two save operations on the same doc can't run at once?
113115 // or is that handled by the OS/async layer
114− pub fn save(&self) -> impl Future<Output = Result<(), anyhow::Error>> {
116+ pub fn save(&mut self) -> impl Future<Output = Result<(), anyhow::Error>> {
115117 // we clone and move text + path into the future so that we asynchronously save the current
116118 // state without blocking any further edits.
117119
@@ -120,10 +122,12 @@ impl Document {
120122 let identifier = self.identifier();
121123
122124 // TODO: mark changes up to now as saved
123− // TODO: mark dirty false
124125
125126 let language_server = self.language_server.clone();
126127
128+ // reset the modified flag
129+ self.modified = false;
130+
127131 async move {
128132 use smol::{fs::File, prelude::*};
129133 let mut file = File::create(path).await?;
@@ -224,6 +228,10 @@ impl Document {
224228
225229 let success = self._apply(&transaction);
226230
231+ self.modified = true;
232+ // TODO: be smarter about modified by keeping track of saved version instead. That way if
233+ // current version == version then it's not modified.
234+
227235 if !transaction.changes().is_empty() {
228236 // Compose this transaction with the previous one
229237 take_with(&mut self.changes, |changes| {
@@ -279,6 +287,11 @@ impl Document {
279287 self.id
280288 }
281289
290+ #[inline]
291+ pub fn modified(&self) -> bool {
292+ self.modified
293+ }
294+
282295 #[inline]
283296 pub fn mode(&self) -> Mode {
284297 self.mode