mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Group file source edits by FileId
This commit is contained in:
parent
f88f3d6885
commit
f51457a643
15 changed files with 188 additions and 180 deletions
|
@ -13,8 +13,7 @@ use hir::{
|
|||
diagnostics::{Diagnostic as _, DiagnosticCode, DiagnosticSinkBuilder},
|
||||
Semantics,
|
||||
};
|
||||
use ide_db::base_db::SourceDatabase;
|
||||
use ide_db::RootDatabase;
|
||||
use ide_db::{base_db::SourceDatabase, source_change::SourceFileEdits, RootDatabase};
|
||||
use itertools::Itertools;
|
||||
use rustc_hash::FxHashSet;
|
||||
use syntax::{
|
||||
|
@ -23,7 +22,7 @@ use syntax::{
|
|||
};
|
||||
use text_edit::TextEdit;
|
||||
|
||||
use crate::{FileId, Label, SourceChange, SourceFileEdit};
|
||||
use crate::{FileId, Label, SourceChange};
|
||||
|
||||
use self::fixes::DiagnosticWithFix;
|
||||
|
||||
|
@ -220,7 +219,7 @@ fn check_unnecessary_braces_in_use_statement(
|
|||
Diagnostic::hint(use_range, "Unnecessary braces in use statement".to_string())
|
||||
.with_fix(Some(Fix::new(
|
||||
"Remove unnecessary braces",
|
||||
SourceFileEdit { file_id, edit }.into(),
|
||||
SourceFileEdits::from_text_edit(file_id, edit).into(),
|
||||
use_range,
|
||||
))),
|
||||
);
|
||||
|
@ -265,13 +264,11 @@ mod tests {
|
|||
.unwrap();
|
||||
let fix = diagnostic.fix.unwrap();
|
||||
let actual = {
|
||||
let file_id = fix.source_change.source_file_edits.first().unwrap().file_id;
|
||||
let file_id = *fix.source_change.source_file_edits.edits.keys().next().unwrap();
|
||||
let mut actual = analysis.file_text(file_id).unwrap().to_string();
|
||||
|
||||
// Go from the last one to the first one, so that ranges won't be affected by previous edits.
|
||||
// FIXME: https://github.com/rust-analyzer/rust-analyzer/issues/4901#issuecomment-644675309
|
||||
for edit in fix.source_change.source_file_edits.iter().rev() {
|
||||
edit.edit.apply(&mut actual);
|
||||
for edit in fix.source_change.source_file_edits.edits.values() {
|
||||
edit.apply(&mut actual);
|
||||
}
|
||||
actual
|
||||
};
|
||||
|
@ -616,7 +613,9 @@ fn test_fn() {
|
|||
Fix {
|
||||
label: "Create module",
|
||||
source_change: SourceChange {
|
||||
source_file_edits: [],
|
||||
source_file_edits: SourceFileEdits {
|
||||
edits: {},
|
||||
},
|
||||
file_system_edits: [
|
||||
CreateFile {
|
||||
dst: AnchoredPathBuf {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue