[ty] Re-arrange imports in symbol extraction

I like using a qualified `ast::` prefix for things from
`ruff_python_ast`, so switch over to that convention.
This commit is contained in:
Andrew Gallant 2025-10-29 15:20:48 -04:00
parent 765257bdce
commit 39f43d888d
No known key found for this signature in database
GPG Key ID: 5518C8B38E0693E0
1 changed files with 11 additions and 9 deletions

View File

@ -9,8 +9,8 @@ use regex::Regex;
use ruff_db::files::File;
use ruff_db::parsed::parsed_module;
use ruff_index::{IndexVec, newtype_index};
use ruff_python_ast as ast;
use ruff_python_ast::visitor::source_order::{self, SourceOrderVisitor};
use ruff_python_ast::{Expr, Stmt};
use ruff_text_size::{Ranged, TextRange};
use ty_project::Db;
@ -382,7 +382,7 @@ struct SymbolVisitor {
}
impl SymbolVisitor {
fn visit_body(&mut self, body: &[Stmt]) {
fn visit_body(&mut self, body: &[ast::Stmt]) {
for stmt in body {
self.visit_stmt(stmt);
}
@ -423,9 +423,9 @@ impl SymbolVisitor {
}
impl SourceOrderVisitor<'_> for SymbolVisitor {
fn visit_stmt(&mut self, stmt: &Stmt) {
fn visit_stmt(&mut self, stmt: &ast::Stmt) {
match stmt {
Stmt::FunctionDef(func_def) => {
ast::Stmt::FunctionDef(func_def) => {
let kind = if self
.iter_symbol_stack()
.any(|s| s.kind == SymbolKind::Class)
@ -467,7 +467,7 @@ impl SourceOrderVisitor<'_> for SymbolVisitor {
self.pop_symbol();
}
Stmt::ClassDef(class_def) => {
ast::Stmt::ClassDef(class_def) => {
let symbol = SymbolTree {
parent: None,
name: class_def.name.to_string(),
@ -487,13 +487,15 @@ impl SourceOrderVisitor<'_> for SymbolVisitor {
self.pop_symbol();
}
Stmt::Assign(assign) => {
ast::Stmt::Assign(assign) => {
// Include assignments only when we're in global or class scope
if self.in_function {
return;
}
for target in &assign.targets {
let Expr::Name(name) = target else { continue };
let ast::Expr::Name(name) = target else {
continue;
};
let kind = if Self::is_constant_name(name.id.as_str()) {
SymbolKind::Constant
} else if self
@ -516,12 +518,12 @@ impl SourceOrderVisitor<'_> for SymbolVisitor {
}
}
Stmt::AnnAssign(ann_assign) => {
ast::Stmt::AnnAssign(ann_assign) => {
// Include assignments only when we're in global or class scope
if self.in_function {
return;
}
let Expr::Name(name) = &*ann_assign.target else {
let ast::Expr::Name(name) = &*ann_assign.target else {
return;
};
let kind = if Self::is_constant_name(name.id.as_str()) {