@@ -35,13 +35,13 @@ pub struct Document {
35 // /// Corresponding language scope name. Usually `source.<lang>`.
35 // /// Corresponding language scope name. Usually `source.<lang>`.
36 pub(crate) language: Option<Arc<LanguageConfiguration>>,
36 pub(crate) language: Option<Arc<LanguageConfiguration>>,
39 /// Pending changes since last history commit.
38 /// Pending changes since last history commit.
40 changes: ChangeSet,
39 changes: ChangeSet,
41 /// State at last commit. Used for calculating reverts.
40 /// State at last commit. Used for calculating reverts.
42 old_state: Option<State>,
41 old_state: Option<State>,
43 /// Undo tree.
42 /// Undo tree.
44 history: History,
43 history: History,
44+ last_saved_revision: usize,
45 version: i32, // should be usize?
45 version: i32, // should be usize?
47 pub diagnostics: Vec<Diagnostic>,
47 pub diagnostics: Vec<Diagnostic>,
@@ -81,12 +81,12 @@ impl Document {
81 restore_cursor: false,
81 restore_cursor: false,
82 syntax: None,
82 syntax: None,
83 language: None,
83 language: None,
86 old_state,
85 old_state,
87 diagnostics: Vec::new(),
86 diagnostics: Vec::new(),
88 version: 0,
87 version: 0,
89 history: History::default(),
88 history: History::default(),
89+ last_saved_revision: 0,
90 language_server: None,
90 language_server: None,
@@ -131,7 +131,7 @@ impl Document {
131 let language_server = self.language_server.clone();
131 let language_server = self.language_server.clone();
133 // reset the modified flag
133 // reset the modified flag
134− self.modified = false;
134+ self.last_saved_revision = self.history.current_revision();
136 async move {
136 async move {
137 use smol::{fs::File, prelude::*};
137 use smol::{fs::File, prelude::*};
@@ -246,10 +246,6 @@ impl Document {
247 let success = self._apply(transaction, view_id);
247 let success = self._apply(transaction, view_id);
249− self.modified = true;
250− // TODO: be smarter about modified by keeping track of saved version instead. That way if
251− // current version == version then it's not modified.
253 if !transaction.changes().is_empty() {
249 if !transaction.changes().is_empty() {
254 // Compose this transaction with the previous one
250 // Compose this transaction with the previous one
255 take_with(&mut self.changes, |changes| {
251 take_with(&mut self.changes, |changes| {
@@ -307,8 +303,10 @@ impl Document {
309 #[inline]
305 #[inline]
310− pub fn modified(&self) -> bool {
306+ pub fn is_modified(&self) -> bool {
311− self.modified
307+ self.path.is_some()
308+ && (self.history.current_revision() != self.last_saved_revision
309+ || !self.changes.is_empty())
314 #[inline]
312 #[inline]