4802: Simplify r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-06-08 19:49:04 +00:00 committed by GitHub
commit 3999bbba1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 25 deletions

View file

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

View file

@ -503,7 +503,7 @@ impl Analysis {
) -> Cancelable<Result<SourceChange, SsrError>> {
self.with_db(|db| {
let edits = ssr::parse_search_replace(query, parse_only, db)?;
Ok(SourceChange::source_file_edits(edits))
Ok(SourceChange::from(edits))
})
}

View file

@ -171,7 +171,7 @@ fn rename_to_self(db: &RootDatabase, position: FilePosition) -> Option<RangeInfo
),
});
Some(RangeInfo::new(range, SourceChange::source_file_edits(edits)))
Some(RangeInfo::new(range, SourceChange::from(edits)))
}
fn text_edit_from_self_param(
@ -234,7 +234,7 @@ fn rename_self_to_param(
let range = ast::SelfParam::cast(self_token.parent())
.map_or(self_token.text_range(), |p| p.syntax().text_range());
Some(RangeInfo::new(range, SourceChange::source_file_edits(edits)))
Some(RangeInfo::new(range, SourceChange::from(edits)))
}
fn rename_reference(
@ -253,7 +253,7 @@ fn rename_reference(
return None;
}
Some(RangeInfo::new(range, SourceChange::source_file_edits(edit)))
Some(RangeInfo::new(range, SourceChange::from(edit)))
}
#[cfg(test)]

View file

@ -17,7 +17,7 @@ mod on_enter;
use ra_db::{FilePosition, SourceDatabase};
use ra_fmt::leading_indent;
use ra_ide_db::RootDatabase;
use ra_ide_db::{source_change::SourceFileEdit, RootDatabase};
use ra_syntax::{
algo::find_node_at_offset,
ast::{self, AstToken},
@ -47,8 +47,8 @@ pub(crate) fn on_char_typed(
assert!(TRIGGER_CHARS.contains(char_typed));
let file = &db.parse(position.file_id).tree();
assert_eq!(file.syntax().text().char_at(position.offset), Some(char_typed));
let text_edit = on_char_typed_inner(file, position.offset, char_typed)?;
Some(SourceChange::source_file_edit_from(position.file_id, text_edit))
let edit = on_char_typed_inner(file, position.offset, char_typed)?;
Some(SourceFileEdit { file_id: position.file_id, edit }.into())
}
fn on_char_typed_inner(file: &SourceFile, offset: TextSize, char_typed: char) -> Option<TextEdit> {

View file

@ -22,17 +22,6 @@ impl SourceChange {
) -> Self {
SourceChange { source_file_edits, file_system_edits, is_snippet: false }
}
/// Creates a new SourceChange with the given label,
/// containing only the given `SourceFileEdits`.
pub fn source_file_edits(edits: Vec<SourceFileEdit>) -> Self {
SourceChange { source_file_edits: edits, file_system_edits: vec![], is_snippet: false }
}
/// Creates a new SourceChange with the given label
/// from the given `FileId` and `TextEdit`
pub fn source_file_edit_from(file_id: FileId, edit: TextEdit) -> Self {
SourceFileEdit { file_id, edit }.into()
}
}
#[derive(Debug, Clone)]
@ -43,11 +32,13 @@ pub struct SourceFileEdit {
impl From<SourceFileEdit> for SourceChange {
fn from(edit: SourceFileEdit) -> SourceChange {
SourceChange {
source_file_edits: vec![edit],
file_system_edits: Vec::new(),
is_snippet: false,
}
vec![edit].into()
}
}
impl From<Vec<SourceFileEdit>> for SourceChange {
fn from(source_file_edits: Vec<SourceFileEdit>) -> SourceChange {
SourceChange { source_file_edits, file_system_edits: Vec::new(), is_snippet: false }
}
}