Skip to content

Commit 3999bbb

Browse files
bors[bot]matklad
andauthored
Merge #4802
4802: Simplify r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 47e742f + 2a42904 commit 3999bbb

File tree

5 files changed

+16
-25
lines changed

5 files changed

+16
-25
lines changed

crates/ra_ide/src/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use ra_syntax::{
2121
};
2222
use ra_text_edit::{TextEdit, TextEditBuilder};
2323

24-
use crate::{Diagnostic, FileId, FileSystemEdit, Fix, SourceChange, SourceFileEdit};
24+
use crate::{Diagnostic, FileId, FileSystemEdit, Fix, SourceFileEdit};
2525

2626
#[derive(Debug, Copy, Clone)]
2727
pub enum Severity {
@@ -115,7 +115,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
115115
let node = d.ast(db);
116116
let replacement = format!("Ok({})", node.syntax());
117117
let edit = TextEdit::replace(node.syntax().text_range(), replacement);
118-
let source_change = SourceChange::source_file_edit_from(file_id, edit);
118+
let source_change = SourceFileEdit { file_id, edit }.into();
119119
let fix = Fix::new("Wrap with ok", source_change);
120120
res.borrow_mut().push(Diagnostic {
121121
range: sema.diagnostics_range(d).range,

crates/ra_ide/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl Analysis {
503503
) -> Cancelable<Result<SourceChange, SsrError>> {
504504
self.with_db(|db| {
505505
let edits = ssr::parse_search_replace(query, parse_only, db)?;
506-
Ok(SourceChange::source_file_edits(edits))
506+
Ok(SourceChange::from(edits))
507507
})
508508
}
509509

crates/ra_ide/src/references/rename.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn rename_to_self(db: &RootDatabase, position: FilePosition) -> Option<RangeInfo
171171
),
172172
});
173173

174-
Some(RangeInfo::new(range, SourceChange::source_file_edits(edits)))
174+
Some(RangeInfo::new(range, SourceChange::from(edits)))
175175
}
176176

177177
fn text_edit_from_self_param(
@@ -234,7 +234,7 @@ fn rename_self_to_param(
234234
let range = ast::SelfParam::cast(self_token.parent())
235235
.map_or(self_token.text_range(), |p| p.syntax().text_range());
236236

237-
Some(RangeInfo::new(range, SourceChange::source_file_edits(edits)))
237+
Some(RangeInfo::new(range, SourceChange::from(edits)))
238238
}
239239

240240
fn rename_reference(
@@ -253,7 +253,7 @@ fn rename_reference(
253253
return None;
254254
}
255255

256-
Some(RangeInfo::new(range, SourceChange::source_file_edits(edit)))
256+
Some(RangeInfo::new(range, SourceChange::from(edit)))
257257
}
258258

259259
#[cfg(test)]

crates/ra_ide/src/typing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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::SourceFileEdit, RootDatabase};
2121
use ra_syntax::{
2222
algo::find_node_at_offset,
2323
ast::{self, AstToken},
@@ -47,8 +47,8 @@ pub(crate) fn on_char_typed(
4747
assert!(TRIGGER_CHARS.contains(char_typed));
4848
let file = &db.parse(position.file_id).tree();
4949
assert_eq!(file.syntax().text().char_at(position.offset), Some(char_typed));
50-
let text_edit = on_char_typed_inner(file, position.offset, char_typed)?;
51-
Some(SourceChange::source_file_edit_from(position.file_id, text_edit))
50+
let edit = on_char_typed_inner(file, position.offset, char_typed)?;
51+
Some(SourceFileEdit { file_id: position.file_id, edit }.into())
5252
}
5353

5454
fn on_char_typed_inner(file: &SourceFile, offset: TextSize, char_typed: char) -> Option<TextEdit> {

crates/ra_ide_db/src/source_change.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ impl SourceChange {
2222
) -> Self {
2323
SourceChange { source_file_edits, file_system_edits, is_snippet: false }
2424
}
25-
26-
/// Creates a new SourceChange with the given label,
27-
/// containing only the given `SourceFileEdits`.
28-
pub fn source_file_edits(edits: Vec<SourceFileEdit>) -> Self {
29-
SourceChange { source_file_edits: edits, file_system_edits: vec![], is_snippet: false }
30-
}
31-
/// Creates a new SourceChange with the given label
32-
/// from the given `FileId` and `TextEdit`
33-
pub fn source_file_edit_from(file_id: FileId, edit: TextEdit) -> Self {
34-
SourceFileEdit { file_id, edit }.into()
35-
}
3625
}
3726

3827
#[derive(Debug, Clone)]
@@ -43,11 +32,13 @@ pub struct SourceFileEdit {
4332

4433
impl From<SourceFileEdit> for SourceChange {
4534
fn from(edit: SourceFileEdit) -> SourceChange {
46-
SourceChange {
47-
source_file_edits: vec![edit],
48-
file_system_edits: Vec::new(),
49-
is_snippet: false,
50-
}
35+
vec![edit].into()
36+
}
37+
}
38+
39+
impl From<Vec<SourceFileEdit>> for SourceChange {
40+
fn from(source_file_edits: Vec<SourceFileEdit>) -> SourceChange {
41+
SourceChange { source_file_edits, file_system_edits: Vec::new(), is_snippet: false }
5142
}
5243
}
5344

0 commit comments

Comments
 (0)