@@ -31,6 +31,7 @@ pub struct Document {
31 // /// Corresponding language scope name. Usually `source.<lang>`.
31 // /// Corresponding language scope name. Usually `source.<lang>`.
32 pub(crate) language: Option<Arc<LanguageConfiguration>>,
32 pub(crate) language: Option<Arc<LanguageConfiguration>>,
34 /// Pending changes since last history commit.
35 /// Pending changes since last history commit.
35 changes: ChangeSet,
36 changes: ChangeSet,
36 /// State at last commit. Used for calculating reverts.
37 /// State at last commit. Used for calculating reverts.
@@ -75,6 +76,7 @@ impl Document {
75 restore_cursor: false,
76 restore_cursor: false,
76 syntax: None,
77 syntax: None,
77 language: None,
78 language: None,
79 old_state,
81 old_state,
80 diagnostics: Vec::new(),
82 diagnostics: Vec::new(),
@@ -111,7 +113,7 @@ impl Document {
112 // TODO: do we need some way of ensuring two save operations on the same doc can't run at once?
114 // TODO: do we need some way of ensuring two save operations on the same doc can't run at once?
113 // or is that handled by the OS/async layer
115 // 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>> {
115 // we clone and move text + path into the future so that we asynchronously save the current
117 // we clone and move text + path into the future so that we asynchronously save the current
116 // state without blocking any further edits.
118 // state without blocking any further edits.
@@ -120,10 +122,12 @@ impl Document {
120 let identifier = self.identifier();
122 let identifier = self.identifier();
122 // TODO: mark changes up to now as saved
124 // TODO: mark changes up to now as saved
123− // TODO: mark dirty false
125 let language_server = self.language_server.clone();
126 let language_server = self.language_server.clone();
128+ // reset the modified flag
129+ self.modified = false;
127 async move {
131 async move {
128 use smol::{fs::File, prelude::*};
132 use smol::{fs::File, prelude::*};
129 let mut file = File::create(path).await?;
133 let mut file = File::create(path).await?;
@@ -224,6 +228,10 @@ impl Document {
225 let success = self._apply(&transaction);
229 let success = self._apply(&transaction);
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.
227 if !transaction.changes().is_empty() {
235 if !transaction.changes().is_empty() {
228 // Compose this transaction with the previous one
236 // Compose this transaction with the previous one
229 take_with(&mut self.changes, |changes| {
237 take_with(&mut self.changes, |changes| {
@@ -279,6 +287,11 @@ impl Document {
291+ pub fn modified(&self) -> bool {
282 #[inline]
295 #[inline]
283 pub fn mode(&self) -> Mode {
296 pub fn mode(&self) -> Mode {
284 self.mode
297 self.mode