use pedant_syntax::go::{GoFactSpan, GoFileFacts, GoScopeFact};
use super::binding_fact::GoBindingRecord;
use super::declaration_fact::GoDeclarationRecord;
use super::import_fact::GoImportRecord;
use super::reference_fact::GoReferenceRecord;
use super::signature_fact::GoSignatureTermRecord;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct GoSourceFacts {
package: Option<(Box<str>, GoFactSpan)>,
imports: Box<[GoImportRecord]>,
declarations: Box<[GoDeclarationRecord]>,
signatures: Box<[GoSignatureTermRecord]>,
references: Box<[GoReferenceRecord]>,
scopes: Box<[GoScopeFact]>,
bindings: Box<[GoBindingRecord]>,
}
impl GoSourceFacts {
pub(super) fn of(facts: &GoFileFacts<'_>) -> Self {
Self {
package: facts
.package_name()
.zip(facts.package_span())
.map(|(name, span)| (Box::from(name), span)),
imports: facts.imports().iter().map(GoImportRecord::of).collect(),
declarations: facts
.declarations()
.iter()
.map(GoDeclarationRecord::of)
.collect(),
signatures: facts
.signature_terms()
.iter()
.map(GoSignatureTermRecord::of)
.collect(),
references: facts
.references()
.iter()
.map(GoReferenceRecord::of)
.collect(),
scopes: Box::from(facts.scopes()),
bindings: facts.bindings().iter().map(GoBindingRecord::of).collect(),
}
}
pub fn package_name(&self) -> Option<&str> {
self.package.as_ref().map(|(name, _)| &**name)
}
pub fn package_span(&self) -> Option<GoFactSpan> {
self.package.as_ref().map(|(_, span)| *span)
}
pub fn imports(&self) -> &[GoImportRecord] {
&self.imports
}
pub fn declarations(&self) -> &[GoDeclarationRecord] {
&self.declarations
}
pub fn signature_terms(&self) -> &[GoSignatureTermRecord] {
&self.signatures
}
pub fn references(&self) -> &[GoReferenceRecord] {
&self.references
}
pub fn scopes(&self) -> &[GoScopeFact] {
&self.scopes
}
pub fn bindings(&self) -> &[GoBindingRecord] {
&self.bindings
}
}