mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Make the statement
vector private on SemanticModel
(#6348)
## Summary Instead, expose these as methods, now that we can use a reasonable nomenclature on the API.
This commit is contained in:
parent
bae87fa016
commit
61d3977f95
10 changed files with 55 additions and 25 deletions
|
@ -185,7 +185,7 @@ impl<'a> Binding<'a> {
|
|||
/// Returns the range of the binding's parent.
|
||||
pub fn parent_range(&self, semantic: &SemanticModel) -> Option<TextRange> {
|
||||
self.source
|
||||
.map(|node_id| semantic.statements[node_id])
|
||||
.map(|statement_id| semantic.statement(statement_id))
|
||||
.and_then(|parent| {
|
||||
if parent.is_import_from_stmt() {
|
||||
Some(parent.range())
|
||||
|
|
|
@ -31,7 +31,7 @@ pub struct SemanticModel<'a> {
|
|||
module_path: Option<&'a [String]>,
|
||||
|
||||
/// Stack of all visited statements.
|
||||
pub statements: Nodes<'a, Stmt>,
|
||||
statements: Nodes<'a, Stmt>,
|
||||
|
||||
/// The identifier of the current statement.
|
||||
statement_id: Option<NodeId>,
|
||||
|
@ -919,6 +919,29 @@ impl<'a> SemanticModel<'a> {
|
|||
None
|
||||
}
|
||||
|
||||
/// Return the [`Nodes`] vector of all statements.
|
||||
pub const fn statements(&self) -> &Nodes<'a, Stmt> {
|
||||
&self.statements
|
||||
}
|
||||
|
||||
/// Return the [`NodeId`] corresponding to the given [`Stmt`].
|
||||
#[inline]
|
||||
pub fn statement_id(&self, statement: &Stmt) -> Option<NodeId> {
|
||||
self.statements.node_id(statement)
|
||||
}
|
||||
|
||||
/// Return the [`Stmt]` corresponding to the given [`NodeId`].
|
||||
#[inline]
|
||||
pub fn statement(&self, statement_id: NodeId) -> &'a Stmt {
|
||||
self.statements[statement_id]
|
||||
}
|
||||
|
||||
/// Given a [`Stmt`], return its parent, if any.
|
||||
#[inline]
|
||||
pub fn parent_statement(&self, statement: &'a Stmt) -> Option<&'a Stmt> {
|
||||
self.statements.parent(statement)
|
||||
}
|
||||
|
||||
/// Set the [`Globals`] for the current [`Scope`].
|
||||
pub fn set_globals(&mut self, globals: Globals<'a>) {
|
||||
// If any global bindings don't already exist in the global scope, add them.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue