Skip to content

Commit 85406c0

Browse files
committed
Move LSP client integration down to editor features to support VSMac
1 parent 8b8f4fa commit 85406c0

26 files changed

+136
-30
lines changed

src/EditorFeatures/Core/Implementation/LanguageServer/AbstractInProcLanguageClient.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
using System.Threading.Tasks;
1111
using Microsoft.CodeAnalysis;
1212
using Microsoft.CodeAnalysis.Diagnostics;
13+
using Microsoft.CodeAnalysis.Editor.Implementation.LanguageServer;
1314
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
15+
using Microsoft.CodeAnalysis.Host;
1416
using Microsoft.CodeAnalysis.LanguageServer;
1517
using Microsoft.CodeAnalysis.Shared.TestHooks;
1618
using Microsoft.VisualStudio.LanguageServer.Client;
@@ -36,7 +38,7 @@ internal abstract partial class AbstractInProcLanguageClient : ILanguageClient,
3638
private readonly AbstractRequestDispatcherFactory _requestDispatcherFactory;
3739
private readonly ILspWorkspaceRegistrationService _lspWorkspaceRegistrationService;
3840

39-
protected readonly Workspace Workspace;
41+
protected readonly HostWorkspaceServices WorkspaceServices;
4042

4143
/// <summary>
4244
/// Created when <see cref="ActivateAsync"/> is called.
@@ -81,7 +83,7 @@ public event AsyncEventHandler<EventArgs>? StopAsync { add { } remove { } }
8183

8284
public AbstractInProcLanguageClient(
8385
AbstractRequestDispatcherFactory requestDispatcherFactory,
84-
VisualStudioWorkspace workspace,
86+
ILspWorkspaceServicesProvider workspaceServicesProvider,
8587
IDiagnosticService? diagnosticService,
8688
IAsynchronousOperationListenerProvider listenerProvider,
8789
ILspWorkspaceRegistrationService lspWorkspaceRegistrationService,
@@ -90,13 +92,14 @@ public AbstractInProcLanguageClient(
9092
string? diagnosticsClientName)
9193
{
9294
_requestDispatcherFactory = requestDispatcherFactory;
93-
Workspace = workspace;
9495
_diagnosticService = diagnosticService;
9596
_listenerProvider = listenerProvider;
9697
_lspWorkspaceRegistrationService = lspWorkspaceRegistrationService;
9798
_diagnosticsClientName = diagnosticsClientName;
9899
_lspLoggerFactory = lspLoggerFactory;
99100
_threadingContext = threadingContext;
101+
102+
WorkspaceServices = workspaceServicesProvider.GetHostWorkspaceServices();
100103
}
101104

102105
public async Task<Connection?> ActivateAsync(CancellationToken cancellationToken)

src/EditorFeatures/Core/Implementation/LanguageServer/AlwaysActivateInProcLanguageClient.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.ComponentModel.Composition;
88
using Microsoft.CodeAnalysis.Diagnostics;
99
using Microsoft.CodeAnalysis.Editor;
10+
using Microsoft.CodeAnalysis.Editor.Implementation.LanguageServer;
1011
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
1112
using Microsoft.CodeAnalysis.Experiments;
1213
using Microsoft.CodeAnalysis.Host.Mef;
@@ -36,13 +37,13 @@ internal class AlwaysActivateInProcLanguageClient : AbstractInProcLanguageClient
3637
[Obsolete(MefConstruction.ImportingConstructorMessage, true)]
3738
public AlwaysActivateInProcLanguageClient(
3839
RequestDispatcherFactory csharpVBRequestDispatcherFactory,
39-
VisualStudioWorkspace workspace,
40+
ILspWorkspaceServicesProvider workspaceServices,
4041
IAsynchronousOperationListenerProvider listenerProvider,
4142
ILspWorkspaceRegistrationService lspWorkspaceRegistrationService,
4243
DefaultCapabilitiesProvider defaultCapabilitiesProvider,
4344
ILspLoggerFactory lspLoggerFactory,
4445
IThreadingContext threadingContext)
45-
: base(csharpVBRequestDispatcherFactory, workspace, diagnosticService: null, listenerProvider, lspWorkspaceRegistrationService, lspLoggerFactory, threadingContext, diagnosticsClientName: null)
46+
: base(csharpVBRequestDispatcherFactory, workspaceServices, diagnosticService: null, listenerProvider, lspWorkspaceRegistrationService, lspLoggerFactory, threadingContext, diagnosticsClientName: null)
4647
{
4748
_defaultCapabilitiesProvider = defaultCapabilitiesProvider;
4849
}
@@ -56,7 +57,7 @@ public override ServerCapabilities GetCapabilities(ClientCapabilities clientCapa
5657
var serverCapabilities = new VSInternalServerCapabilities();
5758

5859
// If the LSP editor feature flag is enabled advertise support for LSP features here so they are available locally and remote.
59-
var isLspEditorEnabled = Workspace.Services.GetRequiredService<IExperimentationService>().IsExperimentEnabled(DefaultWorkspaceContextService.LspEditorFeatureFlagName);
60+
var isLspEditorEnabled = WorkspaceServices.GetRequiredService<IExperimentationService>().IsExperimentEnabled(DefaultWorkspaceContextService.LspEditorFeatureFlagName);
6061
if (isLspEditorEnabled)
6162
{
6263
serverCapabilities = (VSInternalServerCapabilities)_defaultCapabilitiesProvider.GetCapabilities(clientCapabilities);
@@ -71,7 +72,7 @@ public override ServerCapabilities GetCapabilities(ClientCapabilities clientCapa
7172
};
7273
}
7374

74-
serverCapabilities.SupportsDiagnosticRequests = Workspace.IsPullDiagnostics(InternalDiagnosticsOptions.NormalDiagnosticMode);
75+
serverCapabilities.SupportsDiagnosticRequests = WorkspaceServices.IsPullDiagnostics(InternalDiagnosticsOptions.NormalDiagnosticMode);
7576

7677
// This capability is always enabled as we provide cntrl+Q VS search only via LSP in ever scenario.
7778
serverCapabilities.WorkspaceSymbolProvider = true;
@@ -89,6 +90,6 @@ public override ServerCapabilities GetCapabilities(ClientCapabilities clientCapa
8990
/// they will get no diagnostics. When not enabled we don't show the failure box (failure will still be recorded in the task status center)
9091
/// as the failure is not catastrophic.
9192
/// </summary>
92-
public override bool ShowNotificationOnInitializeFailed => Workspace.IsPullDiagnostics(InternalDiagnosticsOptions.NormalDiagnosticMode);
93+
public override bool ShowNotificationOnInitializeFailed => WorkspaceServices.IsPullDiagnostics(InternalDiagnosticsOptions.NormalDiagnosticMode);
9394
}
9495
}

src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/CodeActions/CodeActionResolveHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler
2626
/// system allows the basic code action data to be computed quickly, and the
2727
/// complex data, such as edits and commands, to be computed only when necessary
2828
/// (i.e. when hovering/previewing a code action).
29+
///
30+
/// TODO - This must be moved to the MS.CA.LanguageServer.Protocol project once the
31+
/// EditorFeatures references in <see cref="RunCodeActionHandler"/> are removed.
32+
/// See https://github.com/dotnet/roslyn/issues/55142
2933
/// </summary>
3034
internal class CodeActionResolveHandler : IRequestHandler<LSP.CodeAction, LSP.CodeAction>
3135
{

src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/CodeActions/CodeActionsHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler
1717
/// Handles the initial request for code actions. Leaves the Edit and Command properties
1818
/// of the returned VSCodeActions blank, as these properties should be populated by the
1919
/// CodeActionsResolveHandler only when the user requests them.
20+
///
21+
/// TODO - This must be moved to the MS.CA.LanguageServer.Protocol project once the
22+
/// EditorFeatures references in <see cref="RunCodeActionHandler"/> are removed.
23+
/// See https://github.com/dotnet/roslyn/issues/55142
2024
/// </summary>
2125
internal class CodeActionsHandler : IRequestHandler<LSP.CodeActionParams, LSP.CodeAction[]>
2226
{

src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/CodeActions/RunCodeActionHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler
2323
/// TO-DO: Currently, any ApplyChangesOperation that adds or removes a document must also be
2424
/// applied as a command due to an LSP bug (see https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1147293/).
2525
/// Commands must be applied from the UI thread in VS.
26+
///
27+
/// TODO - This must be moved to the MS.CA.LanguageServer.Protocol project once the
28+
/// UI thread dependencies are resolved and <see cref="IThreadingContext"/> references are removed.
29+
/// See https://github.com/dotnet/roslyn/issues/55142
2630
/// </summary>
2731
internal class RunCodeActionHandler : AbstractExecuteWorkspaceCommandHandler
2832
{

src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/Completion/CompletionHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler
2727
{
2828
/// <summary>
2929
/// Handle a completion request.
30+
///
31+
/// TODO - This must be moved to the MS.CA.LanguageServer.Protocol project once the
32+
/// references to VS Icon types are removed.
33+
/// See https://github.com/dotnet/roslyn/issues/55142
3034
/// </summary>
3135
internal class CompletionHandler : IRequestHandler<LSP.CompletionParams, LSP.CompletionList?>
3236
{

src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/Completion/CompletionResolveHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler
1818
{
1919
/// <summary>
2020
/// Handle a completion resolve request to add description.
21+
///
22+
/// TODO - This must be moved to the MS.CA.LanguageServer.Protocol project once the
23+
/// references to VS icon types and classified text runs are removed.
24+
/// See https://github.com/dotnet/roslyn/issues/55142
2125
/// </summary>
2226
internal class CompletionResolveHandler : IRequestHandler<LSP.CompletionItem, LSP.CompletionItem>
2327
{

src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/Hover/HoverHandler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919

2020
namespace Microsoft.CodeAnalysis.LanguageServer.Handler
2121
{
22+
/// <summary>
23+
/// TODO - This must be moved to the MS.CA.LanguageServer.Protocol project once it
24+
/// no longer references VS icon or classified text run types.
25+
/// See https://github.com/dotnet/roslyn/issues/55142
26+
/// </summary>
2227
[ExportRoslynLanguagesLspRequestHandlerProvider, Shared]
2328
[ProvidesMethod(Methods.TextDocumentHoverName)]
2429
internal class HoverHandler : AbstractStatelessRequestHandler<TextDocumentPositionParams, Hover?>

src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/References/FindAllReferencesHandler.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919
namespace Microsoft.CodeAnalysis.LanguageServer.Handler
2020
{
21+
/// <summary>
22+
/// TODO - This must be moved to the MS.CA.LanguageServer.Protocol project once
23+
/// the <see cref="IFindUsagesService"/> is moved down to the features layer and
24+
/// we no longer reference VS classified text runs.
25+
/// See https://github.com/dotnet/roslyn/issues/55142
26+
/// </summary>
2127
[ExportRoslynLanguagesLspRequestHandlerProvider, Shared]
2228
[ProvidesMethod(LSP.Methods.TextDocumentReferencesName)]
2329
internal class FindAllReferencesHandler : AbstractStatelessRequestHandler<LSP.ReferenceParams, LSP.VSInternalReferenceItem[]?>

src/EditorFeatures/Core/Implementation/LanguageServer/Handlers/Rename/RenameHandler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
namespace Microsoft.CodeAnalysis.LanguageServer.Handler
1818
{
19+
/// <summary>
20+
/// TODO - This must be moved to the MS.CA.LanguageServer.Protocol project once
21+
/// we no longer reference the <see cref="IInlineRenameService"/>
22+
/// See https://github.com/dotnet/roslyn/issues/55142
23+
/// </summary>
1924
[ExportRoslynLanguagesLspRequestHandlerProvider, Shared]
2025
[ProvidesMethod(LSP.Methods.TextDocumentRenameName)]
2126
internal class RenameHandler : AbstractStatelessRequestHandler<LSP.RenameParams, WorkspaceEdit?>

0 commit comments

Comments
 (0)