mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00
[red-knot] Avoid Ranged
for definition target range (#15118)
## Summary
Ref:
3533d7f5b4 (r150651102)
This PR removes the `Ranged` implementation on `DefinitionKind` and
instead uses a method called `target_range` to avoid any confusion about
what range this is for i.e., it's not the range of the node that
represents the definition.
This commit is contained in:
parent
113c804a62
commit
03bb9425df
2 changed files with 10 additions and 6 deletions
|
@ -473,8 +473,14 @@ pub enum DefinitionKind<'db> {
|
|||
TypeVarTuple(AstNodeRef<ast::TypeParamTypeVarTuple>),
|
||||
}
|
||||
|
||||
impl Ranged for DefinitionKind<'_> {
|
||||
fn range(&self) -> TextRange {
|
||||
impl DefinitionKind<'_> {
|
||||
/// Returns the [`TextRange`] of the definition target.
|
||||
///
|
||||
/// A definition target would mainly be the node representing the symbol being defined i.e.,
|
||||
/// [`ast::ExprName`] or [`ast::Identifier`] but could also be other nodes.
|
||||
///
|
||||
/// This is mainly used for logging and debugging purposes.
|
||||
pub(crate) fn target_range(&self) -> TextRange {
|
||||
match self {
|
||||
DefinitionKind::Import(alias) => alias.range(),
|
||||
DefinitionKind::ImportFrom(import) => import.alias().range(),
|
||||
|
@ -498,9 +504,7 @@ impl Ranged for DefinitionKind<'_> {
|
|||
DefinitionKind::TypeVarTuple(type_var_tuple) => type_var_tuple.name.range(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DefinitionKind<'_> {
|
||||
pub(crate) fn category(&self) -> DefinitionCategory {
|
||||
match self {
|
||||
// functions, classes, and imports always bind, and we consider them declarations
|
||||
|
|
|
@ -131,7 +131,7 @@ pub(crate) fn infer_definition_types<'db>(
|
|||
let file = definition.file(db);
|
||||
let _span = tracing::trace_span!(
|
||||
"infer_definition_types",
|
||||
range = ?definition.kind(db).range(),
|
||||
range = ?definition.kind(db).target_range(),
|
||||
file = %file.path(db)
|
||||
)
|
||||
.entered();
|
||||
|
@ -154,7 +154,7 @@ pub(crate) fn infer_deferred_types<'db>(
|
|||
let _span = tracing::trace_span!(
|
||||
"infer_deferred_types",
|
||||
definition = ?definition.as_id(),
|
||||
range = ?definition.kind(db).range(),
|
||||
range = ?definition.kind(db).target_range(),
|
||||
file = %file.path(db)
|
||||
)
|
||||
.entered();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue