コード例 #1
0
        /// <summary>
        /// Typechecks a given <paramref name="workspace"/> (which must support
        /// semantic model, i.e., be of type <see cref="SemanticWorkspace"/>).
        /// </summary>
        public ISemanticModel Typecheck(Workspace workspace)
        {
            var semanticModel = workspace.GetSemanticModel();

            WorkspaceTestBase.AssertNoSemanticErrors(semanticModel);
            return(semanticModel);
        }
コード例 #2
0
        protected KeyValuePair <AbsolutePath, ISourceFile> LoadAndTypecheckFile(
            FrontEndContext context,
            string testSource,
            string[] extraSources,
            Dictionary <string, string> modules,
            out Workspace workspace,
            bool preserveTrivia = false)
        {
            var wsHelper = new WorkspaceTestBase(pathTable: context.PathTable, preludeName: FrontEndHost.PreludeModuleName, nameResolutionSemantics: NameResolutionSemantics.ImplicitProjectReferences);
            var repo     = wsHelper.CreateEmptyContent();

            var testModule = ModuleDescriptor.CreateForTesting("TestModule");

            repo.AddContent(testModule, testSource);
            if (extraSources != null)
            {
                repo.AddContent(testModule, extraSources);
            }

            repo.AddContent(FrontEndHost.PreludeModuleName,
                            File.ReadAllText(@"Libs/lib.core.d.ts"),
                            File.ReadAllText(@"Libs/Prelude.IO.ts"),
                            "namespace Tool {export declare function option(value: string): any;}");
            if (modules != null)
            {
                foreach (var kv in modules)
                {
                    repo.AddContent(ModuleDescriptor.CreateForTesting(kv.Key), kv.Value);
                }
            }

            workspace = wsHelper.CreateSematicWorkspaceFromContent(testModule, preserveTrivia, repo).GetAwaiter().GetResult();
            WorkspaceTestBase.AssertNoWorkspaceFailures(workspace);

            var semanticModel = workspace.GetSemanticModel();

            WorkspaceTestBase.AssertNoSemanticErrors(semanticModel);

            return(workspace.Modules.First(m => m.Descriptor.Name == "TestModule").Specs.First(f => f.Key.GetName(context.PathTable).ToString(context.StringTable) == "0.dsc"));
        }