diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-11-09 16:01:19 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-11-09 16:01:19 +0000 |
commit | 2fd29d04708a19ef30af67bf5e231293d2deaf93 (patch) | |
tree | 237bfb02cc889ef0a70ea3417c965d509815c470 /crates/assists | |
parent | 6b92cc4384361185f990cb614e5007a62f13523c (diff) | |
parent | 4a16c228e7a3f69b7ac102be5c35ab6d3af9c827 (diff) |
Merge #6510
6510: Fix panic when extracting struct r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
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); |