mirror of
https://github.com/astral-sh/ruff
synced 2026-01-08 15:14:19 -05:00
Include decorators in Function and Class definition ranges (#4467)
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
use std::num::TryFromIntError;
|
||||
use std::ops::{Deref, Index, IndexMut};
|
||||
|
||||
use crate::model::SemanticModel;
|
||||
use bitflags::bitflags;
|
||||
use ruff_python_ast::helpers;
|
||||
use ruff_python_ast::source_code::Locator;
|
||||
use ruff_text_size::TextRange;
|
||||
|
||||
use crate::node::NodeId;
|
||||
@@ -108,6 +111,18 @@ impl<'a> Binding<'a> {
|
||||
}
|
||||
existing.is_definition()
|
||||
}
|
||||
|
||||
/// Returns the appropriate visual range for highlighting this binding.
|
||||
pub fn trimmed_range(&self, semantic_model: &SemanticModel, locator: &Locator) -> TextRange {
|
||||
match self.kind {
|
||||
BindingKind::ClassDefinition | BindingKind::FunctionDefinition => {
|
||||
self.source.map_or(self.range, |source| {
|
||||
helpers::identifier_range(semantic_model.stmts[source], locator)
|
||||
})
|
||||
}
|
||||
_ => self.range,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// ID uniquely identifying a [Binding] in a program.
|
||||
|
||||
Reference in New Issue
Block a user