[red-knot] Merge the semantic and module-resolver crates (#12751)

This commit is contained in:
Alex Waygood 2024-08-08 15:34:11 +01:00 committed by GitHub
parent 33e9a6a54e
commit f1de08c2a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
610 changed files with 91 additions and 274 deletions

View file

@ -0,0 +1,45 @@
use std::iter::FusedIterator;
pub(crate) use module::Module;
pub use resolver::resolve_module;
use ruff_db::system::SystemPath;
pub use typeshed::vendored_typeshed_stubs;
use crate::Db;
use resolver::{module_resolution_settings, SearchPathIterator};
mod module;
mod path;
mod resolver;
mod state;
mod typeshed;
#[cfg(test)]
mod testing;
/// Returns an iterator over all search paths pointing to a system path
pub fn system_module_search_paths(db: &dyn Db) -> SystemModuleSearchPathsIter {
SystemModuleSearchPathsIter {
inner: module_resolution_settings(db).search_paths(db),
}
}
pub struct SystemModuleSearchPathsIter<'db> {
inner: SearchPathIterator<'db>,
}
impl<'db> Iterator for SystemModuleSearchPathsIter<'db> {
type Item = &'db SystemPath;
fn next(&mut self) -> Option<Self::Item> {
loop {
let next = self.inner.next()?;
if let Some(system_path) = next.as_system_path() {
return Some(system_path);
}
}
}
}
impl FusedIterator for SystemModuleSearchPathsIter<'_> {}