private Uri?TryGetNormalizedModulePath(Uri parentFileUri, ModuleDeclarationSyntax moduleDeclarationSyntax, out DiagnosticBuilder.ErrorBuilderDelegate?failureBuilder)
        {
            var pathName = SyntaxHelper.TryGetModulePath(moduleDeclarationSyntax, out var getModulePathFailureBuilder);

            if (pathName == null)
            {
                failureBuilder = getModulePathFailureBuilder;
                return(null);
            }

            if (!ValidateFilePath(pathName, out var validateModulePathFailureBuilder))
            {
                failureBuilder = validateModulePathFailureBuilder;
                return(null);
            }

            var moduleUri = fileResolver.TryResolveFilePath(parentFileUri, pathName);

            if (moduleUri == null)
            {
                failureBuilder = x => x.FilePathCouldNotBeResolved(pathName, parentFileUri.LocalPath);
                return(null);
            }

            failureBuilder = null;
            return(moduleUri);
        }
Exemple #2
0
        public override Uri?TryGetLocalModuleEntryPointUri(Uri?parentModuleUri, LocalModuleReference reference, out DiagnosticBuilder.ErrorBuilderDelegate?failureBuilder)
        {
            parentModuleUri = parentModuleUri ?? throw new ArgumentException($"{nameof(parentModuleUri)} must not be null for local module references.");
            var localUri = fileResolver.TryResolveFilePath(parentModuleUri, reference.Path);

            if (localUri is not null)
            {
                failureBuilder = null;
                return(localUri);
            }

            failureBuilder = x => x.FilePathCouldNotBeResolved(reference.Path, parentModuleUri.LocalPath);
            return(null);
        }
Exemple #3
0
        public Uri?TryGetLocalModuleEntryPointPath(Uri parentModuleUri, ModuleReference reference, out DiagnosticBuilder.ErrorBuilderDelegate?failureBuilder)
        {
            var typed = ConvertReference(reference);

            var localUri = fileResolver.TryResolveFilePath(parentModuleUri, typed.Path);

            if (localUri is not null)
            {
                failureBuilder = null;
                return(localUri);
            }

            failureBuilder = x => x.FilePathCouldNotBeResolved(typed.Path, parentModuleUri.LocalPath);
            return(null);
        }
        private static Uri?GetFileUriWithDiagnostics(IBinder binder, IFileResolver fileResolver, IDiagnosticWriter diagnostics, string filePath, SyntaxBase filePathArgument)
        {
            if (!LocalModuleReference.Validate(filePath, out var validateFilePathFailureBuilder))
            {
                diagnostics.Write(validateFilePathFailureBuilder.Invoke(DiagnosticBuilder.ForPosition(filePathArgument)));
                return(null);
            }

            var fileUri = fileResolver.TryResolveFilePath(binder.FileSymbol.FileUri, filePath);

            if (fileUri is null)
            {
                diagnostics.Write(DiagnosticBuilder.ForPosition(filePathArgument).FilePathCouldNotBeResolved(filePath, binder.FileSymbol.FileUri.LocalPath));
                return(null);
            }

            if (!fileUri.IsFile)
            {
                diagnostics.Write(DiagnosticBuilder.ForPosition(filePathArgument).UnableToLoadNonFileUri(fileUri));
                return(null);
            }
            return(fileUri);
        }