Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Deduplicate annotations #16163

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/hir-expand/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl InFile<TextRange> {
}

impl<N: AstNode> InFile<N> {
pub fn original_ast_node(self, db: &dyn db::ExpandDatabase) -> Option<InRealFile<N>> {
pub fn original_ast_node_rooted(self, db: &dyn db::ExpandDatabase) -> Option<InRealFile<N>> {
// This kind of upmapping can only be achieved in attribute expanded files,
// as we don't have node inputs otherwise and therefore can't find an `N` node in the input
let file_id = match self.file_id.repr() {
Expand Down
5 changes: 2 additions & 3 deletions crates/hir/src/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,7 @@ impl<'db> SemanticsImpl<'db> {
}

/// Descend the token into its macro call if it is part of one, returning the tokens in the
/// expansion that it is associated with. If `offset` points into the token's range, it will
/// be considered for the mapping in case of inline format args.
/// expansion that it is associated with.
pub fn descend_into_macros(
&self,
mode: DescendPreference,
Expand Down Expand Up @@ -850,7 +849,7 @@ impl<'db> SemanticsImpl<'db> {
/// Attempts to map the node out of macro expanded files.
/// This only work for attribute expansions, as other ones do not have nodes as input.
pub fn original_ast_node<N: AstNode>(&self, node: N) -> Option<N> {
self.wrap_node_infile(node).original_ast_node(self.db.upcast()).map(
self.wrap_node_infile(node).original_ast_node_rooted(self.db.upcast()).map(
|InRealFile { file_id, value }| {
self.cache(find_root(value.syntax()), file_id.into());
value
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/generate_enum_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn add_variant_to_accumulator(
parent: PathParent,
) -> Option<()> {
let db = ctx.db();
let InRealFile { file_id, value: enum_node } = adt.source(db)?.original_ast_node(db)?;
let InRealFile { file_id, value: enum_node } = adt.source(db)?.original_ast_node_rooted(db)?;

acc.add(
AssistId("generate_enum_variant", AssistKind::Generate),
Expand Down
4 changes: 2 additions & 2 deletions crates/ide-db/src/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ fn source_edit_from_def(
if let Definition::Local(local) = def {
let mut file_id = None;
for source in local.sources(sema.db) {
let source = match source.source.clone().original_ast_node(sema.db) {
let source = match source.source.clone().original_ast_node_rooted(sema.db) {
Some(source) => source,
None => match source
.source
Expand Down Expand Up @@ -560,7 +560,7 @@ fn source_edit_from_def(
}
} else {
// Foo { ref mut field } -> Foo { field: ref mut new_name }
// ^ insert `field: `
// original_ast_node_rootedd: `
// ^^^^^ replace this with `new_name`
edit.insert(
pat.syntax().text_range().start(),
Expand Down