2026-11-09 20:38:55 +00:00
package engine
import "go.maximumdirect.net/configkit/internal/document"
func acquireContextlessInput ( input assembledInput , request inputAcquisitionRequest , processing * sourceVersionProcessingResult , policy acquisitionPolicy ) ( assembledInput , [ ] Diagnostic ) {
parsed := input . parsed
var body * document . Node
var declarations [ ] importDeclarationSpec
var sequences [ ] sequenceDeclarationSpec
var diagnostics [ ] Diagnostic
if processing != nil {
body , declarations = processing . payload , processing . imports
sequences = cloneSequenceDeclarations ( processing . sequences )
} else {
body , declarations , diagnostics = splitImportDirectives ( parsed . document )
}
destination := request . input . destination
localDestination := destination
if request . input . placementMode == PlacementModeSequenceItem {
localDestination = Path { }
}
if len ( diagnostics ) == 0 {
var policies [ ] resolvedImportPolicy
policies , diagnostics = prepareImportDeclarations ( declarations , policy . importDefaults , localDestination )
if len ( diagnostics ) == 0 {
for i , spec := range declarations {
if ! policies [ i ] . required || spec . selector == importSelectorPath && len ( spec . paths ) == 0 {
continue
}
site := spec . fieldSites [ "path" ]
if spec . selector == importSelectorPath && len ( spec . selectorSites ) != 0 {
site = spec . selectorSites [ 0 ]
}
if spec . selector == importSelectorDirectory {
site = spec . fieldSites [ "dir" ]
}
if spec . selector == importSelectorGlob {
site = spec . fieldSites [ "glob" ]
}
diagnostics = [ ] Diagnostic { { Code : CodeImportMissing , Severity : SeverityError , Path : site . path . clone ( ) , Message : "import cannot be selected because no filesystem base is available" , Primary : cloneLocation ( & site . location ) } }
break
}
}
}
if len ( diagnostics ) != 0 {
if request . input . placementMode == PlacementModeSequenceItem {
diagnostics = prependCompositionDiagnosticPaths ( diagnostics , destination . Index ( 0 ) )
}
return input , diagnostics
}
2026-11-09 21:18:16 +00:00
accounting , limits := input . accounting , policy . importLimits
if diagnostic := chargeDeclaringImport ( parsed , accounting , limits ) ; diagnostic != nil {
return input , [ ] Diagnostic { * diagnostic }
}
2026-11-09 20:38:55 +00:00
key := importKeyForMainSource ( parsed . source )
2026-11-09 21:18:16 +00:00
root := acquiredContribution {
source : cloneSourceInfo ( * parsed . source ) , payload : body , identity : key ,
role : importRoleMain , scopeOwner : key , processing : processing , sequenceDeclarations : sequences ,
2026-11-09 20:38:55 +00:00
}
2026-11-09 21:18:16 +00:00
scope , diagnostic := prepareDeclaringImportScope ( root , accounting , limits )
if diagnostic != nil {
return input , [ ] Diagnostic { * diagnostic }
}
scope , diagnostic = finalizeDeclaringImportScope ( scope , root , accounting , limits )
if diagnostic != nil {
return input , [ ] Diagnostic { * diagnostic }
2026-11-09 20:38:55 +00:00
}
input . document = body
input . composition = & composedDocument { acquisition : [ ] acquisitionScope { scope } , importGraph : newImportInclusionGraph ( ) , inputBytes : accounting . bytes , inputNodes : accounting . nodes }
input . acquisition = cloneAcquisitionScopes ( input . composition . acquisition )
return input , nil
}