Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,22 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Execution;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.CSharp.Execution;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.UnitTests;
using Microsoft.CodeAnalysis.Remote;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.SolutionCrawler;
using Microsoft.CodeAnalysis.SymbolSearch;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities.RemoteHost;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServices.Remote;
using Roslyn.Test.Utilities.Remote;
using Roslyn.Utilities;
using Roslyn.VisualStudio.Next.UnitTests.Mocks;
using Xunit;

Expand All @@ -35,11 +30,15 @@ public class RemoteHostClientServiceFactoryTests
[Fact, Trait(Traits.Feature, Traits.Features.RemoteHost)]
public async Task UpdaterService()
{
var exportProvider = TestHostServices.CreateMinimalExportProvider();
var exportProvider = ExportProviderCache
.GetOrCreateExportProviderFactory(ServiceTestExportProvider.CreateAssemblyCatalog()
.WithParts(typeof(InProcRemoteHostClientProvider.Factory), typeof(CSharpOptionsSerializationService)))
.CreateExportProvider();

using var workspace = new AdhocWorkspace(TestHostServices.CreateHostServices(exportProvider));

var options = workspace.CurrentSolution.Options
.WithChangedOption(RemoteHostOptions.SolutionChecksumMonitorBackOffTimeSpanInMS, 1)
.WithChangedOption(Microsoft.VisualStudio.LanguageServices.Remote.RemoteHostOptions.SolutionChecksumMonitorBackOffTimeSpanInMS, 1)
.WithChangedOption(Microsoft.CodeAnalysis.Test.Utilities.RemoteHost.RemoteHostOptions.RemoteHostTest, true);

workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(options));
Expand All @@ -52,8 +51,11 @@ public async Task UpdaterService()
// make sure client is ready
using var client = await service.TryGetRemoteHostClientAsync(CancellationToken.None);

// add solution
// add solution, change document
workspace.AddSolution(SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Default));
var project = workspace.AddProject("proj", LanguageNames.CSharp);
var document = workspace.AddDocument(project.Id, "doc.cs", SourceText.From("code"));
workspace.ApplyTextChanges(document.Id, new[] { new TextChange(new TextSpan(0, 1), "abc") }, CancellationToken.None);

// wait for listener
var workspaceListener = listenerProvider.GetWaiter(FeatureAttribute.Workspace);
Expand Down
8 changes: 1 addition & 7 deletions src/Workspaces/Remote/Razor/ServiceHubServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ protected Task<Solution> GetSolutionAsync(CancellationToken cancellationToken)
}

public Task<Solution> GetSolutionAsync(JObject solutionInfo, CancellationToken cancellationToken)
{
var reader = solutionInfo.CreateReader();
var serializer = JsonSerializer.Create(new JsonSerializerSettings() { Converters = new[] { AggregateJsonConverter.Instance } });
var pinnedSolutionInfo = serializer.Deserialize<PinnedSolutionInfo>(reader);

return CreateSolutionService(pinnedSolutionInfo).GetSolutionAsync(pinnedSolutionInfo, cancellationToken);
}
=> GetSolutionImplAsync(solutionInfo, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ protected PythiaServiceBase(IServiceProvider serviceProvider, Stream stream, IEn
=> base.StartService();

public Task<Solution> GetSolutionAsync(JObject solutionInfo, CancellationToken cancellationToken)
{
var reader = solutionInfo.CreateReader();
var serializer = JsonSerializer.Create(new JsonSerializerSettings() { Converters = new[] { AggregateJsonConverter.Instance } });
var pinnedSolutionInfo = serializer.Deserialize<PinnedSolutionInfo>(reader);

return CreateSolutionService(pinnedSolutionInfo).GetSolutionAsync(pinnedSolutionInfo, cancellationToken);
}
=> GetSolutionImplAsync(solutionInfo, cancellationToken);

#pragma warning disable IDE0060 // Remove unused parameter - Avoiding breaking change in External access API
protected Task<T> RunServiceAsync<T>(Func<Task<T>> callAsync, CancellationToken cancellationToken, [CallerMemberName] string? callerName = null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
Expand Down Expand Up @@ -27,13 +27,7 @@ protected UnitTestingServiceBase(
=> base.StartService();

protected Task<Solution> GetSolutionAsync(JObject solutionInfo, CancellationToken cancellationToken)
{
var reader = solutionInfo.CreateReader();
var serializer = JsonSerializer.Create(new JsonSerializerSettings() { Converters = new[] { AggregateJsonConverter.Instance } });
var pinnedSolutionInfo = serializer.Deserialize<PinnedSolutionInfo>(reader);

return CreateSolutionService(pinnedSolutionInfo).GetSolutionAsync(pinnedSolutionInfo, cancellationToken);
}
=> GetSolutionImplAsync(solutionInfo, cancellationToken);

protected new Task<T> RunServiceAsync<T>(Func<Task<T>> callAsync, CancellationToken cancellationToken)
=> base.RunServiceAsync(callAsync, cancellationToken);
Expand Down
3 changes: 3 additions & 0 deletions src/Workspaces/Remote/ServiceHub/Shared/RemoteEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public RemoteEndPoint(Stream stream, TraceSource logger, object? incomingCallTar

var jsonFormatter = new JsonMessageFormatter();

// disable interpreting of strings as DateTime during deserialization:
jsonFormatter.JsonSerializer.DateParseHandling = DateParseHandling.None;

if (jsonConverters != null)
{
jsonFormatter.JsonSerializer.Converters.AddRange(jsonConverters);
Expand Down
10 changes: 10 additions & 0 deletions src/Workspaces/Remote/ServiceHub/Shared/ServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ErrorReporting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Remote
Expand Down Expand Up @@ -87,6 +88,15 @@ protected SolutionService CreateSolutionService(PinnedSolutionInfo solutionInfo)
protected Task<Solution> GetSolutionAsync(PinnedSolutionInfo solutionInfo, CancellationToken cancellationToken)
=> CreateSolutionService(solutionInfo).GetSolutionAsync(solutionInfo, cancellationToken);

internal Task<Solution> GetSolutionImplAsync(JObject solutionInfo, CancellationToken cancellationToken)
{
var reader = solutionInfo.CreateReader();
var serializer = JsonSerializer.Create(new JsonSerializerSettings() { Converters = new[] { AggregateJsonConverter.Instance }, DateParseHandling = DateParseHandling.None });
var pinnedSolutionInfo = serializer.Deserialize<PinnedSolutionInfo>(reader);

return CreateSolutionService(pinnedSolutionInfo).GetSolutionAsync(pinnedSolutionInfo, cancellationToken);
}

protected async Task<T> RunServiceAsync<T>(Func<Task<T>> callAsync, CancellationToken cancellationToken)
{
AssetStorage.UpdateLastActivityTime();
Expand Down