2019-10-25 03:26:53 -05:00
|
|
|
//! This modules defines type to represent changes to the source code, that flow
|
|
|
|
//! from the server to the client.
|
|
|
|
//!
|
|
|
|
//! It can be viewed as a dual for `AnalysisChange`.
|
|
|
|
|
2020-12-09 10:01:15 -06:00
|
|
|
use base_db::{AnchoredPathBuf, FileId};
|
2020-08-12 10:03:06 -05:00
|
|
|
use text_edit::TextEdit;
|
2019-10-25 03:26:53 -05:00
|
|
|
|
2020-07-07 05:10:18 -05:00
|
|
|
#[derive(Default, Debug, Clone)]
|
2019-10-25 03:26:53 -05:00
|
|
|
pub struct SourceChange {
|
|
|
|
pub source_file_edits: Vec<SourceFileEdit>,
|
|
|
|
pub file_system_edits: Vec<FileSystemEdit>,
|
2020-05-17 05:09:53 -05:00
|
|
|
pub is_snippet: bool,
|
2019-10-25 03:26:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SourceChange {
|
|
|
|
/// Creates a new SourceChange with the given label
|
|
|
|
/// from the edits.
|
2020-05-22 11:03:08 -05:00
|
|
|
pub fn from_edits(
|
2019-10-25 03:26:53 -05:00
|
|
|
source_file_edits: Vec<SourceFileEdit>,
|
|
|
|
file_system_edits: Vec<FileSystemEdit>,
|
|
|
|
) -> Self {
|
2020-05-22 11:03:08 -05:00
|
|
|
SourceChange { source_file_edits, file_system_edits, is_snippet: false }
|
2019-10-25 03:26:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 08:26:40 -05:00
|
|
|
#[derive(Debug, Clone)]
|
2019-10-25 03:26:53 -05:00
|
|
|
pub struct SourceFileEdit {
|
|
|
|
pub file_id: FileId,
|
|
|
|
pub edit: TextEdit,
|
|
|
|
}
|
|
|
|
|
2020-05-22 11:03:08 -05:00
|
|
|
impl From<SourceFileEdit> for SourceChange {
|
|
|
|
fn from(edit: SourceFileEdit) -> SourceChange {
|
2020-06-08 14:44:42 -05:00
|
|
|
vec![edit].into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Vec<SourceFileEdit>> for SourceChange {
|
|
|
|
fn from(source_file_edits: Vec<SourceFileEdit>) -> SourceChange {
|
|
|
|
SourceChange { source_file_edits, file_system_edits: Vec::new(), is_snippet: false }
|
2020-05-22 11:03:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 08:26:40 -05:00
|
|
|
#[derive(Debug, Clone)]
|
2019-10-25 03:26:53 -05:00
|
|
|
pub enum FileSystemEdit {
|
2020-12-09 10:01:15 -06:00
|
|
|
CreateFile { dst: AnchoredPathBuf },
|
|
|
|
MoveFile { src: FileId, dst: AnchoredPathBuf },
|
2019-10-25 03:26:53 -05:00
|
|
|
}
|
2019-10-25 03:49:38 -05:00
|
|
|
|
2020-05-22 11:03:08 -05:00
|
|
|
impl From<FileSystemEdit> for SourceChange {
|
|
|
|
fn from(edit: FileSystemEdit) -> SourceChange {
|
2019-10-25 03:49:38 -05:00
|
|
|
SourceChange {
|
2020-05-22 11:03:08 -05:00
|
|
|
source_file_edits: Vec::new(),
|
|
|
|
file_system_edits: vec![edit],
|
2020-05-17 05:09:53 -05:00
|
|
|
is_snippet: false,
|
2019-10-25 03:49:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|