public AbstractWorkspace(string name, string description) { this.Name = name; this.Description = description; this.Configuration = new WorkspaceConfiguration(); }
public static WorkspaceConfiguration AddWorkspaceConfig <TWorkspaceType>(this IUFrameContainer container, string title, string description = null) { var config = new WorkspaceConfiguration(typeof(TWorkspaceType), title, description); container.RegisterInstance(config, typeof(TWorkspaceType).Name); return(config); }
public void Test_AddUser_AddsAUser() { WorkspaceConfiguration configuration = new WorkspaceConfiguration(); configuration.AddUser("*****@*****.**", Role.ReadOnly); Assert.Equal(1, configuration.Users.Count); Assert.Equal("*****@*****.**", configuration.Users.First().Username); Assert.Equal(Role.ReadOnly, configuration.Users.First().Role); }
public RoslynCompilationWorkspace(WorkspaceConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } Configuration = configuration; var dependencyResolver = configuration.DependencyResolver; var compilationConfiguration = configuration.CompilationConfiguration; workspace = new InteractiveWorkspace(); sourceReferenceResolver = new InteractiveSourceReferenceResolver(dependencyResolver); metadataReferenceResolver = new InteractiveMetadataReferenceResolver(dependencyResolver); monoScriptCompilationPatcher = new MonoScriptCompilationPatcher( assemblyNamePrefixBytes); DependencyResolver = dependencyResolver; hostObjectType = compilationConfiguration.GlobalStateType.ResolvedType; EvaluationContextId = compilationConfiguration.EvaluationContextId; includePeImagesInResolution = compilationConfiguration.IncludePEImagesInDependencyResolution; initialImports = compilationConfiguration.DefaultImports.ToImmutableArray(); initialWarningSuppressions = compilationConfiguration.DefaultWarningSuppressions.ToImmutableArray(); initialDiagnosticOptions = initialWarningSuppressions.ToImmutableDictionary( warningId => warningId, warningId => ReportDiagnostic.Suppress); initialReferences = dependencyResolver .ResolveDefaultReferences() .Select(r => PortableExecutableReference.CreateFromFile(r.Path)) .ToImmutableArray(); foreach (var implicitReference in byNameImplicitReferences) { if (implicitReference == null) { continue; } var assembly = DependencyResolver.ResolveWithoutReferences( new AssemblyName(implicitReference)); if (assembly != null) { initialReferences = initialReferences.Add( MetadataReference.CreateFromFile(assembly.Path)); } } CompletionService = workspace .Services .GetLanguageServices(LanguageNames.CSharp) .GetService <CompletionService> (); }
async Task InitializeCompilationWorkspaceAsync(CancellationToken cancellationToken) { WorkingDirectory = Workbook.WorkingBasePath; if (!WorkingDirectory.DirectoryExists) { WorkingDirectory = Uri.WorkingDirectory; } if (!WorkingDirectory.DirectoryExists) { WorkingDirectory = FilePath.Empty; } if (agent.IsConnected) { await GacCache.InitializingTask; await Agent.Api.AssociateClientSession( ClientSessionAssociationKind.Initial, WorkingDirectory); CompilationWorkspace = new RoslynCompilationWorkspace( await WorkspaceConfiguration.CreateAsync( Agent, SessionKind, cancellationToken)); } await RefreshForAgentIntegration(); if (CompilationWorkspace == null) { throw new Exception("Unable to get compilation workspace for agent."); } var dependencyResolver = CompilationWorkspace.DependencyResolver; if (WorkingDirectory.DirectoryExists) { dependencyResolver.BaseDirectory = WorkingDirectory; dependencyResolver.AddAssemblySearchPath(WorkingDirectory); } Workbook.WorkingPathChanged += (o, e) => { if (dependencyResolver != null) { dependencyResolver.RemoveAssemblySearchPath(WorkingDirectory); dependencyResolver.RemoveAssemblySearchPath(e.OldBasePath); WorkingDirectory = e.NewBasePath; dependencyResolver.BaseDirectory = WorkingDirectory; dependencyResolver.AddAssemblySearchPath(WorkingDirectory); } }; PostEvent(ClientSessionEventKind.CompilationWorkspaceAvailable); }
public void Test_AddUser_ThrowsAnException_WhenAnEmptyUsernameIsSpecified() { try { WorkspaceConfiguration configuration = new WorkspaceConfiguration(); configuration.AddUser(" ", Role.ReadWrite); throw new TestFailedException(); } catch (ArgumentException iae) { Assert.Equal("A username must be specified.", iae.Message); } }
public async Task TwoPlusTwo() { var evaluationContextManager = new EvaluationContextManager( new RepresentationManager(RepresentationManagerOptions.YieldOriginal) ); var workspaceConfiguration = await WorkspaceConfiguration .CreateAsync(evaluationContextManager); var workspaceService = await WorkspaceServiceFactory .CreateWorkspaceServiceAsync("csharp", workspaceConfiguration); var evaluationService = new EvaluationService( workspaceService,
/// <summary> /// Each element in <param name="moduleRepositoryArray"/> represents the extent of a resolver, /// containing module references (keys) to spec content (values). So a workspace is created accordingly: so many /// resolvers as array elements. /// </summary> public WorkspaceProvider CreateWorkspaceProviderFromContentWithFileSystem( IFileSystem fileSystem, bool cancelOnFirstFailure, bool preserveTrivia = false, params ModuleRepository[] moduleRepositoryArray) { var resolverSettings = new List <IResolverSettings>(); foreach (var modulesWithContent in moduleRepositoryArray) { resolverSettings.Add(CreateResolverSettingsFromModulesWithContent(modulesWithContent, fileSystem)); } var workspaceConfiguration = new WorkspaceConfiguration( resolverSettings, constructFingerprintDuringParsing: false, maxDegreeOfParallelismForParsing: DataflowBlockOptions.Unbounded, parsingOptions: ParsingOptions.DefaultParsingOptions.WithTrivia(preserveTrivia), maxDegreeOfParallelismForTypeChecking: 1, cancelOnFirstFailure: cancelOnFirstFailure, includePreludeWithName: PreludeName, cancellationToken: m_cancellationToken); var frontEndFactory = new FrontEndFactory(); frontEndFactory.AddFrontEnd(new SimpleDScriptFrontEnd()); frontEndFactory.TrySeal(new LoggingContext("test", "Test")); var result = WorkspaceProvider.TryCreate( mainConfigurationWorkspace: null, workspaceStatistics: new WorkspaceStatistics(), frontEndFactory, configuration: workspaceConfiguration, pathTable: PathTable, symbolTable: new SymbolTable(), useDecorator: false, addBuiltInPreludeResolver: false, workspaceProvider: out var workspaceProvider, failures: out var failures); // We assume workspace provider does not fail here Contract.Assert(result); return((WorkspaceProvider)workspaceProvider); }
/// <nodoc/> public Expression ParseExpression(RuntimeModelContext runtimeModelContext, AbsolutePath path, string spec, FunctionScope localScope, bool useSemanticNameResolution) { Contract.Requires(runtimeModelContext != null); Contract.Requires(spec != null); var parser = new TypeScript.Net.Parsing.Parser(); // Wrap expression in a function call to make the parser happy. // Currently an object literal '{...};' is not a valid statement. var sourceFile = parser.ParseSourceFileContent( path.ToString(runtimeModelContext.PathTable), @"function createExpression(a: any) {} createExpression(" + spec + ");"); if (sourceFile.ParseDiagnostics.Count != 0) { ReportParseDiagnosticsIfNeeded(runtimeModelContext, sourceFile, path); return(null); } var workspaceConfiguration = WorkspaceConfiguration.CreateForTesting(); var workspace = new Workspace( provider: null, workspaceConfiguration: workspaceConfiguration, modules: new[] { CreateModuleFor(runtimeModelContext, sourceFile) }, failures: Enumerable.Empty <Failure>(), preludeModule: null, configurationModule: null); workspace = SemanticWorkspaceProvider.ComputeSemanticWorkspace(runtimeModelContext.PathTable, workspace, workspaceConfiguration).GetAwaiter().GetResult(); // Because we just created source file to parse, we know exactly what the AST is there. // This information helped to simplify analysis logic and migrate to semantic-base name resolution. var invocation = sourceFile.Statements[1].Cast <IExpressionStatement>().Expression.Cast <ICallExpression>(); // Only for expressions, full names should be preserved. // Only for expressions, no checks for definition before use to avoid contract assertion in location computation. m_conversionConfiguration.UnsafeOptions.DisableDeclarationBeforeUseCheck = true; var converter = CreateAstConverter(sourceFile, runtimeModelContext, path, m_conversionConfiguration, workspace: workspace); return(converter.ConvertExpression(invocation, localScope, useSemanticNameResolution)); }
public void ClearConfiguration() { Configuration = null; }
private Task <Workspace> ComputeSemanticWorkspaceAsync(Workspace workspace, WorkspaceConfiguration workspaceConfiguration) { var semanticWorkspaceProvider = new SemanticWorkspaceProvider(m_frontEndStatistics, workspaceConfiguration); return(semanticWorkspaceProvider.ComputeSemanticWorkspaceAsync(FrontEndContext.PathTable, workspace)); }
public Task <CodeAnalysis.IWorkspaceService> CreateNew( LanguageDescription languageDescription, WorkspaceConfiguration workspaceConfiguration, CancellationToken cancellationToken) => Task.FromResult <CodeAnalysis.IWorkspaceService> ( new RoslynCompilationWorkspace(workspaceConfiguration));
public static async Task <IWorkspaceService> CreateWorkspaceServiceAsync(LanguageDescription languageDescription, WorkspaceConfiguration configuration, CancellationToken cancellationToken = default(CancellationToken));
public CodeLiteWorkspace ParseWorkspace(string workspacePath) { // WORKSPACE XmlDocument workspaceReader = new XmlDocument(); workspaceReader.Load(workspacePath); CodeLiteWorkspace workspace = new CodeLiteWorkspace(); workspace.Name = workspaceReader.SelectSingleNode("CodeLite_Workspace").Attributes.GetNamedItem("Name").Value; // Configurations XmlNode buildMatrixNode = workspaceReader.SelectSingleNode("CodeLite_Workspace/BuildMatrix"); workspace.Configurations = new List <WorkspaceConfiguration>(); foreach (XmlNode configurationNode in buildMatrixNode.SelectNodes("WorkspaceConfiguration")) { WorkspaceConfiguration workspaceConfig = new WorkspaceConfiguration(); workspace.Configurations.Add(workspaceConfig); workspaceConfig.Name = configurationNode.Attributes.GetNamedItem("Name").Value; workspaceConfig.Projects = new List <WorkspaceConfigurationProject>(); foreach (XmlNode projectInConfigNode in configurationNode.SelectNodes("Project")) { WorkspaceConfigurationProject projectConfiguration = new WorkspaceConfigurationProject(); workspaceConfig.Projects.Add(projectConfiguration); projectConfiguration.Name = projectInConfigNode.Attributes.GetNamedItem("Name").Value; projectConfiguration.ConfigName = projectInConfigNode.Attributes.GetNamedItem("ConfigName").Value; } } // PROJECTS workspace.Projects = new List <CodeLiteProject>(); foreach (XmlNode projectNode in workspaceReader.SelectNodes("CodeLite_Workspace/Project")) { CodeLiteProject project = new CodeLiteProject(); workspace.Projects.Add(project); project.Name = projectNode.Attributes.GetNamedItem("Name").Value; project.Path = projectNode.Attributes.GetNamedItem("Path").Value; XmlDocument projectReader = new XmlDocument(); projectReader.Load(Path.GetDirectoryName(workspacePath) + Path.DirectorySeparatorChar + project.Path); // Files project.CodeFiles = new List <string>(); foreach (XmlNode directoryNode in projectReader.SelectNodes("CodeLite_Project/VirtualDirectory")) { ParseVirtualDirectory(directoryNode, project); } // Dependencies project.Dependencies = new List <Dependencies>(); foreach (XmlNode dependencyNode in projectReader.SelectNodes("CodeLite_Project/Dependencies")) { if (dependencyNode.Attributes.GetNamedItem("Name") != null) { Dependencies dependencies = new Dependencies(); project.Dependencies.Add(dependencies); dependencies.Name = dependencyNode.Attributes.GetNamedItem("Name").Value; XmlNodeList dependencyProjects = dependencyNode.SelectNodes("Project"); dependencies.ProjectNames = new List <string>(); foreach (XmlNode dependencyProjectNode in dependencyProjects) { dependencies.ProjectNames.Add(dependencyProjectNode.Attributes.GetNamedItem("Name").Value); } } } // Configurations project.Configurations = new List <CodeLiteProjectConfiguration>(); foreach (XmlNode configNode in projectReader.SelectSingleNode("CodeLite_Project/Settings").SelectNodes("Configuration")) { project.Configurations.Add(ParseProjectConfiguration(configNode)); } // Global settings project.GlobalConfiguration = ParseProjectConfiguration(projectReader.SelectSingleNode("CodeLite_Project/Settings").SelectSingleNode("GlobalSettings")); } return(workspace); }
async Task LoadPackageIntegrationsAsync( AgentType agentType, TargetCompilationConfiguration targetCompilationConfiguration, IEvaluationContextManager evaluationContextManager, InteractivePackage package, CancellationToken cancellationToken) { // Forms is special-cased because we own it and load the extension from our framework. if (PackageIdComparer.Equals(package.Identity.Id, "Xamarin.Forms")) { await WorkspaceConfiguration.LoadFormsAgentExtensions( package.Identity.Version.Version, targetCompilationConfiguration, evaluationContextManager, dependencyResolver); } var assembliesToLoadOnAgent = new List <ResolvedAssembly> (); // Integration assemblies are not expected to be in a TFM directory—we look for them in // the `xamarin.interactive` folder inside the NuGet package. var packagePath = packageManager.GetPackageInstallPath(package); var interactivePath = packagePath.Combine("xamarin.interactive"); if (interactivePath.DirectoryExists) { var interactiveAssemblies = interactivePath.EnumerateFiles("*.dll"); foreach (var interactiveReference in interactiveAssemblies) { var resolvedAssembly = dependencyResolver.ResolveWithoutReferences(interactiveReference); if (HasIntegration(resolvedAssembly)) { assembliesToLoadOnAgent.Add(resolvedAssembly); } } } if (assembliesToLoadOnAgent.Count > 0) { var includePeImage = targetCompilationConfiguration.IncludePEImagesInDependencyResolution; var assembliesToLoad = assembliesToLoadOnAgent.Select(dep => { var peImage = includePeImage ? GetFileBytes(dep.Path) : null; var syms = includePeImage ? GetDebugSymbolsFromAssemblyPath(dep.Path) : null; return(new AssemblyDefinition( dep.AssemblyName, dep.Path, peImage: peImage, debugSymbols: syms )); }).ToArray(); await evaluationContextManager.LoadAssembliesAsync( targetCompilationConfiguration.EvaluationContextId, assembliesToLoad, cancellationToken); } await getAgentConnectionHandler(true, cancellationToken); }