diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 12c005f06d..4ed02f60ef 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -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, }; diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs index 8bf52d0fa8..1873d1d0d0 100644 --- a/crates/ra_ide/src/ssr.rs +++ b/crates/ra_ide/src/ssr.rs @@ -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); diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index a03da46938..6f04f0be4e 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs @@ -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; diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index e6f2d36e94..52fcd7b6f0 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs @@ -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; diff --git a/crates/ra_ide/src/source_change.rs b/crates/ra_ide_db/src/source_change.rs similarity index 79% rename from crates/ra_ide/src/source_change.rs rename to crates/ra_ide_db/src/source_change.rs index 10afd78256..4dd01b3122 100644 --- a/crates/ra_ide/src/source_change.rs +++ b/crates/ra_ide_db/src/source_change.rs @@ -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, pub file_system_edits: Vec, @@ -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>( + pub fn from_edits>( label: L, source_file_edits: Vec, file_system_edits: Vec, @@ -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>(label: L, edits: Vec) -> Self { + pub fn source_file_edits>(label: L, edits: Vec) -> 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>(label: L, edit: SourceFileEdit) -> Self { + pub fn source_file_edit>(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>( + pub fn source_file_edit_from>( 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>(label: L, edit: FileSystemEdit) -> Self { + pub fn file_system_edit>(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) -> Self { + pub fn with_cursor_opt(mut self, cursor_position: Option) -> 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, } 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 }], diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs index 7138bbc655..64b67f2ade 100644 --- a/crates/ra_text_edit/src/lib.rs +++ b/crates/ra_text_edit/src/lib.rs @@ -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 ///