Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proffer ManagedHotReloadLanguageService brokered service in VS #72737

Merged
merged 2 commits into from
Mar 26, 2024
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
1 change: 1 addition & 0 deletions eng/targets/Services.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
<ItemGroup>
<InProcService Include="Microsoft.VisualStudio.LanguageServices.SolutionAssetProvider" />
<InProcService Include="Microsoft.VisualStudio.LanguageServices.WorkspaceProjectFactoryService" />
<InProcService Include="Microsoft.VisualStudio.LanguageServices.ManagedHotReloadLanguageService" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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.

using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Debugger.Contracts.HotReload;

namespace Microsoft.CodeAnalysis.EditAndContinue;

/// <summary>
/// Exposes <see cref="EditAndContinueLanguageService"/> as a brokered service.
/// TODO (https://github.com/dotnet/roslyn/issues/72713):
/// Once debugger is updated to use the brokered service, this class should be removed and <see cref="EditAndContinueLanguageService"/> should be exported directly.
/// </summary>
internal sealed partial class ManagedEditAndContinueLanguageServiceBridge(EditAndContinueLanguageService service) : IManagedHotReloadLanguageService
{
public ValueTask StartSessionAsync(CancellationToken cancellationToken)
=> service.StartSessionAsync(cancellationToken);

public ValueTask EndSessionAsync(CancellationToken cancellationToken)
=> service.EndSessionAsync(cancellationToken);

public ValueTask EnterBreakStateAsync(CancellationToken cancellationToken)
=> service.EnterBreakStateAsync(cancellationToken);

public ValueTask ExitBreakStateAsync(CancellationToken cancellationToken)
=> service.ExitBreakStateAsync(cancellationToken);

public ValueTask OnCapabilitiesChangedAsync(CancellationToken cancellationToken)
=> service.OnCapabilitiesChangedAsync(cancellationToken);

public async ValueTask<ManagedHotReloadUpdates> GetUpdatesAsync(CancellationToken cancellationToken)
=> (await service.GetUpdatesAsync(cancellationToken).ConfigureAwait(false));

public ValueTask CommitUpdatesAsync(CancellationToken cancellationToken)
=> service.CommitUpdatesAsync(cancellationToken);

public ValueTask DiscardUpdatesAsync(CancellationToken cancellationToken)
=> service.DiscardUpdatesAsync(cancellationToken);

public ValueTask<bool> HasChangesAsync(string? sourceFilePath, CancellationToken cancellationToken)
=> service.HasChangesAsync(sourceFilePath, cancellationToken);
}

6 changes: 6 additions & 0 deletions src/VisualStudio/Core/Def/RoslynPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ColorSchemes;
using Microsoft.CodeAnalysis.Common;
using Microsoft.CodeAnalysis.EditAndContinue;
using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncCompletion;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
Expand Down Expand Up @@ -179,6 +180,11 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
serviceBrokerContainer.Proffer(
WorkspaceProjectFactoryServiceDescriptor.ServiceDescriptor,
(_, _, _, _) => ValueTaskFactory.FromResult<object?>(new WorkspaceProjectFactoryService(this.ComponentModel.GetService<IWorkspaceProjectContextFactory>())));

// Must be profferred before any C#/VB projects are loaded and the corresponding UI context activated.
serviceBrokerContainer.Proffer(
ManagedHotReloadLanguageServiceDescriptor.VisualStudioDescriptor,
(_, _, _, _) => ValueTaskFactory.FromResult<object?>(new ManagedEditAndContinueLanguageServiceBridge(this.ComponentModel.GetService<EditAndContinueLanguageService>())));
}

private async Task LoadOptionPersistersAsync(IComponentModel componentModel, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

using System;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.BrokeredServices;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.ServiceHub.Framework;
using Microsoft.VisualStudio.Debugger.Contracts.HotReload;
Expand All @@ -16,22 +14,13 @@

namespace Microsoft.CodeAnalysis.EditAndContinue;

[ExportBrokeredService(MonikerName, ServiceVersion, Audience = ServiceAudience.Local)]
[ExportBrokeredService(ManagedHotReloadLanguageServiceDescriptor.MonikerName, ManagedHotReloadLanguageServiceDescriptor.ServiceVersion, Audience = ServiceAudience.Local)]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed partial class ManagedHotReloadLanguageServiceBridge(InternalContracts.IManagedHotReloadLanguageService service) : IManagedHotReloadLanguageService, IExportedBrokeredService
{
private const string ServiceName = "ManagedHotReloadLanguageService";
private const string ServiceVersion = "0.1";
private const string MonikerName = BrokeredServiceDescriptors.LanguageServerComponentNamespace + "." + BrokeredServiceDescriptors.LanguageServerComponentName + "." + ServiceName;

public static readonly ServiceJsonRpcDescriptor ServiceDescriptor = BrokeredServiceDescriptors.CreateServerServiceDescriptor(ServiceName, new(ServiceVersion));

static ManagedHotReloadLanguageServiceBridge()
=> Debug.Assert(ServiceDescriptor.Moniker.Name == MonikerName);

ServiceRpcDescriptor IExportedBrokeredService.Descriptor
=> ServiceDescriptor;
=> ManagedHotReloadLanguageServiceDescriptor.DevKitDescriptor;

public Task InitializeAsync(CancellationToken cancellationToken)
=> Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.

using System.Diagnostics;
using Microsoft.CodeAnalysis.BrokeredServices;
using Microsoft.ServiceHub.Framework;
using Microsoft.CodeAnalysis.Remote;

namespace Microsoft.CodeAnalysis.EditAndContinue;

internal static class ManagedHotReloadLanguageServiceDescriptor
{
private const string ServiceName = "ManagedHotReloadLanguageService";
public const string ServiceVersion = "1.0";
public const string MonikerName = BrokeredServiceDescriptors.LanguageServerComponentNamespace + "." + BrokeredServiceDescriptors.LanguageServerComponentName + "." + ServiceName;

public static readonly ServiceJsonRpcDescriptor DevKitDescriptor = BrokeredServiceDescriptors.CreateServerServiceDescriptor(ServiceName, new(ServiceVersion));
public static readonly ServiceJsonRpcDescriptor VisualStudioDescriptor = ServiceDescriptor.CreateInProcServiceDescriptor(ServiceDescriptors.ComponentName, ServiceName, suffix: "", ServiceDescriptors.GetFeatureDisplayName);

static ManagedHotReloadLanguageServiceDescriptor()
=> Debug.Assert(DevKitDescriptor.Moniker.Name == MonikerName);
}