Skip to content

Commit

Permalink
Merge pull request #72296 from chabiss/vdiag-lsp
Browse files Browse the repository at this point in the history
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics
  • Loading branch information
dibarbet authored Mar 29, 2024
2 parents 6f89b6c + 7f916fa commit 0f35ec3
Show file tree
Hide file tree
Showing 18 changed files with 231 additions and 4 deletions.
8 changes: 7 additions & 1 deletion Roslyn.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31319.15
Expand Down Expand Up @@ -544,6 +543,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Feat
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Features.Test.Utilities", "src\Features\TestUtilities\Microsoft.CodeAnalysis.Features.Test.Utilities.csproj", "{5762E483-75CE-4328-A410-511F30737712}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics", "src\Tools\ExternalAccess\VisualDiagnostics\Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.csproj", "{6D819E80-BA2F-4317-8368-37F8F4434D3A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0F3118AE-8D36-4384-8E80-BD6566365305}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{47D004BE-F797-430E-8A18-4B0CDFD56643}"
Expand Down Expand Up @@ -1358,6 +1359,10 @@ Global
{5762E483-75CE-4328-A410-511F30737712}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5762E483-75CE-4328-A410-511F30737712}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5762E483-75CE-4328-A410-511F30737712}.Release|Any CPU.Build.0 = Release|Any CPU
{6D819E80-BA2F-4317-8368-37F8F4434D3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D819E80-BA2F-4317-8368-37F8F4434D3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D819E80-BA2F-4317-8368-37F8F4434D3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D819E80-BA2F-4317-8368-37F8F4434D3A}.Release|Any CPU.Build.0 = Release|Any CPU
{DB96C25F-39A9-4A6A-92BC-D1E42717308F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB96C25F-39A9-4A6A-92BC-D1E42717308F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB96C25F-39A9-4A6A-92BC-D1E42717308F}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -1619,6 +1624,7 @@ Global
{4D9D7A28-BB44-4F3F-81DA-14F39B853718} = {CC126D03-7EAC-493F-B187-DCDEE1EF6A70}
{5BABC440-4F1B-46E8-9068-DD7F02ED25D3} = {3E5FE3DB-45F7-4D83-9097-8F05D3B3AEC6}
{5762E483-75CE-4328-A410-511F30737712} = {3E5FE3DB-45F7-4D83-9097-8F05D3B3AEC6}
{6D819E80-BA2F-4317-8368-37F8F4434D3A} = {8977A560-45C2-4EC2-A849-97335B382C74}
{47D004BE-F797-430E-8A18-4B0CDFD56643} = {0F3118AE-8D36-4384-8E80-BD6566365305}
{DB96C25F-39A9-4A6A-92BC-D1E42717308F} = {47D004BE-F797-430E-8A18-4B0CDFD56643}
{64EADED3-4B5D-4431-BBE5-A4ABA1C38C00} = {D449D505-CC6A-4E0B-AF1B-976E2D0AE67A}
Expand Down
4 changes: 2 additions & 2 deletions eng/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@
<!--
VS Debugger
-->
<PackageVersion Include="Microsoft.VisualStudio.Debugger.UI.Interfaces" Version="17.9.0-beta.23614.1" />
<PackageVersion Include="Microsoft.VisualStudio.Debugger.Contracts" Version="17.9.0-beta.23614.1" />
<PackageVersion Include="Microsoft.VisualStudio.Debugger.UI.Interfaces" Version="17.9.0-beta.24072.1" />
<PackageVersion Include="Microsoft.VisualStudio.Debugger.Contracts" Version="17.9.0-beta.24072.1" />
<PackageVersion Include="Microsoft.VisualStudio.Debugger.Engine-implementation" Version="17.8.1072001-preview" />
<PackageVersion Include="Microsoft.VisualStudio.Debugger.Metadata-implementation" Version="17.8.1072001-preview" />

