73 lines
2.9 KiB
Go
73 lines
2.9 KiB
Go
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
|
|
}
|
|
accounting, limits := input.accounting, policy.importLimits
|
|
if diagnostic := chargeDeclaringImport(parsed, accounting, limits); diagnostic != nil {
|
|
return input, []Diagnostic{*diagnostic}
|
|
}
|
|
key := importKeyForMainSource(parsed.source)
|
|
root := acquiredContribution{
|
|
source: cloneSourceInfo(*parsed.source), payload: body, identity: key,
|
|
role: importRoleMain, scopeOwner: key, processing: processing, sequenceDeclarations: sequences,
|
|
}
|
|
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}
|
|
}
|
|
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
|
|
}
|