|
|
@ -31,6 +31,7 @@ pub struct Document {
|
|
|
|
// /// Corresponding language scope name. Usually `source.<lang>`.
|
|
|
|
// /// Corresponding language scope name. Usually `source.<lang>`.
|
|
|
|
pub(crate) language: Option<Arc<LanguageConfiguration>>,
|
|
|
|
pub(crate) language: Option<Arc<LanguageConfiguration>>,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modified: bool,
|
|
|
|
/// Pending changes since last history commit.
|
|
|
|
/// Pending changes since last history commit.
|
|
|
|
changes: ChangeSet,
|
|
|
|
changes: ChangeSet,
|
|
|
|
/// State at last commit. Used for calculating reverts.
|
|
|
|
/// State at last commit. Used for calculating reverts.
|
|
|
@ -75,6 +76,7 @@ impl Document {
|
|
|
|
restore_cursor: false,
|
|
|
|
restore_cursor: false,
|
|
|
|
syntax: None,
|
|
|
|
syntax: None,
|
|
|
|
language: None,
|
|
|
|
language: None,
|
|
|
|
|
|
|
|
modified: false,
|
|
|
|
changes,
|
|
|
|
changes,
|
|
|
|
old_state,
|
|
|
|
old_state,
|
|
|
|
diagnostics: Vec::new(),
|
|
|
|
diagnostics: Vec::new(),
|
|
|
@ -111,7 +113,7 @@ impl Document {
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: do we need some way of ensuring two save operations on the same doc can't run at once?
|
|
|
|
// TODO: do we need some way of ensuring two save operations on the same doc can't run at once?
|
|
|
|
// or is that handled by the OS/async layer
|
|
|
|
// or is that handled by the OS/async layer
|
|
|
|
pub fn save(&self) -> impl Future<Output = Result<(), anyhow::Error>> {
|
|
|
|
pub fn save(&mut self) -> impl Future<Output = Result<(), anyhow::Error>> {
|
|
|
|
// we clone and move text + path into the future so that we asynchronously save the current
|
|
|
|
// we clone and move text + path into the future so that we asynchronously save the current
|
|
|
|
// state without blocking any further edits.
|
|
|
|
// state without blocking any further edits.
|
|
|
|
|
|
|
|
|
|
|
@ -120,10 +122,12 @@ impl Document {
|
|
|
|
let identifier = self.identifier();
|
|
|
|
let identifier = self.identifier();
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: mark changes up to now as saved
|
|
|
|
// TODO: mark changes up to now as saved
|
|
|
|
// TODO: mark dirty false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let language_server = self.language_server.clone();
|
|
|
|
let language_server = self.language_server.clone();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// reset the modified flag
|
|
|
|
|
|
|
|
self.modified = false;
|
|
|
|
|
|
|
|
|
|
|
|
async move {
|
|
|
|
async move {
|
|
|
|
use smol::{fs::File, prelude::*};
|
|
|
|
use smol::{fs::File, prelude::*};
|
|
|
|
let mut file = File::create(path).await?;
|
|
|
|
let mut file = File::create(path).await?;
|
|
|
@ -224,6 +228,10 @@ impl Document {
|
|
|
|
|
|
|
|
|
|
|
|
let success = self._apply(&transaction);
|
|
|
|
let success = self._apply(&transaction);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.modified = true;
|
|
|
|
|
|
|
|
// TODO: be smarter about modified by keeping track of saved version instead. That way if
|
|
|
|
|
|
|
|
// current version == version then it's not modified.
|
|
|
|
|
|
|
|
|
|
|
|
if !transaction.changes().is_empty() {
|
|
|
|
if !transaction.changes().is_empty() {
|
|
|
|
// Compose this transaction with the previous one
|
|
|
|
// Compose this transaction with the previous one
|
|
|
|
take_with(&mut self.changes, |changes| {
|
|
|
|
take_with(&mut self.changes, |changes| {
|
|
|
@ -279,6 +287,11 @@ impl Document {
|
|
|
|
self.id
|
|
|
|
self.id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
|
|
|
pub fn modified(&self) -> bool {
|
|
|
|
|
|
|
|
self.modified
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
#[inline]
|
|
|
|
pub fn mode(&self) -> Mode {
|
|
|
|
pub fn mode(&self) -> Mode {
|
|
|
|
self.mode
|
|
|
|
self.mode
|
|
|
|