public DnxProjectSystem(OmnisharpWorkspace workspace, IOmnisharpEnvironment env, IOptions<OmniSharpOptions> optionsAccessor, ILoggerFactory loggerFactory, IMetadataFileReferenceCache metadataFileReferenceCache, IApplicationLifetime lifetime, IFileSystemWatcher watcher, IEventEmitter emitter, DnxContext context) { _workspace = workspace; _env = env; _logger = loggerFactory.CreateLogger<DnxProjectSystem>(); _metadataFileReferenceCache = metadataFileReferenceCache; _options = optionsAccessor.Options; _dnxPaths = new DnxPaths(env, _options, loggerFactory); _designTimeHostManager = new DesignTimeHostManager(loggerFactory, _dnxPaths); _packagesRestoreTool = new PackagesRestoreTool(_options, loggerFactory, emitter, context, _dnxPaths); _context = context; _watcher = watcher; _emitter = emitter; _directoryEnumerator = new DirectoryEnumerator(loggerFactory); lifetime.ApplicationStopping.Register(OnShutdown); }
public DnxTestCommandProvider(DnxContext context, IOmnisharpEnvironment env, ILoggerFactory loggerFactory, IEventEmitter emitter) { _context = context; var dnxPaths = new DnxPaths(env, context.Options, loggerFactory); _dnx = dnxPaths.Dnx != null ? dnxPaths.Dnx + " ." : dnxPaths.K; }
public PackagesRestoreTool(OmniSharpOptions options, ILoggerFactory logger, IEventEmitter emitter, DnxContext context, DnxPaths paths) { _options = options; _logger = logger.CreateLogger<PackagesRestoreTool>(); _emitter = emitter; _context = context; _paths = paths; _lock = new object(); _projectLocks = new Dictionary<string, object>(); _semaphore = new SemaphoreSlim(Environment.ProcessorCount / 2); }
public PackagesRestoreTool(OmniSharpOptions options, ILoggerFactory logger, IEventEmitter emitter, DnxContext context, DnxPaths paths) { _options = options; _logger = logger.CreateLogger <PackagesRestoreTool>(); _emitter = emitter; _context = context; _paths = paths; _lock = new object(); _projectLocks = new Dictionary <string, object>(); _semaphore = new SemaphoreSlim(GetNumConcurrentRestores()); }
public PackagesRestoreTool(DnxOptions options, IEventEmitter emitter, DnxContext context, DnxPaths paths) { _options = options; //_logger = logger.CreateLogger<PackagesRestoreTool>(); _emitter = emitter; _context = context; _paths = paths; _lock = new object(); _projectLocks = new Dictionary <string, object>(); _semaphore = new SemaphoreSlim(Environment.ProcessorCount / 2); }
public DesignTimeHostManager(ILoggerFactory loggerFactory, DnxPaths paths) { _logger = loggerFactory.CreateLogger <DesignTimeHostManager>(); _paths = paths; }
public void Initalize(IConfiguration configuration) { _options = new DnxOptions(); ConfigurationBinder.Bind(configuration, _options); _dnxPaths = new DnxPaths(_env, _options, _loggerFactory); _packagesRestoreTool = new PackagesRestoreTool(_options, _loggerFactory, _emitter, _context, _dnxPaths); ; _designTimeHostManager = new DesignTimeHostManager(_loggerFactory, _dnxPaths); var runtimePath = _dnxPaths.RuntimePath; _context.RuntimePath = runtimePath.Value; _context.Options = _options; if (!ScanForProjects()) { // No DNX projects found so do nothing _logger.LogInformation("No project.json based projects found"); return; } if (_context.RuntimePath == null) { // There is no default dnx found so do nothing _logger.LogInformation("No default runtime found"); _emitter.Emit(EventTypes.Error, runtimePath.Error); return; } var wh = new ManualResetEventSlim(); _designTimeHostManager.Start(_context.HostId, port => { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); var networkStream = new NetworkStream(socket); _logger.LogInformation("Connected"); _context.DesignTimeHostPort = port; _context.Connection = new ProcessingQueue(networkStream, _logger); _context.Connection.OnReceive += m => { var project = _context.Projects[m.ContextId]; if (m.MessageType == "ProjectInformation") { var val = m.Payload.ToObject<ProjectMessage>(); project.Name = val.Name; project.GlobalJsonPath = val.GlobalJsonPath; project.Configurations = val.Configurations; project.Commands = val.Commands; project.ProjectSearchPaths = val.ProjectSearchPaths; this._emitter.Emit(EventTypes.ProjectChanged, new ProjectInformationResponse() { {nameof(DnxProject), new DnxProject(project)} }); var unprocessed = project.ProjectsByFramework.Keys.ToList(); foreach (var frameworkData in val.Frameworks) { unprocessed.Remove(frameworkData.FrameworkName); var frameworkProject = project.ProjectsByFramework.GetOrAdd(frameworkData.FrameworkName, framework => { return new FrameworkProject(project, frameworkData); }); var id = frameworkProject.ProjectId; if (_workspace.CurrentSolution.ContainsProject(id)) { continue; } else { var projectInfo = ProjectInfo.Create( id, VersionStamp.Create(), val.Name + "+" + frameworkData.ShortName, val.Name, LanguageNames.CSharp, project.Path); _workspace.AddProject(projectInfo); _context.WorkspaceMapping[id] = frameworkProject; } lock (frameworkProject.PendingProjectReferences) { var reference = new Microsoft.CodeAnalysis.ProjectReference(id); foreach (var referenceId in frameworkProject.PendingProjectReferences) { _workspace.AddProjectReference(referenceId, reference); } frameworkProject.PendingProjectReferences.Clear(); } } // Remove old projects foreach (var frameworkName in unprocessed) { FrameworkProject frameworkProject; project.ProjectsByFramework.TryRemove(frameworkName, out frameworkProject); _workspace.RemoveProject(frameworkProject.ProjectId); } } // This is where we can handle messages and update the // language service else if (m.MessageType == "References") { // References as well as the dependency graph information var val = m.Payload.ToObject<ReferencesMessage>(); var frameworkProject = project.ProjectsByFramework[val.Framework.FrameworkName]; var projectId = frameworkProject.ProjectId; var metadataReferences = new List<MetadataReference>(); var projectReferences = new List<Microsoft.CodeAnalysis.ProjectReference>(); var removedFileReferences = frameworkProject.FileReferences.ToDictionary(p => p.Key, p => p.Value); var removedRawReferences = frameworkProject.RawReferences.ToDictionary(p => p.Key, p => p.Value); var removedProjectReferences = frameworkProject.ProjectReferences.ToDictionary(p => p.Key, p => p.Value); foreach (var file in val.FileReferences) { if (removedFileReferences.Remove(file)) { continue; } var metadataReference = _metadataFileReferenceCache.GetMetadataReference(file); frameworkProject.FileReferences[file] = metadataReference; metadataReferences.Add(metadataReference); } foreach (var rawReference in val.RawReferences) { if (removedRawReferences.Remove(rawReference.Key)) { continue; } var metadataReference = MetadataReference.CreateFromImage(rawReference.Value); frameworkProject.RawReferences[rawReference.Key] = metadataReference; metadataReferences.Add(metadataReference); } foreach (var projectReference in val.ProjectReferences) { if (removedProjectReferences.Remove(projectReference.Path)) { continue; } int projectReferenceContextId; if (!_context.ProjectContextMapping.TryGetValue(projectReference.Path, out projectReferenceContextId)) { projectReferenceContextId = AddProject(projectReference.Path); } var referencedProject = _context.Projects[projectReferenceContextId]; var referencedFrameworkProject = referencedProject.ProjectsByFramework.GetOrAdd(projectReference.Framework.FrameworkName, framework => { return new FrameworkProject(referencedProject, projectReference.Framework); }); var projectReferenceId = referencedFrameworkProject.ProjectId; if (_workspace.CurrentSolution.ContainsProject(projectReferenceId)) { projectReferences.Add(new Microsoft.CodeAnalysis.ProjectReference(projectReferenceId)); } else { lock (referencedFrameworkProject.PendingProjectReferences) { referencedFrameworkProject.PendingProjectReferences.Add(projectId); } } referencedFrameworkProject.ProjectDependeees[project.Path] = projectId; frameworkProject.ProjectReferences[projectReference.Path] = projectReferenceId; } foreach (var reference in metadataReferences) { _workspace.AddMetadataReference(projectId, reference); } foreach (var projectReference in projectReferences) { _workspace.AddProjectReference(projectId, projectReference); } foreach (var pair in removedProjectReferences) { _workspace.RemoveProjectReference(projectId, new Microsoft.CodeAnalysis.ProjectReference(pair.Value)); frameworkProject.ProjectReferences.Remove(pair.Key); // TODO: Update the dependee's list } foreach (var pair in removedFileReferences) { _workspace.RemoveMetadataReference(projectId, pair.Value); frameworkProject.FileReferences.Remove(pair.Key); } foreach (var pair in removedRawReferences) { _workspace.RemoveMetadataReference(projectId, pair.Value); frameworkProject.RawReferences.Remove(pair.Key); } } else if (m.MessageType == "Dependencies") { var val = m.Payload.ToObject<DependenciesMessage>(); var unresolvedDependencies = val.Dependencies.Values .Where(dep => dep.Type == "Unresolved"); if (unresolvedDependencies.Any()) { _logger.LogInformation("Project {0} has these unresolved references: {1}", project.Path, string.Join(", ", unresolvedDependencies.Select(d => d.Name))); _emitter.Emit(EventTypes.UnresolvedDependencies, new UnresolvedDependenciesMessage() { FileName = project.Path, UnresolvedDependencies = unresolvedDependencies.Select(d => new PackageDependency() { Name = d.Name, Version = d.Version }) }); _packagesRestoreTool.Run(project); } } else if (m.MessageType == "CompilerOptions") { // Configuration and compiler options var val = m.Payload.ToObject<CompilationOptionsMessage>(); var projectId = project.ProjectsByFramework[val.Framework.FrameworkName].ProjectId; var options = val.CompilationOptions.CompilationOptions; var specificDiagnosticOptions = options.SpecificDiagnosticOptions .ToDictionary(p => p.Key, p => (ReportDiagnostic)p.Value); var csharpOptions = new CSharpCompilationOptions( outputKind: (OutputKind)options.OutputKind, optimizationLevel: (OptimizationLevel)options.OptimizationLevel, platform: (Platform)options.Platform, generalDiagnosticOption: (ReportDiagnostic)options.GeneralDiagnosticOption, warningLevel: options.WarningLevel, allowUnsafe: options.AllowUnsafe, concurrentBuild: options.ConcurrentBuild, specificDiagnosticOptions: specificDiagnosticOptions ); var parseOptions = new CSharpParseOptions(val.CompilationOptions.LanguageVersion, preprocessorSymbols: val.CompilationOptions.Defines); _workspace.SetCompilationOptions(projectId, csharpOptions); _workspace.SetParseOptions(projectId, parseOptions); } else if (m.MessageType == "Sources") { // The sources to feed to the language service var val = m.Payload.ToObject<SourcesMessage>(); project.SourceFiles = val.Files .Where(fileName => Path.GetExtension(fileName) == ".cs") .ToList(); var frameworkProject = project.ProjectsByFramework[val.Framework.FrameworkName]; var projectId = frameworkProject.ProjectId; var unprocessed = new HashSet<string>(frameworkProject.Documents.Keys); foreach (var file in project.SourceFiles) { if (unprocessed.Remove(file)) { continue; } using (var stream = File.OpenRead(file)) { var sourceText = SourceText.From(stream, encoding: Encoding.UTF8); var id = DocumentId.CreateNewId(projectId); var version = VersionStamp.Create(); frameworkProject.Documents[file] = id; var loader = TextLoader.From(TextAndVersion.Create(sourceText, version)); _workspace.AddDocument(DocumentInfo.Create(id, file, filePath: file, loader: loader)); } } foreach (var file in unprocessed) { var docId = frameworkProject.Documents[file]; frameworkProject.Documents.Remove(file); _workspace.RemoveDocument(docId); } frameworkProject.Loaded = true; } else if (m.MessageType == "Error") { var val = m.Payload.ToObject<Microsoft.Framework.DesignTimeHost.Models.OutgoingMessages.ErrorMessage>(); _logger.LogError(val.Message); } if (project.ProjectsByFramework.Values.All(p => p.Loaded)) { wh.Set(); } }; // Start the message channel _context.Connection.Start(); // Initialize the DNX projects Initialize(); }); wh.Wait(); }
public void Start(string hostId, Action <int> onConnected) { lock (_processLock) { if (_stopped) { return; } int port = GetFreePort(); string runtimePath = _paths.RuntimePath.Value; // This gets the folder name (e.g. dnx-mono.1.0.0-beta5 or dnx-clr-x86.1.0.0-beta5) var fullName = DnxSdk.GetRuntimeNameFromFullPath(runtimePath); string flavor; string os; string arch; string version; if (DnxSdk.TryParseFullName(fullName, out flavor, out os, out arch, out version) && string.Equals(flavor, "coreclr", StringComparison.OrdinalIgnoreCase) && !string.Equals(os, "win", StringComparison.OrdinalIgnoreCase)) { // Work around since DTH is broken on CoreCLR on *nix and OSX var runtimeName = DnxSdk.GetFullName(version, "mono", os, arch); runtimePath = Path.Combine(Path.GetDirectoryName(runtimePath), runtimeName); _logger.LogInformation("Using '{0}' for design time host.", runtimePath); } var dthPath = Path.Combine(runtimePath, "bin", "lib", "Microsoft.Dnx.DesignTimeHost", "Microsoft.Dnx.DesignTimeHost.dll"); // TODO: This is for backcompat. Once the dust settles, and MS.Framework.DTH goes away, remove this. if (!File.Exists(dthPath)) { dthPath = Path.Combine(runtimePath, "bin", "lib", "Microsoft.Framework.DesignTimeHost", "Microsoft.Framework.DesignTimeHost.dll"); } var dnx = DnxPaths.FirstPath(runtimePath, "dnx", "dnx.exe"); var klr = DnxPaths.FirstPath(runtimePath, "klr", "klr.exe"); var psi = new ProcessStartInfo { FileName = dnx ?? klr, CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, Arguments = string.Format(@"""{0}"" {1} {2} {3}", dthPath, port, Process.GetCurrentProcess().Id, hostId), }; #if DNX451 psi.EnvironmentVariables["KRE_APPBASE"] = Directory.GetCurrentDirectory(); psi.EnvironmentVariables["DNX_APPBASE"] = Directory.GetCurrentDirectory(); #else psi.Environment["KRE_APPBASE"] = Directory.GetCurrentDirectory(); psi.Environment["DNX_APPBASE"] = Directory.GetCurrentDirectory(); #endif _logger.LogVerbose(psi.FileName + " " + psi.Arguments); _designTimeHostProcess = new Process(); _designTimeHostProcess.StartInfo = psi; _designTimeHostProcess.OutputDataReceived += (sender, args) => this._logger.LogInformation(args.Data ?? string.Empty); this._designTimeHostProcess.Start(); this._designTimeHostProcess.BeginOutputReadLine(); // Wait a little bit for it to conncet before firing the callback using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { var t1 = DateTime.UtcNow; var dthTimeout = TimeSpan.FromSeconds(30); while (!socket.Connected && DateTime.UtcNow - t1 < dthTimeout) { Thread.Sleep(500); try { socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); } catch (SocketException) { // this happens when the DTH isn't listening yet } } if (!socket.Connected) { // reached timeout _logger.LogError("Failed to launch DesignTimeHost in a timely fashion."); return; } } if (_designTimeHostProcess.HasExited) { // REVIEW: Should we quit here or retry? _logger.LogError(string.Format("Failed to launch DesignTimeHost. Process exited with code {0}.", _designTimeHostProcess.ExitCode)); return; } _logger.LogInformation(string.Format("Running DesignTimeHost on port {0}, with PID {1}", port, _designTimeHostProcess.Id)); _designTimeHostProcess.EnableRaisingEvents = true; _designTimeHostProcess.OnExit(() => { _logger.LogWarning("Design time host process ended"); Start(hostId, onConnected); }); onConnected(port); } }
public DesignTimeHostManager(ILoggerFactory loggerFactory, DnxPaths paths) { _logger = loggerFactory.CreateLogger<DesignTimeHostManager>(); _paths = paths; }
public void Initalize(IConfiguration configuration) { _options = new DnxOptions(); OptionsServices.ReadProperties(_options, configuration); _dnxPaths = new DnxPaths(_env, _options, _loggerFactory); _packagesRestoreTool = new PackagesRestoreTool(_options, _loggerFactory, _emitter, _context, _dnxPaths);; _designTimeHostManager = new DesignTimeHostManager(_loggerFactory, _dnxPaths); var runtimePath = _dnxPaths.RuntimePath; _context.RuntimePath = runtimePath.Value; _context.Options = _options; if (!ScanForProjects()) { // No DNX projects found so do nothing _logger.LogInformation("No project.json based projects found"); return; } if (_context.RuntimePath == null) { // There is no default dnx found so do nothing _logger.LogInformation("No default runtime found"); _emitter.Emit(EventTypes.Error, runtimePath.Error); return; } var wh = new ManualResetEventSlim(); _designTimeHostManager.Start(_context.HostId, port => { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(IPAddress.Loopback, port)); var networkStream = new NetworkStream(socket); _logger.LogInformation("Connected"); _context.DesignTimeHostPort = port; _context.Connection = new ProcessingQueue(networkStream, _logger); _context.Connection.OnReceive += m => { var project = _context.Projects[m.ContextId]; if (m.MessageType == "ProjectInformation") { var val = m.Payload.ToObject <ProjectMessage>(); project.Name = val.Name; project.GlobalJsonPath = val.GlobalJsonPath; project.Configurations = val.Configurations; project.Commands = val.Commands; project.ProjectSearchPaths = val.ProjectSearchPaths; this._emitter.Emit(EventTypes.ProjectChanged, new ProjectInformationResponse() { { nameof(DnxProject), new DnxProject(project) } }); var unprocessed = project.ProjectsByFramework.Keys.ToList(); foreach (var frameworkData in val.Frameworks) { unprocessed.Remove(frameworkData.FrameworkName); var frameworkProject = project.ProjectsByFramework.GetOrAdd(frameworkData.FrameworkName, framework => { return(new FrameworkProject(project, frameworkData)); }); var id = frameworkProject.ProjectId; if (_workspace.CurrentSolution.ContainsProject(id)) { continue; } else { var projectInfo = ProjectInfo.Create( id, VersionStamp.Create(), val.Name + "+" + frameworkData.ShortName, val.Name, LanguageNames.CSharp, project.Path); _workspace.AddProject(projectInfo); _context.WorkspaceMapping[id] = frameworkProject; } lock (frameworkProject.PendingProjectReferences) { var reference = new Microsoft.CodeAnalysis.ProjectReference(id); foreach (var referenceId in frameworkProject.PendingProjectReferences) { _workspace.AddProjectReference(referenceId, reference); } frameworkProject.PendingProjectReferences.Clear(); } } // Remove old projects foreach (var frameworkName in unprocessed) { FrameworkProject frameworkProject; project.ProjectsByFramework.TryRemove(frameworkName, out frameworkProject); _workspace.RemoveProject(frameworkProject.ProjectId); } } // This is where we can handle messages and update the // language service else if (m.MessageType == "References") { // References as well as the dependency graph information var val = m.Payload.ToObject <ReferencesMessage>(); var frameworkProject = project.ProjectsByFramework[val.Framework.FrameworkName]; var projectId = frameworkProject.ProjectId; var metadataReferences = new List <MetadataReference>(); var projectReferences = new List <Microsoft.CodeAnalysis.ProjectReference>(); var removedFileReferences = frameworkProject.FileReferences.ToDictionary(p => p.Key, p => p.Value); var removedRawReferences = frameworkProject.RawReferences.ToDictionary(p => p.Key, p => p.Value); var removedProjectReferences = frameworkProject.ProjectReferences.ToDictionary(p => p.Key, p => p.Value); foreach (var file in val.FileReferences) { if (removedFileReferences.Remove(file)) { continue; } var metadataReference = _metadataFileReferenceCache.GetMetadataReference(file); frameworkProject.FileReferences[file] = metadataReference; metadataReferences.Add(metadataReference); } foreach (var rawReference in val.RawReferences) { if (removedRawReferences.Remove(rawReference.Key)) { continue; } var metadataReference = MetadataReference.CreateFromImage(rawReference.Value); frameworkProject.RawReferences[rawReference.Key] = metadataReference; metadataReferences.Add(metadataReference); } foreach (var projectReference in val.ProjectReferences) { if (removedProjectReferences.Remove(projectReference.Path)) { continue; } int projectReferenceContextId; if (!_context.ProjectContextMapping.TryGetValue(projectReference.Path, out projectReferenceContextId)) { projectReferenceContextId = AddProject(projectReference.Path); } var referencedProject = _context.Projects[projectReferenceContextId]; var referencedFrameworkProject = referencedProject.ProjectsByFramework.GetOrAdd(projectReference.Framework.FrameworkName, framework => { return(new FrameworkProject(referencedProject, projectReference.Framework)); }); var projectReferenceId = referencedFrameworkProject.ProjectId; if (_workspace.CurrentSolution.ContainsProject(projectReferenceId)) { projectReferences.Add(new Microsoft.CodeAnalysis.ProjectReference(projectReferenceId)); } else { lock (referencedFrameworkProject.PendingProjectReferences) { referencedFrameworkProject.PendingProjectReferences.Add(projectId); } } referencedFrameworkProject.ProjectDependeees[project.Path] = projectId; frameworkProject.ProjectReferences[projectReference.Path] = projectReferenceId; } foreach (var reference in metadataReferences) { _workspace.AddMetadataReference(projectId, reference); } foreach (var projectReference in projectReferences) { _workspace.AddProjectReference(projectId, projectReference); } foreach (var pair in removedProjectReferences) { _workspace.RemoveProjectReference(projectId, new Microsoft.CodeAnalysis.ProjectReference(pair.Value)); frameworkProject.ProjectReferences.Remove(pair.Key); // TODO: Update the dependee's list } foreach (var pair in removedFileReferences) { _workspace.RemoveMetadataReference(projectId, pair.Value); frameworkProject.FileReferences.Remove(pair.Key); } foreach (var pair in removedRawReferences) { _workspace.RemoveMetadataReference(projectId, pair.Value); frameworkProject.RawReferences.Remove(pair.Key); } } else if (m.MessageType == "Dependencies") { var val = m.Payload.ToObject <DependenciesMessage>(); var unresolvedDependencies = val.Dependencies.Values .Where(dep => dep.Type == "Unresolved"); if (unresolvedDependencies.Any()) { _logger.LogInformation("Project {0} has these unresolved references: {1}", project.Path, string.Join(", ", unresolvedDependencies.Select(d => d.Name))); _emitter.Emit(EventTypes.UnresolvedDependencies, new UnresolvedDependenciesMessage() { FileName = project.Path, UnresolvedDependencies = unresolvedDependencies.Select(d => new PackageDependency() { Name = d.Name, Version = d.Version }) }); _packagesRestoreTool.Run(project); } } else if (m.MessageType == "CompilerOptions") { // Configuration and compiler options var val = m.Payload.ToObject <CompilationOptionsMessage>(); var projectId = project.ProjectsByFramework[val.Framework.FrameworkName].ProjectId; var options = val.CompilationOptions.CompilationOptions; var specificDiagnosticOptions = options.SpecificDiagnosticOptions .ToDictionary(p => p.Key, p => (ReportDiagnostic)p.Value); var csharpOptions = new CSharpCompilationOptions( outputKind: (OutputKind)options.OutputKind, optimizationLevel: (OptimizationLevel)options.OptimizationLevel, platform: (Platform)options.Platform, generalDiagnosticOption: (ReportDiagnostic)options.GeneralDiagnosticOption, warningLevel: options.WarningLevel, allowUnsafe: options.AllowUnsafe, concurrentBuild: options.ConcurrentBuild, specificDiagnosticOptions: specificDiagnosticOptions ); var parseOptions = new CSharpParseOptions(val.CompilationOptions.LanguageVersion, preprocessorSymbols: val.CompilationOptions.Defines); _workspace.SetCompilationOptions(projectId, csharpOptions); _workspace.SetParseOptions(projectId, parseOptions); } else if (m.MessageType == "Sources") { // The sources to feed to the language service var val = m.Payload.ToObject <SourcesMessage>(); project.SourceFiles = val.Files .Where(fileName => Path.GetExtension(fileName) == ".cs") .ToList(); var frameworkProject = project.ProjectsByFramework[val.Framework.FrameworkName]; var projectId = frameworkProject.ProjectId; var unprocessed = new HashSet <string>(frameworkProject.Documents.Keys); foreach (var file in project.SourceFiles) { if (unprocessed.Remove(file)) { continue; } using (var stream = File.OpenRead(file)) { var sourceText = SourceText.From(stream, encoding: Encoding.UTF8); var id = DocumentId.CreateNewId(projectId); var version = VersionStamp.Create(); frameworkProject.Documents[file] = id; var loader = TextLoader.From(TextAndVersion.Create(sourceText, version)); _workspace.AddDocument(DocumentInfo.Create(id, file, filePath: file, loader: loader)); } } foreach (var file in unprocessed) { var docId = frameworkProject.Documents[file]; frameworkProject.Documents.Remove(file); _workspace.RemoveDocument(docId); } frameworkProject.Loaded = true; } else if (m.MessageType == "Error") { var val = m.Payload.ToObject <Microsoft.Framework.DesignTimeHost.Models.OutgoingMessages.ErrorMessage>(); _logger.LogError(val.Message); } if (project.ProjectsByFramework.Values.All(p => p.Loaded)) { wh.Set(); } }; // Start the message channel _context.Connection.Start(); // Initialize the DNX projects Initialize(); }); wh.Wait(); }