diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-15 09:43:08 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-15 09:43:08 +0000 |
commit | 054e2061521292a72748510f3f6cb7c8b1e8611b (patch) | |
tree | c1660a95eae4aaa57ea5546de0d81678d49f68f1 /crates/ide/src/diagnostics.rs | |
parent | dc48de28d8460903dbfc9454c8cae0e17d62e9c1 (diff) | |
parent | d5095329a1c12e93653d8de4a93f0b4f5cad4c6e (diff) |
Merge #7272
7272: Group file source edits by FileId r=matklad a=Veykril
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide/src/diagnostics.rs')
-rw-r--r-- | crates/ide/src/diagnostics.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 055c0a79c..2e5395b51 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -13,8 +13,7 @@ use hir::{ | |||
13 | diagnostics::{Diagnostic as _, DiagnosticCode, DiagnosticSinkBuilder}, | 13 | diagnostics::{Diagnostic as _, DiagnosticCode, DiagnosticSinkBuilder}, |
14 | Semantics, | 14 | Semantics, |
15 | }; | 15 | }; |
16 | use ide_db::base_db::SourceDatabase; | 16 | use ide_db::{base_db::SourceDatabase, RootDatabase}; |
17 | use ide_db::RootDatabase; | ||
18 | use itertools::Itertools; | 17 | use itertools::Itertools; |
19 | use rustc_hash::FxHashSet; | 18 | use rustc_hash::FxHashSet; |
20 | use syntax::{ | 19 | use syntax::{ |
@@ -23,7 +22,7 @@ use syntax::{ | |||
23 | }; | 22 | }; |
24 | use text_edit::TextEdit; | 23 | use text_edit::TextEdit; |
25 | 24 | ||
26 | use crate::{FileId, Label, SourceChange, SourceFileEdit}; | 25 | use crate::{FileId, Label, SourceChange}; |
27 | 26 | ||
28 | use self::fixes::DiagnosticWithFix; | 27 | use self::fixes::DiagnosticWithFix; |
29 | 28 | ||
@@ -220,7 +219,7 @@ fn check_unnecessary_braces_in_use_statement( | |||
220 | Diagnostic::hint(use_range, "Unnecessary braces in use statement".to_string()) | 219 | Diagnostic::hint(use_range, "Unnecessary braces in use statement".to_string()) |
221 | .with_fix(Some(Fix::new( | 220 | .with_fix(Some(Fix::new( |
222 | "Remove unnecessary braces", | 221 | "Remove unnecessary braces", |
223 | SourceFileEdit { file_id, edit }.into(), | 222 | SourceChange::from_text_edit(file_id, edit), |
224 | use_range, | 223 | use_range, |
225 | ))), | 224 | ))), |
226 | ); | 225 | ); |
@@ -265,13 +264,11 @@ mod tests { | |||
265 | .unwrap(); | 264 | .unwrap(); |
266 | let fix = diagnostic.fix.unwrap(); | 265 | let fix = diagnostic.fix.unwrap(); |
267 | let actual = { | 266 | let actual = { |
268 | let file_id = fix.source_change.source_file_edits.first().unwrap().file_id; | 267 | let file_id = *fix.source_change.source_file_edits.keys().next().unwrap(); |
269 | let mut actual = analysis.file_text(file_id).unwrap().to_string(); | 268 | let mut actual = analysis.file_text(file_id).unwrap().to_string(); |
270 | 269 | ||
271 | // Go from the last one to the first one, so that ranges won't be affected by previous edits. | 270 | for edit in fix.source_change.source_file_edits.values() { |
272 | // FIXME: https://github.com/rust-analyzer/rust-analyzer/issues/4901#issuecomment-644675309 | 271 | edit.apply(&mut actual); |
273 | for edit in fix.source_change.source_file_edits.iter().rev() { | ||
274 | edit.edit.apply(&mut actual); | ||
275 | } | 272 | } |
276 | actual | 273 | actual |
277 | }; | 274 | }; |
@@ -616,7 +613,7 @@ fn test_fn() { | |||
616 | Fix { | 613 | Fix { |
617 | label: "Create module", | 614 | label: "Create module", |
618 | source_change: SourceChange { | 615 | source_change: SourceChange { |
619 | source_file_edits: [], | 616 | source_file_edits: {}, |
620 | file_system_edits: [ | 617 | file_system_edits: [ |
621 | CreateFile { | 618 | CreateFile { |
622 | dst: AnchoredPathBuf { | 619 | dst: AnchoredPathBuf { |