Пример #1
0
        private static bool TryCreateResolvers(
            [NotNull] FrontEndFactory frontEndFactory,
            WorkspaceConfiguration configuration,
            PathTable pathTable,
            AbsolutePath mainConfigurationFile,
            bool addBuiltInPreludeResolver,
            out List <IWorkspaceModuleResolver> resolvers,
            out IEnumerable <Failure> failures)
        {
            Contract.Ensures(Contract.Result <List <IWorkspaceModuleResolver> >() != null);
            Contract.EnsuresForAll(Contract.Result <List <IWorkspaceModuleResolver> >(), r => r != null);

            resolvers = new List <IWorkspaceModuleResolver>(configuration.ResolverSettings.Count + (addBuiltInPreludeResolver ? 1 : 0));

            var resolverFailures = new List <Failure>();

            var resolverSettings = new List <IResolverSettings>(configuration.ResolverSettings);

            // The built in resolver is generally not added only for some tests. Regular spec processing always adds it.
            if (addBuiltInPreludeResolver)
            {
                // We add a resolver that points to the built-in prelude at the end of the resolver collection
                // so the built-in prelude is used if no prelude is specified explicitly
                var builtInPreludeSettings = PreludeManager.GetResolverSettingsForBuiltInPrelude(mainConfigurationFile, pathTable);
                resolverSettings.Add(builtInPreludeSettings);
            }

            foreach (var resolverConfiguration in resolverSettings)
            {
                var kind = resolverConfiguration.Kind;
                if (!frontEndFactory.TryGetFrontEnd(kind, out var frontEnd))
                {
                    resolverFailures.Add(new WorkspaceModuleResolverGenericInitializationFailure(kind));
                    continue;
                }

                if (!frontEnd.TryCreateWorkspaceResolver(resolverConfiguration, out var resolver))
                {
                    resolverFailures.Add(new WorkspaceModuleResolverGenericInitializationFailure(resolverConfiguration.Kind));
                }
                else
                {
                    resolvers.Add(resolver);
                }
            }

            failures = resolverFailures;
            return(resolverFailures.Count == 0);
        }
Пример #2
0
        private static bool TryCreateResolvers <T>(
            IWorkspaceResolverFactory <T> workspaceResolverFactory,
            WorkspaceConfiguration configuration,
            AbsolutePath mainConfigurationFile,
            PathTable pathTable,
            bool addBuiltInPreludeResolver,
            out List <IWorkspaceModuleResolver> resolvers,
            out IEnumerable <Failure> failures)
        {
            Contract.Ensures(Contract.Result <List <IWorkspaceModuleResolver> >() != null);
            Contract.EnsuresForAll(Contract.Result <List <IWorkspaceModuleResolver> >(), r => r != null);

            resolvers = new List <IWorkspaceModuleResolver>(configuration.ResolverSettings.Count + (addBuiltInPreludeResolver ? 1 : 0));

            var resolverFailures = new List <Failure>();

            var resolverSettings = new List <IResolverSettings>(configuration.ResolverSettings);

            // The built in resolver is generally not added only for some tests. Regular spec processing always adds it.
            if (addBuiltInPreludeResolver)
            {
                // We add a resolver that points to the built-in prelude at the end of the resolver collection
                // so the built-in prelude is used if no prelude is specified explicitly
                var builtInPreludeSettings = PreludeManager.GetResolverSettingsForBuiltInPrelude(mainConfigurationFile, pathTable);
                resolverSettings.Add(builtInPreludeSettings);
            }

            foreach (var resolverConfiguration in resolverSettings)
            {
                var maybeResolver = workspaceResolverFactory.TryGetResolver(resolverConfiguration);
                if (!maybeResolver.Succeeded)
                {
                    resolverFailures.Add(maybeResolver.Failure);
                }
                else
                {
                    var resolver = (IWorkspaceModuleResolver)maybeResolver.Result;
                    resolvers.Add(resolver);
                }
            }

            failures = resolverFailures;
            return(resolverFailures.Count == 0);
        }