Make Definition a salsa-ingredient (#12151)

This commit is contained in:
Micha Reiser 2024-07-04 08:46:08 +02:00 committed by GitHub
parent e6e09ea93a
commit 3ce8b9fcae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 499 additions and 707 deletions

View file

@ -4,9 +4,8 @@ use ruff_python_ast as ast;
use ruff_python_ast::{Expr, ExpressionRef, StmtClassDef};
use crate::semantic_index::ast_ids::HasScopedAstId;
use crate::semantic_index::definition::Definition;
use crate::semantic_index::symbol::PublicSymbolId;
use crate::semantic_index::{public_symbol, semantic_index, NodeWithScopeKey};
use crate::semantic_index::{public_symbol, semantic_index};
use crate::types::{infer_types, public_symbol_ty, Type, TypingContext};
use crate::Db;
@ -143,12 +142,10 @@ impl HasTy for ast::Expr {
impl HasTy for ast::StmtFunctionDef {
fn ty<'db>(&self, model: &SemanticModel<'db>) -> Type<'db> {
let index = semantic_index(model.db, model.file);
let definition_scope = index.definition_scope(NodeWithScopeKey::from(self));
let scope = definition_scope.to_scope_id(model.db, model.file);
let definition = index.definition(self);
let scope = definition.scope(model.db).to_scope_id(model.db, model.file);
let types = infer_types(model.db, scope);
let definition = Definition::FunctionDef(self.scoped_ast_id(model.db, scope));
types.definition_ty(definition)
}
@ -157,11 +154,10 @@ impl HasTy for ast::StmtFunctionDef {
impl HasTy for StmtClassDef {
fn ty<'db>(&self, model: &SemanticModel<'db>) -> Type<'db> {
let index = semantic_index(model.db, model.file);
let definition_scope = index.definition_scope(NodeWithScopeKey::from(self));
let scope = definition_scope.to_scope_id(model.db, model.file);
let definition = index.definition(self);
let scope = definition.scope(model.db).to_scope_id(model.db, model.file);
let types = infer_types(model.db, scope);
let definition = Definition::ClassDef(self.scoped_ast_id(model.db, scope));
types.definition_ty(definition)
}