aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-11-09 15:40:41 +0000
committerAleksey Kladov <[email protected]>2020-11-09 15:59:57 +0000
commit4a16c228e7a3f69b7ac102be5c35ab6d3af9c827 (patch)
tree237bfb02cc889ef0a70ea3417c965d509815c470 /crates/assists/src
parent6b92cc4384361185f990cb614e5007a62f13523c (diff)
Fix panic when extracting struct
Diffstat (limited to 'crates/assists/src')
-rw-r--r--crates/assists/src/assist_context.rs7
-rw-r--r--crates/assists/src/handlers/extract_struct_from_enum_variant.rs30
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
392enum E {
393 <|>V { i: i32, j: i32 }
394}
395mod foo;
396
397//- /foo.rs
398use crate::E;
399fn f() {
400 let e = E::V { i: 9, j: 2 };
401}
402"#,
403 r#"
404struct V{ pub i: i32, pub j: i32 }
405
406enum E {
407 V(V)
408}
409mod 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);