mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 14:33:29 +00:00
3c72fc0573
Anchoring to the SourceRoot wont' work if the path is absolute: #[path = "/tmp/foo.rs"] mod foo; Anchoring to a file will. However, we *should* anchor, instead of just producing an abs path. I can imagine a situation where, for example, rust-analyzer processes crates from different machines (or, for example, from in-memory git branch), where the same absolute path in different crates might refer to different files in the end!
59 lines
1.6 KiB
Rust
59 lines
1.6 KiB
Rust
//! 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 ra_db::FileId;
|
|
use ra_text_edit::TextEdit;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct SourceChange {
|
|
pub source_file_edits: Vec<SourceFileEdit>,
|
|
pub file_system_edits: Vec<FileSystemEdit>,
|
|
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<SourceFileEdit>,
|
|
file_system_edits: Vec<FileSystemEdit>,
|
|
) -> 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<SourceFileEdit> for SourceChange {
|
|
fn from(edit: SourceFileEdit) -> SourceChange {
|
|
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 }
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum FileSystemEdit {
|
|
CreateFile { anchor: FileId, dst: String },
|
|
MoveFile { src: FileId, anchor: FileId, dst: String },
|
|
}
|
|
|
|
impl From<FileSystemEdit> for SourceChange {
|
|
fn from(edit: FileSystemEdit) -> SourceChange {
|
|
SourceChange {
|
|
source_file_edits: Vec::new(),
|
|
file_system_edits: vec![edit],
|
|
is_snippet: false,
|
|
}
|
|
}
|
|
}
|