Expand Down
1 change: 1 addition & 0 deletions eng/config/PublishData.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler": "vs-impl",
"Microsoft.CodeAnalysis.ExternalAccess.TypeScript": "vs-impl",
"Microsoft.CodeAnalysis.ExternalAccess.UnitTesting": "vs-impl",
"Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics": "vs-impl",
"Microsoft.CodeAnalysis.ExternalAccess.Xamarin.Remote": "vs-impl",
"Microsoft.CodeAnalysis.ExternalAccess.Xaml": "vs-impl",
"Microsoft.CodeAnalysis.ExternalAccess.DotNetWatch": "vs-impl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// 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.Collections.Immutable;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.BrokeredServices;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.ServiceHub.Framework;
using Microsoft.VisualStudio.Composition;
Expand Down Expand Up @@ -30,13 +32,16 @@ internal class ServiceBrokerFactory
private readonly ExportProvider _exportProvider;
private Task _bridgeCompletionTask;
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
private readonly ImmutableArray<IOnServiceBrokerInitialized> _onServiceBrokerInitialized;

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public ServiceBrokerFactory(ExportProvider exportProvider)
public ServiceBrokerFactory([ImportMany] IEnumerable<IOnServiceBrokerInitialized> onServiceBrokerInitialized,
ExportProvider exportProvider)
{
_exportProvider = exportProvider;
_bridgeCompletionTask = Task.CompletedTask;
_onServiceBrokerInitialized = onServiceBrokerInitialized.ToImmutableArray();
}

/// <summary>
Expand Down Expand Up @@ -64,6 +69,17 @@ public async Task CreateAsync()
Contract.ThrowIfFalse(_container == null, "We should only create one container.");

_container = await BrokeredServiceContainer.CreateAsync(_exportProvider, _cancellationTokenSource.Token);

foreach (var onInitialized in _onServiceBrokerInitialized)
{
try
{
onInitialized.OnServiceBrokerInitialized(_container.GetFullAccessServiceBroker());
}
catch (Exception)
{
}
}
}

public async Task CreateAndConnectAsync(string brokeredServicePipeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ internal class Descriptors
{ RemoteProjectInitializationStatusService.Moniker, new ServiceRegistration(ServiceAudience.Local, null, allowGuestClients: false) },
{ BrokeredServiceDescriptors.SolutionSnapshotProvider.Moniker, new ServiceRegistration(ServiceAudience.Local, null, allowGuestClients: false) },
{ BrokeredServiceDescriptors.DebuggerManagedHotReloadService.Moniker, new ServiceRegistration(ServiceAudience.Local, null, allowGuestClients: false) },
{ BrokeredServiceDescriptors.HotReloadSessionNotificationService.Moniker, new ServiceRegistration(ServiceAudience.Local, null, allowGuestClients: false) },
{ BrokeredServiceDescriptors.ManagedHotReloadAgentManagerService.Moniker, new ServiceRegistration(ServiceAudience.Local, null, allowGuestClients: false) },
{ BrokeredServiceDescriptors.MauiLaunchCustomizerServiceDescriptor.Moniker, new ServiceRegistration(ServiceAudience.Local, null, allowGuestClients: false) },
}.ToImmutableDictionary();

public static ServiceJsonRpcDescriptor CreateDescriptor(ServiceMoniker serviceMoniker) => new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

<!-- Not directly referenced but needed for Route embedded language features -->
<ProjectReference Include="..\..\..\Tools\ExternalAccess\AspNetCore\Microsoft.CodeAnalysis.ExternalAccess.AspNetCore.csproj" />
<ProjectReference Include="..\..\..\Tools\ExternalAccess\VisualDiagnostics\Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.csproj" />
<ProjectReference Include="..\..\..\Tools\ExternalAccess\Xaml\Microsoft.CodeAnalysis.ExternalAccess.Xaml.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@

<ItemGroup>
<None Include="Protocol\.editorconfig" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.ServiceHub.Framework;

