提交 1481ef3c 编写于 作者: S Sam Harwell

Fix failure to initialize RemoteWorkspace in the out-of-process host

上级 c0bef8d3
......@@ -381,7 +381,7 @@ private static async Task<SolutionService> GetSolutionServiceAsync(Solution solu
var storage = new AssetStorage();
var source = new TestAssetSource(storage, map);
var remoteWorkspace = new RemoteWorkspace();
var service = new SolutionService(new AssetService(sessionId, storage, remoteWorkspace), remoteWorkspace);
var service = new SolutionService(new AssetService(sessionId, storage, remoteWorkspace));
return service;
}
......
......@@ -78,7 +78,7 @@ public RoslynServices(int scopeId, AssetStorage storage, HostServices hostServic
var workspace = (RemoteWorkspace)primaryWorkspace.Workspace ?? new RemoteWorkspace();
AssetService = new AssetService(_scopeId, storage, workspace);
SolutionService = new SolutionService(AssetService, workspace);
SolutionService = new SolutionService(AssetService);
CompilationService = new CompilationService(SolutionService);
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host.Mef;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Remote
......@@ -22,15 +24,27 @@ internal class SolutionService : ISolutionController
private volatile static Tuple<Checksum, Solution> s_primarySolution;
private volatile static Tuple<Checksum, Solution> s_lastSolution;
public SolutionService(AssetService assetService, RemoteWorkspace remoteWorkspace)
public SolutionService(AssetService assetService)
{
_assetService = assetService;
PrimaryWorkspace = remoteWorkspace;
}
public RemoteWorkspace PrimaryWorkspace
public static RemoteWorkspace PrimaryWorkspace
{
get;
get
{
var exportProvider = (IMefHostExportProvider)RoslynServices.HostServices;
var primaryWorkspace = exportProvider.GetExports<PrimaryWorkspace>().Single().Value;
if (primaryWorkspace.Workspace == null)
{
// The Roslyn OOP service assumes a singleton workspace exists, but doesn't initialize it anywhere.
// If we get here, code is asking for a workspace before it exists, so we create one on the fly.
// The RemoteWorkspace constructor assigns itself as the new singleton instance.
new RemoteWorkspace();
}
return (RemoteWorkspace)primaryWorkspace.Workspace;
}
}
public Task<Solution> GetSolutionAsync(Checksum solutionChecksum, CancellationToken cancellationToken)
......
......@@ -62,7 +62,7 @@ public void ReportAnalyzerPerformance(List<AnalyzerPerformanceInfo> snapshot, in
{
token.ThrowIfCancellationRequested();
var service = RoslynServices.SolutionService.PrimaryWorkspace.Services.GetService<IPerformanceTrackerService>();
var service = SolutionService.PrimaryWorkspace.Services.GetService<IPerformanceTrackerService>();
if (service == null)
{
return;
......
......@@ -220,10 +220,10 @@ private void SetGlobalContext(int uiCultureLCID, int cultureLCID, string seriali
FatalError.NonFatalHandler = WatsonReporter.Report;
// start performance reporter
var diagnosticAnalyzerPerformanceTracker = RoslynServices.SolutionService.PrimaryWorkspace.Services.GetService<IPerformanceTrackerService>();
var diagnosticAnalyzerPerformanceTracker = SolutionService.PrimaryWorkspace.Services.GetService<IPerformanceTrackerService>();
if (diagnosticAnalyzerPerformanceTracker != null)
{
var globalOperationNotificationService = RoslynServices.SolutionService.PrimaryWorkspace.Services.GetService<IGlobalOperationNotificationService>();
var globalOperationNotificationService = SolutionService.PrimaryWorkspace.Services.GetService<IGlobalOperationNotificationService>();
_performanceReporter = new PerformanceReporter(Logger, diagnosticAnalyzerPerformanceTracker, globalOperationNotificationService, s_reportInterval, ShutdownCancellationToken);
}
}
......@@ -265,12 +265,12 @@ private static TelemetrySession GetTelemetrySession(string serializedSession)
private RemotePersistentStorageLocationService GetPersistentStorageService()
{
return (RemotePersistentStorageLocationService)RoslynServices.SolutionService.PrimaryWorkspace.Services.GetService<IPersistentStorageLocationService>();
return (RemotePersistentStorageLocationService)SolutionService.PrimaryWorkspace.Services.GetService<IPersistentStorageLocationService>();
}
private RemoteGlobalOperationNotificationService GetGlobalOperationNotificationService()
{
var notificationService = RoslynServices.SolutionService.PrimaryWorkspace.Services.GetService<IGlobalOperationNotificationService>() as RemoteGlobalOperationNotificationService;
var notificationService = SolutionService.PrimaryWorkspace.Services.GetService<IGlobalOperationNotificationService>() as RemoteGlobalOperationNotificationService;
return notificationService;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册