From bb5c189b7dae1ea63ccd5d7a0c2e097d7c676f77 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 16:39:16 +0200 Subject: Rename ra_ide_db -> ide_db --- crates/ide_db/src/source_change.rs | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 crates/ide_db/src/source_change.rs (limited to 'crates/ide_db/src/source_change.rs') diff --git a/crates/ide_db/src/source_change.rs b/crates/ide_db/src/source_change.rs new file mode 100644 index 000000000..f1590ec66 --- /dev/null +++ b/crates/ide_db/src/source_change.rs @@ -0,0 +1,59 @@ +//! 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`. + +use base_db::FileId; +use text_edit::TextEdit; + +#[derive(Default, Debug, Clone)] +pub struct SourceChange { + pub source_file_edits: Vec, + pub file_system_edits: Vec, + pub is_snippet: bool, +} + +impl SourceChange { + /// Creates a new SourceChange with the given label + /// from the edits. + pub fn from_edits( + source_file_edits: Vec, + file_system_edits: Vec, + ) -> Self { + SourceChange { source_file_edits, file_system_edits, is_snippet: false } + } +} + +#[derive(Debug, Clone)] +pub struct SourceFileEdit { + pub file_id: FileId, + pub edit: TextEdit, +} + +impl From for SourceChange { + fn from(edit: SourceFileEdit) -> SourceChange { + vec![edit].into() + } +} + +impl From> for SourceChange { + fn from(source_file_edits: Vec) -> SourceChange { + SourceChange { source_file_edits, file_system_edits: Vec::new(), is_snippet: false } + } +} + +#[derive(Debug, Clone)] +pub enum FileSystemEdit { + CreateFile { anchor: FileId, dst: String }, + MoveFile { src: FileId, anchor: FileId, dst: String }, +} + +impl From for SourceChange { + fn from(edit: FileSystemEdit) -> SourceChange { + SourceChange { + source_file_edits: Vec::new(), + file_system_edits: vec![edit], + is_snippet: false, + } + } +} -- cgit v1.2.3