Lift SourceChange to the ra_ide_db

This commit is contained in:
Aleksey Kladov 2020-05-06 11:31:26 +02:00
parent beb35c3ecb
commit 3850b1c086
6 changed files with 25 additions and 25 deletions

View file

@ -16,7 +16,6 @@ macro_rules! eprintln {
}
pub mod mock_analysis;
mod source_change;
mod prime_caches;
mod status;
@ -78,7 +77,6 @@ pub use crate::{
inlay_hints::{InlayHint, InlayHintsConfig, InlayKind},
references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult},
runnables::{Runnable, RunnableKind, TestId},
source_change::{FileSystemEdit, SourceChange, SourceFileEdit},
ssr::SsrError,
syntax_highlighting::{
Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange,
@ -94,6 +92,7 @@ pub use ra_ide_db::{
line_index::{LineCol, LineIndex},
line_index_utils::translate_offset_with_edit,
search::SearchScope,
source_change::{FileSystemEdit, SourceChange, SourceFileEdit},
symbol_index::Query,
RootDatabase,
};

View file

@ -1,18 +1,18 @@
//! structural search replace
use crate::source_change::SourceFileEdit;
use std::{collections::HashMap, iter::once, str::FromStr};
use ra_db::{SourceDatabase, SourceDatabaseExt};
use ra_ide_db::symbol_index::SymbolsDatabase;
use ra_ide_db::RootDatabase;
use ra_syntax::ast::make::try_expr_from_text;
use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase};
use ra_syntax::ast::{
ArgList, AstToken, CallExpr, Comment, Expr, MethodCallExpr, RecordField, RecordLit,
make::try_expr_from_text, ArgList, AstToken, CallExpr, Comment, Expr, MethodCallExpr,
RecordField, RecordLit,
};
use ra_syntax::{AstNode, SyntaxElement, SyntaxKind, SyntaxNode};
use ra_text_edit::{TextEdit, TextEditBuilder};
use rustc_hash::FxHashMap;
use std::collections::HashMap;
use std::{iter::once, str::FromStr};
use crate::SourceFileEdit;
#[derive(Debug, PartialEq)]
pub struct SsrError(String);

View file

@ -17,15 +17,16 @@ mod on_enter;
use ra_db::{FilePosition, SourceDatabase};
use ra_fmt::leading_indent;
use ra_ide_db::RootDatabase;
use ra_ide_db::{source_change::SingleFileChange, RootDatabase};
use ra_syntax::{
algo::find_node_at_offset,
ast::{self, AstToken},
AstNode, SourceFile, TextRange, TextSize,
};
use ra_text_edit::TextEdit;
use crate::{source_change::SingleFileChange, SourceChange};
use crate::SourceChange;
pub(crate) use on_enter::on_enter;

View file

@ -10,6 +10,7 @@ pub mod change;
pub mod defs;
pub mod search;
pub mod imports_locator;
pub mod source_change;
mod wasm_shims;
use std::sync::Arc;

View file

@ -3,13 +3,12 @@
//!
//! It can be viewed as a dual for `AnalysisChange`.
use ra_db::RelativePathBuf;
use ra_text_edit::TextEdit;
use crate::{FileId, FilePosition, SourceRootId, TextSize};
use ra_db::{FileId, FilePosition, RelativePathBuf, SourceRootId};
use ra_text_edit::{TextEdit, TextSize};
#[derive(Debug)]
pub struct SourceChange {
/// For display in the undo log in the editor
pub label: String,
pub source_file_edits: Vec<SourceFileEdit>,
pub file_system_edits: Vec<FileSystemEdit>,
@ -19,7 +18,7 @@ pub struct SourceChange {
impl SourceChange {
/// Creates a new SourceChange with the given label
/// from the edits.
pub(crate) fn from_edits<L: Into<String>>(
pub fn from_edits<L: Into<String>>(
label: L,
source_file_edits: Vec<SourceFileEdit>,
file_system_edits: Vec<FileSystemEdit>,
@ -34,7 +33,7 @@ impl SourceChange {
/// 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 {
pub fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self {
let label = label.into();
assert!(label.starts_with(char::is_uppercase));
SourceChange {
@ -58,13 +57,13 @@ impl SourceChange {
/// 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 {
pub 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>>(
pub fn source_file_edit_from<L: Into<String>>(
label: L,
file_id: FileId,
edit: TextEdit,
@ -74,18 +73,18 @@ impl SourceChange {
/// 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 {
pub 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 {
pub 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 {
pub fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self {
self.cursor_position = cursor_position;
self
}
@ -103,14 +102,14 @@ pub enum FileSystemEdit {
MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf },
}
pub(crate) struct SingleFileChange {
pub struct SingleFileChange {
pub label: String,
pub edit: TextEdit,
pub cursor_position: Option<TextSize>,
}
impl SingleFileChange {
pub(crate) fn into_source_change(self, file_id: FileId) -> SourceChange {
pub fn into_source_change(self, file_id: FileId) -> SourceChange {
SourceChange {
label: self.label,
source_file_edits: vec![SourceFileEdit { file_id, edit: self.edit }],

View file

@ -4,7 +4,7 @@
//! so `TextEdit` is the ultimate representation of the work done by
//! rust-analyzer.
use text_size::{TextRange, TextSize};
pub use text_size::{TextRange, TextSize};
/// `InsertDelete` -- a single "atomic" change to text
///