mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
move source change to a dedicated file
This commit is contained in:
parent
8d2fd59cfb
commit
b112430ca7
2 changed files with 104 additions and 95 deletions
|
@ -14,6 +14,7 @@ mod db;
|
||||||
pub mod mock_analysis;
|
pub mod mock_analysis;
|
||||||
mod symbol_index;
|
mod symbol_index;
|
||||||
mod change;
|
mod change;
|
||||||
|
mod source_change;
|
||||||
mod feature_flags;
|
mod feature_flags;
|
||||||
|
|
||||||
mod status;
|
mod status;
|
||||||
|
@ -54,8 +55,6 @@ use ra_db::{
|
||||||
CheckCanceled, FileLoader, SourceDatabase,
|
CheckCanceled, FileLoader, SourceDatabase,
|
||||||
};
|
};
|
||||||
use ra_syntax::{SourceFile, TextRange, TextUnit};
|
use ra_syntax::{SourceFile, TextRange, TextUnit};
|
||||||
use ra_text_edit::TextEdit;
|
|
||||||
use relative_path::RelativePathBuf;
|
|
||||||
|
|
||||||
use crate::{db::LineIndexDatabase, symbol_index::FileSymbol};
|
use crate::{db::LineIndexDatabase, symbol_index::FileSymbol};
|
||||||
|
|
||||||
|
@ -73,6 +72,7 @@ pub use crate::{
|
||||||
line_index_utils::translate_offset_with_edit,
|
line_index_utils::translate_offset_with_edit,
|
||||||
references::{ReferenceSearchResult, SearchScope},
|
references::{ReferenceSearchResult, SearchScope},
|
||||||
runnables::{Runnable, RunnableKind},
|
runnables::{Runnable, RunnableKind},
|
||||||
|
source_change::{FileSystemEdit, SourceChange, SourceFileEdit},
|
||||||
syntax_highlighting::HighlightedRange,
|
syntax_highlighting::HighlightedRange,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,99 +83,6 @@ pub use ra_db::{
|
||||||
|
|
||||||
pub type Cancelable<T> = Result<T, Canceled>;
|
pub type Cancelable<T> = Result<T, Canceled>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct SourceChange {
|
|
||||||
pub label: String,
|
|
||||||
pub source_file_edits: Vec<SourceFileEdit>,
|
|
||||||
pub file_system_edits: Vec<FileSystemEdit>,
|
|
||||||
pub cursor_position: Option<FilePosition>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SourceChange {
|
|
||||||
/// Creates a new SourceChange with the given label
|
|
||||||
/// from the edits.
|
|
||||||
pub(crate) fn from_edits<L: Into<String>>(
|
|
||||||
label: L,
|
|
||||||
source_file_edits: Vec<SourceFileEdit>,
|
|
||||||
file_system_edits: Vec<FileSystemEdit>,
|
|
||||||
) -> Self {
|
|
||||||
SourceChange {
|
|
||||||
label: label.into(),
|
|
||||||
source_file_edits,
|
|
||||||
file_system_edits,
|
|
||||||
cursor_position: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new SourceChange with the given label,
|
|
||||||
/// containing only the given `SourceFileEdits`.
|
|
||||||
pub(crate) fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self {
|
|
||||||
SourceChange {
|
|
||||||
label: label.into(),
|
|
||||||
source_file_edits: edits,
|
|
||||||
file_system_edits: vec![],
|
|
||||||
cursor_position: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new SourceChange with the given label,
|
|
||||||
/// containing only the given `FileSystemEdits`.
|
|
||||||
pub(crate) fn file_system_edits<L: Into<String>>(label: L, edits: Vec<FileSystemEdit>) -> Self {
|
|
||||||
SourceChange {
|
|
||||||
label: label.into(),
|
|
||||||
source_file_edits: vec![],
|
|
||||||
file_system_edits: edits,
|
|
||||||
cursor_position: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new SourceChange with the given label,
|
|
||||||
/// containing only a single `SourceFileEdit`.
|
|
||||||
pub(crate) fn source_file_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self {
|
|
||||||
SourceChange::source_file_edits(label, vec![edit])
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new SourceChange with the given label
|
|
||||||
/// from the given `FileId` and `TextEdit`
|
|
||||||
pub(crate) fn source_file_edit_from<L: Into<String>>(
|
|
||||||
label: L,
|
|
||||||
file_id: FileId,
|
|
||||||
edit: TextEdit,
|
|
||||||
) -> Self {
|
|
||||||
SourceChange::source_file_edit(label, SourceFileEdit { file_id, edit })
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new SourceChange with the given label
|
|
||||||
/// from the given `FileId` and `TextEdit`
|
|
||||||
pub(crate) fn file_system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self {
|
|
||||||
SourceChange::file_system_edits(label, vec![edit])
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the cursor position to the given `FilePosition`
|
|
||||||
pub(crate) fn with_cursor(mut self, cursor_position: FilePosition) -> Self {
|
|
||||||
self.cursor_position = Some(cursor_position);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the cursor position to the given `FilePosition`
|
|
||||||
pub(crate) fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self {
|
|
||||||
self.cursor_position = cursor_position;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct SourceFileEdit {
|
|
||||||
pub file_id: FileId,
|
|
||||||
pub edit: TextEdit,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum FileSystemEdit {
|
|
||||||
CreateFile { source_root: SourceRootId, path: RelativePathBuf },
|
|
||||||
MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf },
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Diagnostic {
|
pub struct Diagnostic {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
|
|
102
crates/ra_ide_api/src/source_change.rs
Normal file
102
crates/ra_ide_api/src/source_change.rs
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
//! 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_text_edit::TextEdit;
|
||||||
|
use relative_path::RelativePathBuf;
|
||||||
|
|
||||||
|
use crate::{FileId, FilePosition, SourceRootId};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SourceChange {
|
||||||
|
pub label: String,
|
||||||
|
pub source_file_edits: Vec<SourceFileEdit>,
|
||||||
|
pub file_system_edits: Vec<FileSystemEdit>,
|
||||||
|
pub cursor_position: Option<FilePosition>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SourceChange {
|
||||||
|
/// Creates a new SourceChange with the given label
|
||||||
|
/// from the edits.
|
||||||
|
pub(crate) fn from_edits<L: Into<String>>(
|
||||||
|
label: L,
|
||||||
|
source_file_edits: Vec<SourceFileEdit>,
|
||||||
|
file_system_edits: Vec<FileSystemEdit>,
|
||||||
|
) -> Self {
|
||||||
|
SourceChange {
|
||||||
|
label: label.into(),
|
||||||
|
source_file_edits,
|
||||||
|
file_system_edits,
|
||||||
|
cursor_position: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new SourceChange with the given label,
|
||||||
|
/// containing only the given `SourceFileEdits`.
|
||||||
|
pub(crate) fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self {
|
||||||
|
SourceChange {
|
||||||
|
label: label.into(),
|
||||||
|
source_file_edits: edits,
|
||||||
|
file_system_edits: vec![],
|
||||||
|
cursor_position: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new SourceChange with the given label,
|
||||||
|
/// containing only the given `FileSystemEdits`.
|
||||||
|
pub(crate) fn file_system_edits<L: Into<String>>(label: L, edits: Vec<FileSystemEdit>) -> Self {
|
||||||
|
SourceChange {
|
||||||
|
label: label.into(),
|
||||||
|
source_file_edits: vec![],
|
||||||
|
file_system_edits: edits,
|
||||||
|
cursor_position: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new SourceChange with the given label,
|
||||||
|
/// containing only a single `SourceFileEdit`.
|
||||||
|
pub(crate) fn source_file_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self {
|
||||||
|
SourceChange::source_file_edits(label, vec![edit])
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new SourceChange with the given label
|
||||||
|
/// from the given `FileId` and `TextEdit`
|
||||||
|
pub(crate) fn source_file_edit_from<L: Into<String>>(
|
||||||
|
label: L,
|
||||||
|
file_id: FileId,
|
||||||
|
edit: TextEdit,
|
||||||
|
) -> Self {
|
||||||
|
SourceChange::source_file_edit(label, SourceFileEdit { file_id, edit })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new SourceChange with the given label
|
||||||
|
/// from the given `FileId` and `TextEdit`
|
||||||
|
pub(crate) fn file_system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self {
|
||||||
|
SourceChange::file_system_edits(label, vec![edit])
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the cursor position to the given `FilePosition`
|
||||||
|
pub(crate) fn with_cursor(mut self, cursor_position: FilePosition) -> Self {
|
||||||
|
self.cursor_position = Some(cursor_position);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the cursor position to the given `FilePosition`
|
||||||
|
pub(crate) fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self {
|
||||||
|
self.cursor_position = cursor_position;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SourceFileEdit {
|
||||||
|
pub file_id: FileId,
|
||||||
|
pub edit: TextEdit,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum FileSystemEdit {
|
||||||
|
CreateFile { source_root: SourceRootId, path: RelativePathBuf },
|
||||||
|
MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf },
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue