-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72296 from chabiss/vdiag-lsp
Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics
- Loading branch information
Showing
18 changed files
with
231 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Tools/ExternalAccess/VisualDiagnostics/Contracts/IVisualDiagnosticsLanguageService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/Tools/ExternalAccess/VisualDiagnostics/Internal/VisualDiagnosticsServiceFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/Tools/ExternalAccess/VisualDiagnostics/InternalAPI.Shipped.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#nullable enable |
18 changes: 18 additions & 0 deletions
18
src/Tools/ExternalAccess/VisualDiagnostics/InternalAPI.Unshipped.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
35 changes: 35 additions & 0 deletions
35
...alAccess/VisualDiagnostics/Microsoft.CodeAnalysis.ExternalAccess.VisualDiagnostics.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.