Skip to content

Commit c5c1360

Browse files
committed
fix: make diagnostic range accommodate for macros
1 parent 4eb3d2e commit c5c1360

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use hir::{db::ExpandDatabase, Const, Function, HasSource, HirDisplay, TypeAlias};
22
use ide_db::{
33
assists::{Assist, AssistId, AssistKind},
4-
base_db::FileRange,
54
label::Label,
65
source_change::SourceChangeBuilder,
76
};
8-
use syntax::{AstNode, SyntaxKind};
97
use text_edit::TextRange;
108

119
use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
@@ -64,7 +62,7 @@ pub(crate) fn trait_impl_redundant_assoc_item(
6462
Diagnostic::new(
6563
DiagnosticCode::RustcHardError("E0407"),
6664
format!("{redundant_item_name} is not a member of trait `{trait_name}`"),
67-
FileRange { file_id: d.file_id.file_id().unwrap(), range: diagnostic_range },
65+
hir::InFile::new(d.file_id, diagnostic_range).original_node_file_range_rooted(db),
6866
)
6967
.with_fixes(quickfix_for_redundant_assoc_item(
7068
ctx,
@@ -90,12 +88,11 @@ fn quickfix_for_redundant_assoc_item(
9088
if trait_def_crate != current_crate {
9189
return None;
9290
}
91+
9392
let trait_def = d.trait_.source(db)?.value;
94-
let where_to_insert = trait_def
95-
.syntax()
96-
.descendants_with_tokens()
97-
.find(|it| it.kind() == SyntaxKind::L_CURLY)
98-
.map(|it| it.text_range())?;
93+
let l_curly = trait_def.assoc_item_list()?.l_curly_token()?.text_range();
94+
let where_to_insert =
95+
hir::InFile::new(d.file_id, l_curly).original_node_file_range_rooted(db).range;
9996

10097
Some(builder.insert(where_to_insert.end(), redundant_item_def))
10198
};

0 commit comments

Comments
 (0)