Carry resolved filesystem facts through loads
This commit is contained in:
@@ -17,12 +17,35 @@ type resolvedFilesystemContext struct {
|
||||
}
|
||||
|
||||
func resolveFilesystemContext(source Source, context *FilesystemContext, main parsedSource, hostToken *namespaceToken) (resolvedFilesystemContext, *Diagnostic) {
|
||||
if source.kind == sourceNone && context != nil {
|
||||
return resolveAbsentFilesystemContext(context)
|
||||
}
|
||||
if nativeContext(source, context) {
|
||||
return resolveNativeFilesystemContext(source, context)
|
||||
}
|
||||
return resolveHostFilesystemContext(source, context, main, hostToken)
|
||||
}
|
||||
|
||||
func resolveAbsentFilesystemContext(context *FilesystemContext) (resolvedFilesystemContext, *Diagnostic) {
|
||||
if context.FS != nil {
|
||||
return resolveNativeFilesystemContext(Source{kind: sourceNone}, context)
|
||||
}
|
||||
rootPath, err := canonicalExistingPath(context.Root)
|
||||
if err != nil {
|
||||
value := importDiagnostic(CodeImportInvalid, "configuration root could not be canonicalized", nil)
|
||||
return resolvedFilesystemContext{}, &value
|
||||
}
|
||||
basePath := rootPath
|
||||
if context.BaseDir != "" {
|
||||
basePath, err = canonicalExistingPath(context.BaseDir)
|
||||
if err != nil {
|
||||
value := importDiagnostic(CodeImportInvalid, "import base directory could not be canonicalized", nil)
|
||||
return resolvedFilesystemContext{}, &value
|
||||
}
|
||||
}
|
||||
return resolvedFilesystemContext{rootPath: rootPath, basePath: basePath}, nil
|
||||
}
|
||||
|
||||
func resolveNativeFilesystemContext(source Source, context *FilesystemContext) (resolvedFilesystemContext, *Diagnostic) {
|
||||
var namespace *nativeNamespace
|
||||
resolved := resolvedFilesystemContext{rootPath: ".", basePath: "."}
|
||||
@@ -50,7 +73,7 @@ func resolveNativeFilesystemContext(source Source, context *FilesystemContext) (
|
||||
}
|
||||
|
||||
func resolveHostFilesystemContext(source Source, context *FilesystemContext, main parsedSource, hostToken *namespaceToken) (resolvedFilesystemContext, *Diagnostic) {
|
||||
if main.source == nil || main.document == nil {
|
||||
if main.source == nil {
|
||||
value := importDiagnostic(CodeImportInvalid, "imports require a selected configuration source", nil)
|
||||
return resolvedFilesystemContext{}, &value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user