use std::path::{Path, PathBuf};
use shuck_semantic::{SourcePathResolver, SourceRef};
#[derive(Debug, Clone)]
pub(super) struct NativeSourceResolver {
cwd: PathBuf,
source_paths: Vec<String>,
}
impl NativeSourceResolver {
pub(super) fn new(cwd: PathBuf, source_paths: Vec<String>) -> Self {
Self { cwd, source_paths }
}
pub(super) fn has_roots(&self) -> bool {
!self.source_paths.is_empty()
}
}
impl SourcePathResolver for NativeSourceResolver {
fn resolve_candidate_paths(&self, source_path: &Path, candidate: &str) -> Vec<PathBuf> {
shuck_semantic::resolve_candidate_against_roots(
source_path,
candidate,
&self.source_paths,
&self.cwd,
)
}
}
pub(super) fn resolve_source_ref_paths(
source_path: &Path,
source_ref: &SourceRef,
resolver: &NativeSourceResolver,
) -> Option<PathBuf> {
shuck_semantic::resolve_source_ref_targets(
source_path,
source_ref,
&resolver.source_paths,
&resolver.cwd,
)
}
pub(super) fn source_ref_candidate_paths(
source_path: &Path,
source_ref: &SourceRef,
resolver: &NativeSourceResolver,
) -> Vec<PathBuf> {
shuck_semantic::source_ref_candidate_paths(
source_path,
source_ref,
&resolver.source_paths,
&resolver.cwd,
)
}