[ty] Fix rename/references to find all overloaded function definitions
This fixes an issue where renaming an overloaded function only renamed a single definition instead of all overloads and the implementation. The fix addresses two issues: 1. `navigation_targets_match` in references.rs now checks if any current target matches any of the target definitions (not just the first). This is important for overloaded functions where each overload is a separate definition but they all refer to the same logical symbol. 2. `get_definition_targets` for FunctionDef in goto.rs now uses a new `definitions_for_name_in_scope` function that returns all definitions with the same name in the same scope, not just the single function's definition. The new `definitions_for_name_in_scope` function in ide_support.rs takes a file and scope directly, bypassing the scope lookup from a node, which allows proper handling of function name identifiers. This also fixes property getter/setter/deleter renaming and submodule import reference finding, which now correctly identify all related definitions.
This commit is contained in:
@@ -30,8 +30,8 @@ pub use suppression::create_suppression_fix;
|
||||
pub use types::DisplaySettings;
|
||||
pub use types::ide_support::{
|
||||
ImportAliasResolution, ResolvedDefinition, definitions_for_attribute, definitions_for_bin_op,
|
||||
definitions_for_imported_symbol, definitions_for_name, definitions_for_unary_op,
|
||||
map_stub_definition,
|
||||
definitions_for_imported_symbol, definitions_for_name, definitions_for_name_in_scope,
|
||||
definitions_for_unary_op, map_stub_definition,
|
||||
};
|
||||
|
||||
pub mod ast_node_ref;
|
||||
|
||||
@@ -33,7 +33,7 @@ pub struct Definition<'db> {
|
||||
pub file: File,
|
||||
|
||||
/// The scope in which the definition occurs.
|
||||
pub(crate) file_scope: FileScopeId,
|
||||
pub file_scope: FileScopeId,
|
||||
|
||||
/// The place ID of the definition.
|
||||
pub(crate) place: ScopedPlaceId,
|
||||
|
||||
@@ -190,6 +190,53 @@ pub fn definitions_for_name<'db>(
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns all definitions for a name in a specific scope.
|
||||
/// This is useful when you have a Definition and want to find all other definitions
|
||||
/// with the same name in its scope (e.g., for overloaded functions).
|
||||
pub fn definitions_for_name_in_scope<'db>(
|
||||
db: &'db dyn Db,
|
||||
file: ruff_db::files::File,
|
||||
file_scope_id: crate::semantic_index::scope::FileScopeId,
|
||||
name_str: &str,
|
||||
alias_resolution: ImportAliasResolution,
|
||||
) -> Vec<ResolvedDefinition<'db>> {
|
||||
let index = semantic_index(db, file);
|
||||
let place_table = index.place_table(file_scope_id);
|
||||
|
||||
let Some(symbol_id) = place_table.symbol_id(name_str) else {
|
||||
return vec![];
|
||||
};
|
||||
|
||||
let use_def_map = index.use_def_map(file_scope_id);
|
||||
let mut all_definitions = FxIndexSet::default();
|
||||
|
||||
// Get all definitions (both bindings and declarations) for this symbol
|
||||
let bindings = use_def_map.all_reachable_symbol_bindings(symbol_id);
|
||||
let declarations = use_def_map.all_reachable_symbol_declarations(symbol_id);
|
||||
|
||||
for binding in bindings {
|
||||
if let Some(def) = binding.binding.definition() {
|
||||
all_definitions.insert(def);
|
||||
}
|
||||
}
|
||||
|
||||
for declaration in declarations {
|
||||
if let Some(def) = declaration.declaration.definition() {
|
||||
all_definitions.insert(def);
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve import definitions to their targets
|
||||
let mut resolved_definitions = Vec::new();
|
||||
|
||||
for definition in &all_definitions {
|
||||
let resolved = resolve_definition(db, *definition, Some(name_str), alias_resolution);
|
||||
resolved_definitions.extend(resolved);
|
||||
}
|
||||
|
||||
resolved_definitions
|
||||
}
|
||||
|
||||
fn is_float_or_complex_annotation(db: &dyn Db, ty: UnionType, name: &str) -> bool {
|
||||
let float_or_complex_ty = match name {
|
||||
"float" => UnionType::from_elements(
|
||||
|
||||
Reference in New Issue
Block a user