Skip to content

Commit

Permalink
Verify we are not in a macro attempt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
wyatt-herkamp committed Apr 15, 2024
1 parent 0faa294 commit 701068d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions crates/ide-diagnostics/src/handlers/unused_variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ pub(crate) fn unused_variables(
}
let diagnostic_range = ctx.sema.diagnostics_display_range(ast);
// The range for the Actual Name. We don't want to replace the entire declarition. Using the diagnostic range causes issues within in Array Destructuring.
let name_range =
d.local.primary_source(ctx.sema.db).name().map(|v| v.syntax().value.text_range())?;
// Make sure we are within the diagnostic range for the variable
if !diagnostic_range.range.contains_range(name_range) {
let name_range = d
.local
.primary_source(ctx.sema.db)
.name()
.map(|v| v.syntax().original_file_range_rooted(ctx.sema.db))
.filter(|it| Some(it.file_id) == ast.file_id.file_id())?;
if !diagnostic_range.range.contains_range(name_range.range) {
return None;
}
let var_name = d.local.name(ctx.sema.db);
Expand All @@ -42,7 +45,7 @@ pub(crate) fn unused_variables(
.with_fixes(fixes(
ctx.sema.db,
var_name,
name_range,
name_range.range,
diagnostic_range,
ast.file_id.is_macro(),
))
Expand Down

0 comments on commit 701068d

Please sign in to comment.