From 697998f836075683f79c95e3276244da6788accd Mon Sep 17 00:00:00 2001 From: David Peter Date: Wed, 8 Oct 2025 17:45:28 +0200 Subject: [PATCH] [ty] Do not re-export `ide_support` attributes from `types` (#20769) ## Summary The `types` module currently re-exports a lot of functions and data types from `types::ide_support`. One of these is called `Member`, a name that is overloaded several times already. And I'd like to add one more `Member` struct soon. Making the whole `ide_support` module public seems cleaner to me, anyway. ## Test Plan Pure refactoring. --- crates/ty_ide/src/goto.rs | 6 ++++-- crates/ty_ide/src/inlay_hints.rs | 3 ++- crates/ty_ide/src/semantic_tokens.rs | 5 ++--- crates/ty_ide/src/signature_help.rs | 2 +- crates/ty_python_semantic/src/semantic_model.rs | 5 +++-- crates/ty_python_semantic/src/types.rs | 8 +------- crates/ty_python_semantic/src/types/function.rs | 3 ++- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/crates/ty_ide/src/goto.rs b/crates/ty_ide/src/goto.rs index bb085e3c3c..419fcae322 100644 --- a/crates/ty_ide/src/goto.rs +++ b/crates/ty_ide/src/goto.rs @@ -15,8 +15,10 @@ use ruff_text_size::{Ranged, TextRange, TextSize}; use ty_python_semantic::HasDefinition; use ty_python_semantic::ImportAliasResolution; use ty_python_semantic::ResolvedDefinition; -use ty_python_semantic::types::definitions_for_keyword_argument; -use ty_python_semantic::types::{Type, call_signature_details}; +use ty_python_semantic::types::Type; +use ty_python_semantic::types::ide_support::{ + call_signature_details, definitions_for_keyword_argument, +}; use ty_python_semantic::{ HasType, SemanticModel, definitions_for_imported_symbol, definitions_for_name, }; diff --git a/crates/ty_ide/src/inlay_hints.rs b/crates/ty_ide/src/inlay_hints.rs index 64ce9b9c15..1e3f545aff 100644 --- a/crates/ty_ide/src/inlay_hints.rs +++ b/crates/ty_ide/src/inlay_hints.rs @@ -6,7 +6,8 @@ use ruff_db::parsed::parsed_module; use ruff_python_ast::visitor::source_order::{self, SourceOrderVisitor, TraversalSignal}; use ruff_python_ast::{AnyNodeRef, Expr, Stmt}; use ruff_text_size::{Ranged, TextRange, TextSize}; -use ty_python_semantic::types::{Type, inlay_hint_function_argument_details}; +use ty_python_semantic::types::Type; +use ty_python_semantic::types::ide_support::inlay_hint_function_argument_details; use ty_python_semantic::{HasType, SemanticModel}; #[derive(Debug, Clone)] diff --git a/crates/ty_ide/src/semantic_tokens.rs b/crates/ty_ide/src/semantic_tokens.rs index 9b70b32e60..dccebf3c4b 100644 --- a/crates/ty_ide/src/semantic_tokens.rs +++ b/crates/ty_ide/src/semantic_tokens.rs @@ -13,9 +13,8 @@ use ruff_python_ast::{ use ruff_text_size::{Ranged, TextLen, TextRange}; use std::ops::Deref; use ty_python_semantic::{ - HasType, SemanticModel, - semantic_index::definition::DefinitionKind, - types::{Type, definition_kind_for_name}, + HasType, SemanticModel, semantic_index::definition::DefinitionKind, types::Type, + types::ide_support::definition_kind_for_name, }; // This module walks the AST and collects a set of "semantic tokens" for a file diff --git a/crates/ty_ide/src/signature_help.rs b/crates/ty_ide/src/signature_help.rs index bbcb676c69..d0648b2e25 100644 --- a/crates/ty_ide/src/signature_help.rs +++ b/crates/ty_ide/src/signature_help.rs @@ -17,7 +17,7 @@ use ruff_text_size::{Ranged, TextRange, TextSize}; use ty_python_semantic::ResolvedDefinition; use ty_python_semantic::SemanticModel; use ty_python_semantic::semantic_index::definition::Definition; -use ty_python_semantic::types::{ +use ty_python_semantic::types::ide_support::{ CallSignatureDetails, call_signature_details, find_active_signature_from_details, }; diff --git a/crates/ty_python_semantic/src/semantic_model.rs b/crates/ty_python_semantic/src/semantic_model.rs index 11ea272246..eb50b50366 100644 --- a/crates/ty_python_semantic/src/semantic_model.rs +++ b/crates/ty_python_semantic/src/semantic_model.rs @@ -12,6 +12,7 @@ use crate::semantic_index::definition::Definition; use crate::semantic_index::scope::FileScopeId; use crate::semantic_index::semantic_index; use crate::types::ide_support::all_declarations_and_bindings; +use crate::types::ide_support::{Member, all_members}; use crate::types::{Type, binding_type, infer_scope_types}; pub struct SemanticModel<'db> { @@ -193,7 +194,7 @@ impl<'db> SemanticModel<'db> { let builtin = module.is_known(self.db, KnownModule::Builtins); let mut completions = vec![]; - for crate::types::Member { name, ty } in crate::types::all_members(self.db, ty) { + for Member { name, ty } in all_members(self.db, ty) { completions.push(Completion { name, ty: Some(ty), @@ -226,7 +227,7 @@ impl<'db> SemanticModel<'db> { /// Returns completions for symbols available in a `object.` context. pub fn attribute_completions(&self, node: &ast::ExprAttribute) -> Vec> { let ty = node.value.inferred_type(self); - crate::types::all_members(self.db, ty) + all_members(self.db, ty) .into_iter() .map(|member| Completion { name: member.name, diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index b6de9b7f39..00c25e38b9 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -55,12 +55,6 @@ use crate::types::generics::{ GenericContext, PartialSpecialization, Specialization, bind_typevar, typing_self, walk_generic_context, }; -pub use crate::types::ide_support::{ - CallSignatureDetails, Member, MemberWithDefinition, all_members, call_signature_details, - definition_kind_for_name, definitions_for_attribute, definitions_for_imported_symbol, - definitions_for_keyword_argument, definitions_for_name, find_active_signature_from_details, - inlay_hint_function_argument_details, -}; use crate::types::infer::infer_unpack_types; use crate::types::mro::{Mro, MroError, MroIterator}; pub(crate) use crate::types::narrow::infer_narrowing_constraint; @@ -89,7 +83,7 @@ mod display; mod enums; mod function; mod generics; -pub(crate) mod ide_support; +pub mod ide_support; mod infer; mod instance; mod mro; diff --git a/crates/ty_python_semantic/src/types/function.rs b/crates/ty_python_semantic/src/types/function.rs index 4488a77d25..bb357d4afa 100644 --- a/crates/ty_python_semantic/src/types/function.rs +++ b/crates/ty_python_semantic/src/types/function.rs @@ -74,6 +74,7 @@ use crate::types::diagnostic::{ }; use crate::types::display::DisplaySettings; use crate::types::generics::GenericContext; +use crate::types::ide_support::all_members; use crate::types::narrow::ClassInfoConstraintFunction; use crate::types::signatures::{CallableSignature, Signature}; use crate::types::visitor::any_over_type; @@ -82,7 +83,7 @@ use crate::types::{ ClassLiteral, ClassType, DeprecatedInstance, DynamicType, FindLegacyTypeVarsVisitor, HasRelationToVisitor, IsEquivalentVisitor, KnownClass, KnownInstanceType, NormalizedVisitor, SpecialFormType, TrackedConstraintSet, Truthiness, Type, TypeMapping, TypeRelation, - UnionBuilder, all_members, binding_type, todo_type, walk_signature, + UnionBuilder, binding_type, todo_type, walk_signature, }; use crate::{Db, FxOrderSet, ModuleName, resolve_module};