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