use std::result::Result as CrateResult;
use proc_macro_crate::Error as CrateError;
use proc_macro_crate::FoundCrate;
use proc_macro2::Span;
use quote::format_ident;
use syn::DeriveInput;
use syn::Error;
use syn::Path;
use syn::Result;
use syn::parse_quote;
pub(crate) fn resolve(
input: &DeriveInput,
result: CrateResult<FoundCrate, CrateError>,
itself: Path,
error_context: &str,
) -> Result<Path> {
match result {
Ok(FoundCrate::Itself) => Ok(itself),
Ok(FoundCrate::Name(name)) => {
let identifier = format_ident!("{}", name.replace('-', "_"), span = Span::call_site());
Ok(parse_quote!(::#identifier))
}
Err(error) => Err(Error::new_spanned(input, format!("{error_context}: {error}"))),
}
}