mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-09 13:18:52 +00:00
Include decorators in Function
and Class
definition ranges (#4467)
This commit is contained in:
parent
9308e939f4
commit
daadd24bde
11 changed files with 198 additions and 136 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue