diff options
| author | Young-Flash <dongyang@apache.org> | 2024-01-02 21:30:13 +0800 |
|---|---|---|
| committer | Young-Flash <dongyang@apache.org> | 2024-01-02 21:30:13 +0800 |
| commit | 91bd59682a8975e7f3699b132103548c7409ed1c (patch) | |
| tree | a5e39d4f18d30c73dbc87acd6b41fc7f5841c485 | |
| parent | 481fab1591a32f5886043263611bd87b1acc6719 (diff) | |
| download | rust-91bd59682a8975e7f3699b132103548c7409ed1c.tar.gz rust-91bd59682a8975e7f3699b132103548c7409ed1c.zip | |
fix: make editing range accommodate for macros
| -rw-r--r-- | crates/ide-diagnostics/src/handlers/unresolved_method.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/crates/ide-diagnostics/src/handlers/unresolved_method.rs b/crates/ide-diagnostics/src/handlers/unresolved_method.rs index 6fd89b33a17..60a45a05a4a 100644 --- a/crates/ide-diagnostics/src/handlers/unresolved_method.rs +++ b/crates/ide-diagnostics/src/handlers/unresolved_method.rs @@ -1,4 +1,4 @@ -use hir::{db::ExpandDatabase, AssocItem, HirDisplay}; +use hir::{db::ExpandDatabase, AssocItem, HirDisplay, InFile}; use ide_db::{ assists::{Assist, AssistId, AssistKind}, base_db::FileRange, @@ -121,7 +121,9 @@ fn assoc_func_fix(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedMethodCall) - let expr: ast::Expr = expr_ptr.value.to_node(&root); let call = ast::MethodCallExpr::cast(expr.syntax().clone())?; - let range = call.syntax().text_range(); + let range = InFile::new(expr_ptr.file_id, call.syntax().text_range()) + .original_node_file_range_rooted(db) + .range; let receiver = call.receiver()?; let receiver_type = &ctx.sema.type_of_expr(&receiver)?.original; @@ -241,7 +243,7 @@ impl A { fn main() { let a = A{}; a.hello(); - // ^^^^^^^^^ 💡 error: no method `hello` on type `A`, but an associated function with a similar name exists + // ^^^^^ 💡 error: no method `hello` on type `A`, but an associated function with a similar name exists } "#, ); |
