From 7ba0689f60d588f3574c22346ca649768b8a9903 Mon Sep 17 00:00:00 2001 From: Tomas Matousek Date: Tue, 14 Jan 2025 13:14:36 -0800 Subject: [PATCH 1/3] IServiceBrokerProvider --- ...crosoft.CodeAnalysis.EditorFeatures.csproj | 5 +++- .../ServiceBrokerProvider.cs | 7 ++--- ...isualStudio.LanguageServices.DevKit.csproj | 6 ----- .../Remote/Core/IServiceBrokerProvider.cs | 12 +++++++++ ...oker.cs => RemoteServiceBrokerProvider.cs} | 26 ++++++------------- ...soft.CodeAnalysis.Remote.ServiceHub.csproj | 4 --- .../BrokeredServiceBase.FactoryBase.cs | 2 +- 7 files changed, 27 insertions(+), 35 deletions(-) rename src/{Workspaces/Remote/Core => LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices}/ServiceBrokerProvider.cs (91%) create mode 100644 src/Workspaces/Remote/Core/IServiceBrokerProvider.cs rename src/Workspaces/Remote/ServiceHub/Host/{IGlobalServiceBroker.cs => RemoteServiceBrokerProvider.cs} (53%) diff --git a/src/EditorFeatures/Core/Microsoft.CodeAnalysis.EditorFeatures.csproj b/src/EditorFeatures/Core/Microsoft.CodeAnalysis.EditorFeatures.csproj index 4c73a2c02380e..0d1bf87e852d7 100644 --- a/src/EditorFeatures/Core/Microsoft.CodeAnalysis.EditorFeatures.csproj +++ b/src/EditorFeatures/Core/Microsoft.CodeAnalysis.EditorFeatures.csproj @@ -31,11 +31,11 @@ - + @@ -101,4 +101,7 @@ + + + diff --git a/src/Workspaces/Remote/Core/ServiceBrokerProvider.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/ServiceBrokerProvider.cs similarity index 91% rename from src/Workspaces/Remote/Core/ServiceBrokerProvider.cs rename to src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/ServiceBrokerProvider.cs index 474f047ac9dbe..3714f03a9e03d 100644 --- a/src/Workspaces/Remote/Core/ServiceBrokerProvider.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/ServiceBrokerProvider.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#pragma warning disable RS0030 // Do not use banned APIs (MEFv1) + using System; using System.ComponentModel.Composition; using Microsoft.CodeAnalysis.Host.Mef; @@ -10,11 +12,6 @@ namespace Microsoft.CodeAnalysis.BrokeredServices; -internal interface IServiceBrokerProvider -{ - IServiceBroker ServiceBroker { get; } -} - /// /// MEF service that can be used to fetch an instance without having to use legacy MEF imports. /// diff --git a/src/VisualStudio/DevKit/Impl/Microsoft.VisualStudio.LanguageServices.DevKit.csproj b/src/VisualStudio/DevKit/Impl/Microsoft.VisualStudio.LanguageServices.DevKit.csproj index 4c7df6f74a51e..6a3b2eae473fa 100644 --- a/src/VisualStudio/DevKit/Impl/Microsoft.VisualStudio.LanguageServices.DevKit.csproj +++ b/src/VisualStudio/DevKit/Impl/Microsoft.VisualStudio.LanguageServices.DevKit.csproj @@ -22,15 +22,9 @@ - - - - - - - - diff --git a/src/Workspaces/Remote/ServiceHub/Services/BrokeredServiceBase.FactoryBase.cs b/src/Workspaces/Remote/ServiceHub/Services/BrokeredServiceBase.FactoryBase.cs index 905ef1fcd1120..acea0f21b289f 100644 --- a/src/Workspaces/Remote/ServiceHub/Services/BrokeredServiceBase.FactoryBase.cs +++ b/src/Workspaces/Remote/ServiceHub/Services/BrokeredServiceBase.FactoryBase.cs @@ -94,7 +94,7 @@ internal TService Create( { // Register this service broker globally (if it's the first we encounter) so it can be used by other // global services that need it. - GlobalServiceBroker.RegisterServiceBroker(serviceBroker); + RemoteServiceBrokerProvider.RegisterServiceBroker(serviceBroker); var descriptor = ServiceDescriptors.Instance.GetServiceDescriptorForServiceFactory(typeof(TService)); var serviceHubTraceSource = (TraceSource?)hostProvidedServices.GetService(typeof(TraceSource)); From c90a3d03326f1c613b7d15377d69673c2932a815 Mon Sep 17 00:00:00 2001 From: tmat Date: Wed, 15 Jan 2025 18:57:32 -0800 Subject: [PATCH 2/3] FIx --- .../EditAndContinueLanguageServiceTests.cs | 5 ++++- .../BrokeredServices/ServiceBrokerProvider.cs | 9 +++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/EditorFeatures/Test/EditAndContinue/EditAndContinueLanguageServiceTests.cs b/src/EditorFeatures/Test/EditAndContinue/EditAndContinueLanguageServiceTests.cs index eaf50833afbf7..8398039f50f26 100644 --- a/src/EditorFeatures/Test/EditAndContinue/EditAndContinueLanguageServiceTests.cs +++ b/src/EditorFeatures/Test/EditAndContinue/EditAndContinueLanguageServiceTests.cs @@ -46,6 +46,7 @@ private static string Inspect(DebuggerContracts.ManagedHotReloadDiagnostic d) private TestWorkspace CreateEditorWorkspace(out Solution solution, out EditAndContinueService service, out EditAndContinueLanguageService languageService, Type[] additionalParts = null) { var composition = EditorTestCompositions.EditorFeatures + .AddExcludedPartTypes(typeof(ServiceBrokerProvider)) .AddParts( typeof(MockHostWorkspaceProvider), typeof(MockManagedHotReloadService), @@ -87,7 +88,9 @@ private class TestSourceTextContainer : SourceTextContainer public async Task Test(bool commitChanges) { var localComposition = EditorTestCompositions.LanguageServerProtocolEditorFeatures - .AddExcludedPartTypes(typeof(EditAndContinueService)) + .AddExcludedPartTypes( + typeof(EditAndContinueService), + typeof(ServiceBrokerProvider)) .AddParts( typeof(NoCompilationLanguageService), typeof(MockHostWorkspaceProvider), diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/ServiceBrokerProvider.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/ServiceBrokerProvider.cs index 3714f03a9e03d..e66f12ddd7826 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/ServiceBrokerProvider.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/ServiceBrokerProvider.cs @@ -2,23 +2,20 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#pragma warning disable RS0030 // Do not use banned APIs (MEFv1) - using System; -using System.ComponentModel.Composition; +using System.Composition; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.ServiceHub.Framework; -using Microsoft.VisualStudio.Shell.ServiceBroker; namespace Microsoft.CodeAnalysis.BrokeredServices; /// /// MEF service that can be used to fetch an instance without having to use legacy MEF imports. /// -[Export(typeof(IServiceBrokerProvider))] +[Export(typeof(IServiceBrokerProvider)), Shared] [method: ImportingConstructor] [method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] -internal sealed class ServiceBrokerProvider([Import(typeof(SVsFullAccessServiceBroker))] IServiceBroker serviceBroker) : IServiceBrokerProvider +internal sealed class ServiceBrokerProvider([Import("Microsoft.VisualStudio.Shell.ServiceBroker.SVsFullAccessServiceBroker")] IServiceBroker serviceBroker) : IServiceBrokerProvider { public IServiceBroker ServiceBroker { get; } = serviceBroker; } From 26256f5b758bfad1cddf909838831deb49f6122e Mon Sep 17 00:00:00 2001 From: Tomas Matousek Date: Thu, 16 Jan 2025 10:56:33 -0800 Subject: [PATCH 3/3] MEFV1 --- .../BrokeredServices/ServiceBrokerProvider.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/ServiceBrokerProvider.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/ServiceBrokerProvider.cs index e66f12ddd7826..3714f03a9e03d 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/ServiceBrokerProvider.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/ServiceBrokerProvider.cs @@ -2,20 +2,23 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#pragma warning disable RS0030 // Do not use banned APIs (MEFv1) + using System; -using System.Composition; +using System.ComponentModel.Composition; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.ServiceHub.Framework; +using Microsoft.VisualStudio.Shell.ServiceBroker; namespace Microsoft.CodeAnalysis.BrokeredServices; /// /// MEF service that can be used to fetch an instance without having to use legacy MEF imports. /// -[Export(typeof(IServiceBrokerProvider)), Shared] +[Export(typeof(IServiceBrokerProvider))] [method: ImportingConstructor] [method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] -internal sealed class ServiceBrokerProvider([Import("Microsoft.VisualStudio.Shell.ServiceBroker.SVsFullAccessServiceBroker")] IServiceBroker serviceBroker) : IServiceBrokerProvider +internal sealed class ServiceBrokerProvider([Import(typeof(SVsFullAccessServiceBroker))] IServiceBroker serviceBroker) : IServiceBrokerProvider { public IServiceBroker ServiceBroker { get; } = serviceBroker; }