[ty] Add search paths info to unresolved import diagnostics (#20040)

Fixes https://github.com/astral-sh/ty/issues/457

---------

Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
This commit is contained in:
Renkai Ge 2025-08-26 23:01:16 +08:00 committed by GitHub
parent 136abace92
commit 73720c73be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 111 additions and 7 deletions

View file

@ -10,8 +10,7 @@ pub use resolver::{resolve_module, resolve_real_module};
use ruff_db::system::SystemPath;
use crate::Db;
use crate::module_resolver::resolver::{ModuleResolveMode, search_paths};
use resolver::SearchPathIterator;
pub(crate) use resolver::{ModuleResolveMode, SearchPathIterator, search_paths};
mod list;
mod module;

View file

@ -700,6 +700,25 @@ impl SearchPath {
SearchPathInner::StandardLibraryVendored(_) => "std-vendored",
}
}
/// Returns a string suitable for describing what kind of search path this is
/// in user-facing diagnostics.
#[must_use]
pub(crate) fn describe_kind(&self) -> &'static str {
match *self.0 {
SearchPathInner::Extra(_) => {
"extra search path specified on the CLI or in your config file"
}
SearchPathInner::FirstParty(_) => "first-party code",
SearchPathInner::StandardLibraryCustom(_) => {
"custom stdlib stubs specified on the CLI or in your config file"
}
SearchPathInner::StandardLibraryReal(_) => "runtime stdlib source code",
SearchPathInner::SitePackages(_) => "site-packages",
SearchPathInner::Editable(_) => "editable install",
SearchPathInner::StandardLibraryVendored(_) => "stdlib typeshed stubs vendored by ty",
}
}
}
impl PartialEq<SystemPath> for SearchPath {