Skip to content

Commit ede8906

Browse files
bors[bot]matklad
andauthored
Merge #4340
4340: Lift SourceChange to the ra_ide_db r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 18907e6 + 3850b1c commit ede8906

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

crates/ra_ide/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ macro_rules! eprintln {
1616
}
1717

1818
pub mod mock_analysis;
19-
mod source_change;
2019

2120
mod prime_caches;
2221
mod status;
@@ -78,7 +77,6 @@ pub use crate::{
7877
inlay_hints::{InlayHint, InlayHintsConfig, InlayKind},
7978
references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult},
8079
runnables::{Runnable, RunnableKind, TestId},
81-
source_change::{FileSystemEdit, SourceChange, SourceFileEdit},
8280
ssr::SsrError,
8381
syntax_highlighting::{
8482
Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange,
@@ -94,6 +92,7 @@ pub use ra_ide_db::{
9492
line_index::{LineCol, LineIndex},
9593
line_index_utils::translate_offset_with_edit,
9694
search::SearchScope,
95+
source_change::{FileSystemEdit, SourceChange, SourceFileEdit},
9796
symbol_index::Query,
9897
RootDatabase,
9998
};

crates/ra_ide/src/ssr.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//! structural search replace
22
3-
use crate::source_change::SourceFileEdit;
3+
use std::{collections::HashMap, iter::once, str::FromStr};
4+
45
use ra_db::{SourceDatabase, SourceDatabaseExt};
5-
use ra_ide_db::symbol_index::SymbolsDatabase;
6-
use ra_ide_db::RootDatabase;
7-
use ra_syntax::ast::make::try_expr_from_text;
6+
use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase};
87
use ra_syntax::ast::{
9-
ArgList, AstToken, CallExpr, Comment, Expr, MethodCallExpr, RecordField, RecordLit,
8+
make::try_expr_from_text, ArgList, AstToken, CallExpr, Comment, Expr, MethodCallExpr,
9+
RecordField, RecordLit,
1010
};
1111
use ra_syntax::{AstNode, SyntaxElement, SyntaxKind, SyntaxNode};
1212
use ra_text_edit::{TextEdit, TextEditBuilder};
1313
use rustc_hash::FxHashMap;
14-
use std::collections::HashMap;
15-
use std::{iter::once, str::FromStr};
14+
15+
use crate::SourceFileEdit;
1616

1717
#[derive(Debug, PartialEq)]
1818
pub struct SsrError(String);

crates/ra_ide/src/typing.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ mod on_enter;
1717

1818
use ra_db::{FilePosition, SourceDatabase};
1919
use ra_fmt::leading_indent;
20-
use ra_ide_db::RootDatabase;
20+
use ra_ide_db::{source_change::SingleFileChange, RootDatabase};
2121
use ra_syntax::{
2222
algo::find_node_at_offset,
2323
ast::{self, AstToken},
2424
AstNode, SourceFile, TextRange, TextSize,
2525
};
26+
2627
use ra_text_edit::TextEdit;
2728

28-
use crate::{source_change::SingleFileChange, SourceChange};
29+
use crate::SourceChange;
2930

3031
pub(crate) use on_enter::on_enter;
3132

crates/ra_ide_db/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod change;
1010
pub mod defs;
1111
pub mod search;
1212
pub mod imports_locator;
13+
pub mod source_change;
1314
mod wasm_shims;
1415

1516
use std::sync::Arc;

crates/ra_ide/src/source_change.rs renamed to crates/ra_ide_db/src/source_change.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
//!
44
//! It can be viewed as a dual for `AnalysisChange`.
55
6-
use ra_db::RelativePathBuf;
7-
use ra_text_edit::TextEdit;
8-
9-
use crate::{FileId, FilePosition, SourceRootId, TextSize};
6+
use ra_db::{FileId, FilePosition, RelativePathBuf, SourceRootId};
7+
use ra_text_edit::{TextEdit, TextSize};
108

119
#[derive(Debug)]
1210
pub struct SourceChange {
11+
/// For display in the undo log in the editor
1312
pub label: String,
1413
pub source_file_edits: Vec<SourceFileEdit>,
1514
pub file_system_edits: Vec<FileSystemEdit>,
@@ -19,7 +18,7 @@ pub struct SourceChange {
1918
impl SourceChange {
2019
/// Creates a new SourceChange with the given label
2120
/// from the edits.
22-
pub(crate) fn from_edits<L: Into<String>>(
21+
pub fn from_edits<L: Into<String>>(
2322
label: L,
2423
source_file_edits: Vec<SourceFileEdit>,
2524
file_system_edits: Vec<FileSystemEdit>,
@@ -34,7 +33,7 @@ impl SourceChange {
3433

3534
/// Creates a new SourceChange with the given label,
3635
/// containing only the given `SourceFileEdits`.
37-
pub(crate) fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self {
36+
pub fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self {
3837
let label = label.into();
3938
assert!(label.starts_with(char::is_uppercase));
4039
SourceChange {
@@ -58,13 +57,13 @@ impl SourceChange {
5857

5958
/// Creates a new SourceChange with the given label,
6059
/// containing only a single `SourceFileEdit`.
61-
pub(crate) fn source_file_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self {
60+
pub fn source_file_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self {
6261
SourceChange::source_file_edits(label, vec![edit])
6362
}
6463

6564
/// Creates a new SourceChange with the given label
6665
/// from the given `FileId` and `TextEdit`
67-
pub(crate) fn source_file_edit_from<L: Into<String>>(
66+
pub fn source_file_edit_from<L: Into<String>>(
6867
label: L,
6968
file_id: FileId,
7069
edit: TextEdit,
@@ -74,18 +73,18 @@ impl SourceChange {
7473

7574
/// Creates a new SourceChange with the given label
7675
/// from the given `FileId` and `TextEdit`
77-
pub(crate) fn file_system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self {
76+
pub fn file_system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self {
7877
SourceChange::file_system_edits(label, vec![edit])
7978
}
8079

8180
/// Sets the cursor position to the given `FilePosition`
82-
pub(crate) fn with_cursor(mut self, cursor_position: FilePosition) -> Self {
81+
pub fn with_cursor(mut self, cursor_position: FilePosition) -> Self {
8382
self.cursor_position = Some(cursor_position);
8483
self
8584
}
8685

8786
/// Sets the cursor position to the given `FilePosition`
88-
pub(crate) fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self {
87+
pub fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self {
8988
self.cursor_position = cursor_position;
9089
self
9190
}
@@ -103,14 +102,14 @@ pub enum FileSystemEdit {
103102
MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf },
104103
}
105104

106-
pub(crate) struct SingleFileChange {
105+
pub struct SingleFileChange {
107106
pub label: String,
108107
pub edit: TextEdit,
109108
pub cursor_position: Option<TextSize>,
110109
}
111110

112111
impl SingleFileChange {
113-
pub(crate) fn into_source_change(self, file_id: FileId) -> SourceChange {
112+
pub fn into_source_change(self, file_id: FileId) -> SourceChange {
114113
SourceChange {
115114
label: self.label,
116115
source_file_edits: vec![SourceFileEdit { file_id, edit: self.edit }],

crates/ra_text_edit/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! so `TextEdit` is the ultimate representation of the work done by
55
//! rust-analyzer.
66
7-
use text_size::{TextRange, TextSize};
7+
pub use text_size::{TextRange, TextSize};
88

99
/// `InsertDelete` -- a single "atomic" change to text
1010
///

0 commit comments

Comments
 (0)