diff options
Diffstat (limited to 'crates/assists')
-rw-r--r-- | crates/assists/src/assist_context.rs | 7 | ||||
-rw-r--r-- | crates/assists/src/handlers/extract_struct_from_enum_variant.rs | 30 |
2 files changed, 34 insertions, 3 deletions
diff --git a/crates/assists/src/assist_context.rs b/crates/assists/src/assist_context.rs index a17e592b0..69499ea32 100644 --- a/crates/assists/src/assist_context.rs +++ b/crates/assists/src/assist_context.rs | |||
@@ -277,9 +277,10 @@ impl AssistBuilder { | |||
277 | algo::diff(old.syntax(), new.syntax()).into_text_edit(&mut self.edit) | 277 | algo::diff(old.syntax(), new.syntax()).into_text_edit(&mut self.edit) |
278 | } | 278 | } |
279 | pub(crate) fn rewrite(&mut self, rewriter: SyntaxRewriter) { | 279 | pub(crate) fn rewrite(&mut self, rewriter: SyntaxRewriter) { |
280 | let node = rewriter.rewrite_root().unwrap(); | 280 | if let Some(node) = rewriter.rewrite_root() { |
281 | let new = rewriter.rewrite(&node); | 281 | let new = rewriter.rewrite(&node); |
282 | algo::diff(&node, &new).into_text_edit(&mut self.edit); | 282 | algo::diff(&node, &new).into_text_edit(&mut self.edit); |
283 | } | ||
283 | } | 284 | } |
284 | 285 | ||
285 | fn finish(mut self) -> SourceChange { | 286 | fn finish(mut self) -> SourceChange { |
diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index 58aadcef7..84662d832 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -382,6 +382,36 @@ fn f() { | |||
382 | ) | 382 | ) |
383 | } | 383 | } |
384 | 384 | ||
385 | #[test] | ||
386 | fn test_several_files_record() { | ||
387 | // FIXME: this should fix the usage as well! | ||
388 | check_assist( | ||
389 | extract_struct_from_enum_variant, | ||
390 | r#" | ||
391 | //- /main.rs | ||
392 | enum E { | ||
393 | <|>V { i: i32, j: i32 } | ||
394 | } | ||
395 | mod foo; | ||
396 | |||
397 | //- /foo.rs | ||
398 | use crate::E; | ||
399 | fn f() { | ||
400 | let e = E::V { i: 9, j: 2 }; | ||
401 | } | ||
402 | "#, | ||
403 | r#" | ||
404 | struct V{ pub i: i32, pub j: i32 } | ||
405 | |||
406 | enum E { | ||
407 | V(V) | ||
408 | } | ||
409 | mod foo; | ||
410 | |||
411 | "#, | ||
412 | ) | ||
413 | } | ||
414 | |||
385 | fn check_not_applicable(ra_fixture: &str) { | 415 | fn check_not_applicable(ra_fixture: &str) { |
386 | let fixture = | 416 | let fixture = |
387 | format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE); | 417 | format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE); |