mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Merge #10587
10587: fix: Fix `add_missing_match_arm` panicking on failed upmapping r=Veykril a=Veykril Closes https://github.com/rust-analyzer/rust-analyzer/issues/10580#issuecomment-946170475 Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
e77fc481ad
1 changed files with 7 additions and 12 deletions
|
@ -6,7 +6,6 @@ use ide_db::helpers::{mod_path_to_ast, FamousDefs};
|
||||||
use ide_db::RootDatabase;
|
use ide_db::RootDatabase;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use syntax::ast::{self, make, AstNode, HasName, MatchArm, MatchArmList, MatchExpr, Pat};
|
use syntax::ast::{self, make, AstNode, HasName, MatchArm, MatchArmList, MatchExpr, Pat};
|
||||||
use syntax::TextRange;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
utils::{self, render_snippet, Cursor},
|
utils::{self, render_snippet, Cursor},
|
||||||
|
@ -40,21 +39,15 @@ use crate::{
|
||||||
pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
||||||
let match_expr = ctx.find_node_at_offset_with_descend::<ast::MatchExpr>()?;
|
let match_expr = ctx.find_node_at_offset_with_descend::<ast::MatchExpr>()?;
|
||||||
let match_arm_list = match_expr.match_arm_list()?;
|
let match_arm_list = match_expr.match_arm_list()?;
|
||||||
let target_range: TextRange;
|
let target_range = ctx.sema.original_range(match_expr.syntax()).range;
|
||||||
|
|
||||||
if let None = cursor_at_trivial_match_arm_list(&ctx, &match_expr, &match_arm_list) {
|
if let None = cursor_at_trivial_match_arm_list(&ctx, &match_expr, &match_arm_list) {
|
||||||
target_range = TextRange::new(
|
let arm_list_range = ctx.sema.original_range(match_arm_list.syntax()).range;
|
||||||
ctx.sema.original_range(match_expr.syntax()).range.start(),
|
let cursor_in_range = arm_list_range.contains_range(ctx.selection_trimmed());
|
||||||
ctx.sema.original_range(match_arm_list.syntax()).range.start(),
|
if cursor_in_range {
|
||||||
);
|
|
||||||
|
|
||||||
let cursor_in_range = target_range.contains_range(ctx.selection_trimmed());
|
|
||||||
if !cursor_in_range {
|
|
||||||
cov_mark::hit!(not_applicable_outside_of_range_right);
|
cov_mark::hit!(not_applicable_outside_of_range_right);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
target_range = ctx.sema.original_range(match_expr.syntax()).range;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let expr = match_expr.expr()?;
|
let expr = match_expr.expr()?;
|
||||||
|
@ -953,7 +946,9 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
"match E::X ",
|
"match E::X {
|
||||||
|
E::X => {}
|
||||||
|
}",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue