mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Merge #4802
4802: Simplify r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
3999bbba1b
@ -21,7 +21,7 @@ use ra_syntax::{
|
|||||||
};
|
};
|
||||||
use ra_text_edit::{TextEdit, TextEditBuilder};
|
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)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum Severity {
|
pub enum Severity {
|
||||||
@ -115,7 +115,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
|
|||||||
let node = d.ast(db);
|
let node = d.ast(db);
|
||||||
let replacement = format!("Ok({})", node.syntax());
|
let replacement = format!("Ok({})", node.syntax());
|
||||||
let edit = TextEdit::replace(node.syntax().text_range(), replacement);
|
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);
|
let fix = Fix::new("Wrap with ok", source_change);
|
||||||
res.borrow_mut().push(Diagnostic {
|
res.borrow_mut().push(Diagnostic {
|
||||||
range: sema.diagnostics_range(d).range,
|
range: sema.diagnostics_range(d).range,
|
||||||
|
@ -503,7 +503,7 @@ impl Analysis {
|
|||||||
) -> Cancelable<Result<SourceChange, SsrError>> {
|
) -> Cancelable<Result<SourceChange, SsrError>> {
|
||||||
self.with_db(|db| {
|
self.with_db(|db| {
|
||||||
let edits = ssr::parse_search_replace(query, parse_only, db)?;
|
let edits = ssr::parse_search_replace(query, parse_only, db)?;
|
||||||
Ok(SourceChange::source_file_edits(edits))
|
Ok(SourceChange::from(edits))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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(
|
fn text_edit_from_self_param(
|
||||||
@ -234,7 +234,7 @@ fn rename_self_to_param(
|
|||||||
let range = ast::SelfParam::cast(self_token.parent())
|
let range = ast::SelfParam::cast(self_token.parent())
|
||||||
.map_or(self_token.text_range(), |p| p.syntax().text_range());
|
.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(
|
fn rename_reference(
|
||||||
@ -253,7 +253,7 @@ fn rename_reference(
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(RangeInfo::new(range, SourceChange::source_file_edits(edit)))
|
Some(RangeInfo::new(range, SourceChange::from(edit)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -17,7 +17,7 @@ mod on_enter;
|
|||||||
|
|
||||||
use ra_db::{FilePosition, SourceDatabase};
|
use ra_db::{FilePosition, SourceDatabase};
|
||||||
use ra_fmt::leading_indent;
|
use ra_fmt::leading_indent;
|
||||||
use ra_ide_db::RootDatabase;
|
use ra_ide_db::{source_change::SourceFileEdit, RootDatabase};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
algo::find_node_at_offset,
|
algo::find_node_at_offset,
|
||||||
ast::{self, AstToken},
|
ast::{self, AstToken},
|
||||||
@ -47,8 +47,8 @@ pub(crate) fn on_char_typed(
|
|||||||
assert!(TRIGGER_CHARS.contains(char_typed));
|
assert!(TRIGGER_CHARS.contains(char_typed));
|
||||||
let file = &db.parse(position.file_id).tree();
|
let file = &db.parse(position.file_id).tree();
|
||||||
assert_eq!(file.syntax().text().char_at(position.offset), Some(char_typed));
|
assert_eq!(file.syntax().text().char_at(position.offset), Some(char_typed));
|
||||||
let text_edit = on_char_typed_inner(file, position.offset, char_typed)?;
|
let edit = on_char_typed_inner(file, position.offset, char_typed)?;
|
||||||
Some(SourceChange::source_file_edit_from(position.file_id, text_edit))
|
Some(SourceFileEdit { file_id: position.file_id, edit }.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_char_typed_inner(file: &SourceFile, offset: TextSize, char_typed: char) -> Option<TextEdit> {
|
fn on_char_typed_inner(file: &SourceFile, offset: TextSize, char_typed: char) -> Option<TextEdit> {
|
||||||
|
@ -22,17 +22,6 @@ impl SourceChange {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
SourceChange { source_file_edits, file_system_edits, is_snippet: false }
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
@ -43,11 +32,13 @@ pub struct SourceFileEdit {
|
|||||||
|
|
||||||
impl From<SourceFileEdit> for SourceChange {
|
impl From<SourceFileEdit> for SourceChange {
|
||||||
fn from(edit: SourceFileEdit) -> SourceChange {
|
fn from(edit: SourceFileEdit) -> SourceChange {
|
||||||
SourceChange {
|
vec![edit].into()
|
||||||
source_file_edits: vec![edit],
|
|
||||||
file_system_edits: Vec::new(),
|
|
||||||
is_snippet: false,
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user