namespace Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Contracts
{
/// <summary>
/// Workspace service responsible for starting a Visual Diagnostic session on the LSP server
/// </summary>
internal interface IVisualDiagnosticsLanguageService : IWorkspaceService, IDisposable
{
/// <summary>
/// Initialize the diagnostic host
/// </summary>
/// <param name="serviceBroker">Service broker</param>
/// <param name="token">Cancellation token</param>
/// <returns></returns>
Task InitializeAsync(IServiceBroker serviceBroker, CancellationToken token);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// 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;
using System.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.BrokeredServices;
using Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Contracts;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.ServiceHub.Framework;
using Roslyn.LanguageServer.Protocol;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics;

/// <summary>
/// LSP Service responsible for loading IVisualDiagnosticsLanguageService workspace service and delegate the broker service to the workspace service,
/// and handling MAUI XAML/C#/CSS/Razor Hot Reload support
/// </summary>
[Export(typeof(IOnServiceBrokerInitialized))]
[ExportCSharpVisualBasicLspServiceFactory(typeof(OnInitializedService)), Shared]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
[method: ImportingConstructor]
internal sealed class VisualDiagnosticsServiceFactory(
LspWorkspaceRegistrationService lspWorkspaceRegistrationService) : ILspServiceFactory, IOnServiceBrokerInitialized
{
private readonly LspWorkspaceRegistrationService _lspWorkspaceRegistrationService = lspWorkspaceRegistrationService;
private readonly Lazy<OnInitializedService> _OnInitializedService = new Lazy<OnInitializedService>(() => new OnInitializedService(lspWorkspaceRegistrationService));

public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
{
return _OnInitializedService.Value;
}

public void OnServiceBrokerInitialized(IServiceBroker serviceBroker)
{
_OnInitializedService.Value.OnServiceBrokerInitialized(serviceBroker);
}

private class OnInitializedService : ILspService, IOnInitialized, IOnServiceBrokerInitialized, IDisposable
{
private readonly LspWorkspaceRegistrationService _lspWorkspaceRegistrationService;
private IVisualDiagnosticsLanguageService? _visualDiagnosticsLanguageService;
private CancellationToken _cancellationToken;
private static readonly TaskCompletionSource<bool> _taskCompletionSource = new TaskCompletionSource<bool>();

public OnInitializedService(LspWorkspaceRegistrationService lspWorkspaceRegistrationService)
{
_lspWorkspaceRegistrationService = lspWorkspaceRegistrationService;
}

public void Dispose()
{
(_visualDiagnosticsLanguageService as IDisposable)?.Dispose();
}

public Task OnInitializedAsync(ClientCapabilities clientCapabilities, RequestContext context, CancellationToken cancellationToken)
{
_cancellationToken = cancellationToken;
_taskCompletionSource.TrySetResult(true);
return Task.CompletedTask;
}

public void OnServiceBrokerInitialized(IServiceBroker serviceBroker)
{
_taskCompletionSource.Task.ContinueWith((initialized) => OnInitializeVisualDiagnosticsLanguageServiceAsync(serviceBroker), TaskScheduler.Default);
}

private async Task OnInitializeVisualDiagnosticsLanguageServiceAsync(IServiceBroker serviceBroker)
{
// initialize VisualDiagnosticsLanguageService
Workspace workspace = _lspWorkspaceRegistrationService.GetAllRegistrations().First(w => w.Kind == WorkspaceKind.Host);
Contract.ThrowIfFalse(workspace != null, "We should always have a host workspace.");

IVisualDiagnosticsLanguageService? visualDiagnosticsLanguageService = workspace.Services.GetService<IVisualDiagnosticsLanguageService>();

if (visualDiagnosticsLanguageService != null)
{
await visualDiagnosticsLanguageService.InitializeAsync(serviceBroker, _cancellationToken).ConfigureAwait(false);
_visualDiagnosticsLanguageService = visualDiagnosticsLanguageService;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Contracts.IVisualDiagnosticsLanguageService
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Contracts.IVisualDiagnosticsLanguageService.HandleDiagnosticSessionStartAsync(Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Contracts.ProcessInfo info, System.Threading.CancellationToken token) -> System.Threading.Tasks.Task!
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Contracts.IVisualDiagnosticsLanguageService.HandleDiagnosticSessionStopAsync(Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Contracts.ProcessInfo info, System.Threading.CancellationToken token) -> System.Threading.Tasks.Task!
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Contracts.IVisualDiagnosticsLanguageService.InitializeAsync(Microsoft.ServiceHub.Framework.IServiceBroker! serviceBroker, System.Threading.CancellationToken token) -> System.Threading.Tasks.Task!
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Contracts.IVisualDiagnosticsLanguageService.RequestDataBridgeConnectionAsync(string! connectionId, System.Threading.CancellationToken token) -> System.Threading.Tasks.Task<Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Contracts.ConnectionInfo>!
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Contracts.IVisualDiagnosticsServiceBroker
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Contracts.IVisualDiagnosticsServiceBroker.GetServiceBrokerAsync() -> System.Threading.Tasks.Task<Microsoft.ServiceHub.Framework.IServiceBroker!>!
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Internal.VisualDiagnosticsServiceBroker
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Internal.VisualDiagnosticsServiceBroker.NotifyServiceBrokerInitialized.get -> Microsoft.CodeAnalysis.BrokeredServices.IOnServiceBrokerInitialized?
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Internal.VisualDiagnosticsServiceBroker.NotifyServiceBrokerInitialized.set -> void
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Internal.VisualDiagnosticsServiceBroker.OnServiceBrokerInitialized(Microsoft.ServiceHub.Framework.IServiceBroker! serviceBroker) -> void
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.Internal.VisualDiagnosticsServiceBroker.VisualDiagnosticsServiceBroker() -> void
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.RunningProcessEntry
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.RunningProcessEntry.RunningProcessEntry() -> void
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.VisualDiagnosticsServiceFactory
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.VisualDiagnosticsServiceFactory.CreateILspService(Microsoft.CodeAnalysis.LanguageServer.LspServices! lspServices, Microsoft.CodeAnalysis.LanguageServer.WellKnownLspServerKinds serverKind) -> Microsoft.CodeAnalysis.LanguageServer.ILspService!
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.VisualDiagnosticsServiceFactory.OnServiceBrokerInitialized(Microsoft.ServiceHub.Framework.IServiceBroker! serviceBroker) -> void
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.VisualDiagnosticsServiceFactory.VisualDiagnosticsServiceFactory(Microsoft.CodeAnalysis.LanguageServer.LspWorkspaceRegistrationService! lspWorkspaceRegistrationService) -> void
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>

<!-- NuGet -->
<IsPackable>true</IsPackable>
<PackageId>Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics</PackageId>
<PackageDescription>
A supporting package for Visual Studio Microsoft.VisualStudio.DesignTools.CodeAnalysis.Diagnostics:
https://devdiv.visualstudio.com/DevDiv/_git/VS?path=/src/Xaml/Diagnostics/Source/CodeAnalysisDiagnostics
</PackageDescription>
</PropertyGroup>
<ItemGroup>
<!-- ⚠ Only designTools assemblies should be added here ⚠ -->
<InternalsVisibleTo Include="Microsoft.VisualStudio.DesignTools.CodeAnalysis" Key="$(VisualStudioKey)" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.DesignTools.CodeAnalysis.Diagnostics" Key="$(VisualStudioKey)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
<ProjectReference Include="..\..\..\Features\Core\Portable\Microsoft.CodeAnalysis.Features.csproj" />
<ProjectReference Include="..\..\..\Features\LanguageServer\Protocol\Microsoft.CodeAnalysis.LanguageServer.Protocol.csproj" />
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
<ProjectReference Include="..\..\..\Workspaces\Remote\Core\Microsoft.CodeAnalysis.Remote.Workspaces.csproj" />
</ItemGroup>
<ItemGroup>
<PublicAPI Include="PublicAPI.Shipped.txt" />
<PublicAPI Include="PublicAPI.Unshipped.txt" />
<PublicAPI Include="InternalAPI.Shipped.txt" />
<PublicAPI Include="InternalAPI.Unshipped.txt" />
</ItemGroup>
</Project>
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.Razor.UnitTests"/>
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.Xaml" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.EditorConfigGenerator" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.TypeScript.EditorFeatures" Key="$(TypeScriptKey)" WorkItem="https://github.com/dotnet/roslyn/issues/35077" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.TypeScript" Key="$(TypeScriptKey)" WorkItem="https://github.com/dotnet/roslyn/issues/35077" />
<InternalsVisibleTo Include="Roslyn.Services.Editor.TypeScript.UnitTests" Key="$(TypeScriptKey)" WorkItem="https://github.com/dotnet/roslyn/issues/35077" />
Expand Down
Loading

0 comments on commit 0f35ec3

Please sign in to comment.