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

[LSP] Support LSP services associated with LSP server instances (with lifetimes that match). #61266

Merged
merged 8 commits into from
May 17, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.Collections.Generic;
using System.Text;
using Microsoft.CodeAnalysis.LanguageServer;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;
internal abstract class AbstractVSTypeScriptRequestHandlerFactory : ILspServiceFactory
{
public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
{
return CreateRequestHandler();
}

protected abstract IVSTypeScriptRequestHandler CreateRequestHandler();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.VisualStudio.LanguageServer.Protocol;

Expand Down Expand Up @@ -65,6 +66,6 @@ internal record struct TypeScriptRequestContext(Solution? Solution, Document? Do
/// </summary>
internal record struct TypeScriptTextDocumentIdentifier(Uri Uri, string? ProjectId);

internal interface IVSTypeScriptRequestHandler
internal interface IVSTypeScriptRequestHandler : ILspService
{
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api;

[AttributeUsage(AttributeTargets.Class), MetadataAttribute]
internal class ExportTypeScriptLspRequestHandlerProviderAttribute : ExportLspRequestHandlerProviderAttribute
internal class ExportTypeScriptLspServiceFactoryAttribute : ExportLspServiceFactoryAttribute
{
public ExportTypeScriptLspRequestHandlerProviderAttribute(Type firstHandlerType, params Type[] additionalHandlerTypes) : base(ProtocolConstants.TypeScriptLanguageContract, firstHandlerType, additionalHandlerTypes)
public ExportTypeScriptLspServiceFactoryAttribute(Type handlerType) : base(handlerType, ProtocolConstants.TypeScriptLanguageContract)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript;

[Shared]
[ExportLspRequestHandlerProvider(ProtocolConstants.TypeScriptLanguageContract, typeof(DidChangeHandler))]
[ExportStatelessLspService(typeof(DidChangeHandler), ProtocolConstants.TypeScriptLanguageContract), Shared]
internal class VSTypeScriptDidChangeHandler : DidChangeHandler
{
[ImportingConstructor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript;

[Shared]
[ExportLspRequestHandlerProvider(ProtocolConstants.TypeScriptLanguageContract, typeof(DidCloseHandler))]
[ExportStatelessLspService(typeof(DidCloseHandler), ProtocolConstants.TypeScriptLanguageContract), Shared]
internal class VSTypeScriptDidCloseHandler : DidCloseHandler
{
[ImportingConstructor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript;

[Shared]
[ExportLspRequestHandlerProvider(ProtocolConstants.TypeScriptLanguageContract, typeof(DidOpenHandler))]
[ExportStatelessLspService(typeof(DidOpenHandler), ProtocolConstants.TypeScriptLanguageContract), Shared]
internal class VSTypeScriptDidOpenHandler : DidOpenHandler
{
[ImportingConstructor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ internal class VSTypeScriptInProcLanguageClient : AbstractInProcLanguageClient
[Obsolete(MefConstruction.ImportingConstructorMessage, true)]
public VSTypeScriptInProcLanguageClient(
[Import(AllowDefault = true)] IVSTypeScriptCapabilitiesProvider? typeScriptCapabilitiesProvider,
VSTypeScriptRequestDispatcherFactory requestDispatcherFactory,
VSTypeScriptLspServiceProvider lspServiceProvider,
IGlobalOptionService globalOptions,
IAsynchronousOperationListenerProvider listenerProvider,
LspWorkspaceRegistrationService lspWorkspaceRegistrationService,
DefaultCapabilitiesProvider defaultCapabilitiesProvider,
ILspLoggerFactory lspLoggerFactory,
IThreadingContext threadingContext)
: base(requestDispatcherFactory, globalOptions, listenerProvider, lspWorkspaceRegistrationService, lspLoggerFactory, threadingContext)
: base(lspServiceProvider, globalOptions, listenerProvider, lspLoggerFactory, threadingContext)
{
_typeScriptCapabilitiesProvider = typeScriptCapabilitiesProvider;
}
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;
using System.Collections.Generic;
using System.Composition;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript;

[Export(typeof(VSTypeScriptLspServiceProvider)), Shared]
internal class VSTypeScriptLspServiceProvider : AbstractLspServiceProvider
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VSTypeScriptLspServiceProvider(
[ImportMany(ProtocolConstants.TypeScriptLanguageContract)] IEnumerable<Lazy<ILspService, LspServiceMetadataView>> lspServices,
[ImportMany(ProtocolConstants.TypeScriptLanguageContract)] IEnumerable<Lazy<ILspServiceFactory, LspServiceMetadataView>> lspServiceFactories) : base(lspServices, lspServiceFactories)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript;

[ExportLspServiceFactory(typeof(LspWorkspaceManager), ProtocolConstants.TypeScriptLanguageContract), Shared]
internal class VSTypeScriptLspWorkspaceManagerFactory : LspWorkspaceManagerFactory
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VSTypeScriptLspWorkspaceManagerFactory(LspWorkspaceRegistrationService lspWorkspaceRegistrationService) : base(lspWorkspaceRegistrationService)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,34 @@
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics;
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript
namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript;

[ExportLspServiceFactory(typeof(DocumentPullDiagnosticHandler), ProtocolConstants.TypeScriptLanguageContract), Shared]
internal class VSTypeScriptDocumentPullDiagnosticHandlerFactory : DocumentPullDiagnosticHandlerFactory
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VSTypeScriptDocumentPullDiagnosticHandlerFactory(
IDiagnosticService diagnosticService,
IDiagnosticAnalyzerService analyzerService,
EditAndContinueDiagnosticUpdateSource editAndContinueDiagnosticUpdateSource,
dibarbet marked this conversation as resolved.
Show resolved Hide resolved
IGlobalOptionService globalOptions) : base(diagnosticService, analyzerService, editAndContinueDiagnosticUpdateSource, globalOptions)
{
}
}

[ExportLspServiceFactory(typeof(WorkspacePullDiagnosticHandler), ProtocolConstants.TypeScriptLanguageContract), Shared]
internal class VSTypeScriptWorkspacePullDiagnosticHandler : WorkspacePullDiagnosticHandlerFactory
{
[Shared]
[ExportLspRequestHandlerProvider(ProtocolConstants.TypeScriptLanguageContract, typeof(DocumentPullDiagnosticHandler), typeof(WorkspacePullDiagnosticHandler))]
internal class VSTypeScriptPullDiagnosticHandlerProvider : PullDiagnosticHandlerProvider
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VSTypeScriptWorkspacePullDiagnosticHandler(
IDiagnosticService diagnosticService,
EditAndContinueDiagnosticUpdateSource editAndContinueDiagnosticUpdateSource,
IGlobalOptionService globalOptions) : base(diagnosticService, editAndContinueDiagnosticUpdateSource, globalOptions)
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VSTypeScriptPullDiagnosticHandlerProvider(
IDiagnosticService diagnosticService,
IDiagnosticAnalyzerService analyzerService,
EditAndContinueDiagnosticUpdateSource editAndContinueDiagnosticUpdateSource) : base(diagnosticService, analyzerService, editAndContinueDiagnosticUpdateSource)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,18 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Composition;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.Handler;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript;

[Shared]
[Export(typeof(VSTypeScriptRequestDispatcherFactory))]
internal class VSTypeScriptRequestDispatcherFactory : AbstractRequestDispatcherFactory
[ExportLspServiceFactory(typeof(RequestDispatcher), ProtocolConstants.TypeScriptLanguageContract), Shared]
internal class VSTypeScriptRequestDispatcherFactory : RequestDispatcherFactory
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VSTypeScriptRequestDispatcherFactory(
[ImportMany(ProtocolConstants.TypeScriptLanguageContract)] IEnumerable<Lazy<IRequestHandlerProvider, RequestHandlerProviderMetadataView>> requestHandlerProviders) : base(requestHandlerProviders)
public VSTypeScriptRequestDispatcherFactory()
{
}

public override RequestDispatcher CreateRequestDispatcher(WellKnownLspServerKinds serverKind)
{
return base.CreateRequestDispatcher(serverKind);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.Collections.Generic;
using System.Composition;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.Handler;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript;

[ExportLspServiceFactory(typeof(RequestTelemetryLogger), ProtocolConstants.TypeScriptLanguageContract), Shared]
internal class VSTypeScriptRequestTelemetryLoggerFactory : RequestTelemetryLoggerFactory
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VSTypeScriptRequestTelemetryLoggerFactory()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ internal abstract partial class AbstractInProcLanguageClient : ILanguageClient,
private readonly ILspLoggerFactory _lspLoggerFactory;

private readonly IAsynchronousOperationListenerProvider _listenerProvider;
private readonly AbstractRequestDispatcherFactory _requestDispatcherFactory;
private readonly LspWorkspaceRegistrationService _lspWorkspaceRegistrationService;
private readonly AbstractLspServiceProvider _lspServiceProvider;

protected readonly IGlobalOptionService GlobalOptions;

Expand Down Expand Up @@ -100,18 +99,16 @@ internal abstract partial class AbstractInProcLanguageClient : ILanguageClient,
public event AsyncEventHandler<EventArgs>? StopAsync { add { } remove { } }

public AbstractInProcLanguageClient(
AbstractRequestDispatcherFactory requestDispatcherFactory,
AbstractLspServiceProvider lspServiceProvider,
IGlobalOptionService globalOptions,
IAsynchronousOperationListenerProvider listenerProvider,
LspWorkspaceRegistrationService lspWorkspaceRegistrationService,
ILspLoggerFactory lspLoggerFactory,
IThreadingContext threadingContext,
AbstractLanguageClientMiddleLayer? middleLayer = null)
{
_requestDispatcherFactory = requestDispatcherFactory;
_lspServiceProvider = lspServiceProvider;
GlobalOptions = globalOptions;
_listenerProvider = listenerProvider;
_lspWorkspaceRegistrationService = lspWorkspaceRegistrationService;
_lspLoggerFactory = lspLoggerFactory;
_threadingContext = threadingContext;
_middleLayer = middleLayer;
Expand Down Expand Up @@ -227,12 +224,9 @@ public ILanguageServerTarget Create(
ILspLogger logger)
{
return new LanguageServerTarget(
_requestDispatcherFactory,
_lspServiceProvider,
jsonRpc,
capabilitiesProvider,
_lspWorkspaceRegistrationService,
lspMiscellaneousFilesWorkspace: null,
GlobalOptions,
_listenerProvider,
logger,
SupportedLanguages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ internal class AlwaysActivateInProcLanguageClient : AbstractInProcLanguageClient
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, true)]
public AlwaysActivateInProcLanguageClient(
RequestDispatcherFactory csharpVBRequestDispatcherFactory,
CSharpVisualBasicLspServiceProvider lspServiceProvider,
IGlobalOptionService globalOptions,
IAsynchronousOperationListenerProvider listenerProvider,
LspWorkspaceRegistrationService lspWorkspaceRegistrationService,
DefaultCapabilitiesProvider defaultCapabilitiesProvider,
ILspLoggerFactory lspLoggerFactory,
IThreadingContext threadingContext)
: base(csharpVBRequestDispatcherFactory, globalOptions, listenerProvider, lspWorkspaceRegistrationService, lspLoggerFactory, threadingContext)
: base(lspServiceProvider, globalOptions, listenerProvider, lspLoggerFactory, threadingContext)
{
_defaultCapabilitiesProvider = defaultCapabilitiesProvider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

using System;
using System.Collections.Generic;
using System.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer.Handler.CodeActions;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.PooledObjects;
Expand All @@ -32,21 +34,21 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler
/// EditorFeatures references in <see cref="RunCodeActionHandler"/> are removed.
/// See https://github.com/dotnet/roslyn/issues/55142
/// </summary>
[ExportCSharpVisualBasicStatelessLspService(typeof(CodeActionResolveHandler)), Shared]
[Method(LSP.Methods.CodeActionResolveName)]
internal class CodeActionResolveHandler : IRequestHandler<LSP.CodeAction, LSP.CodeAction>
{
private readonly CodeActionsCache _codeActionsCache;
private readonly ICodeFixService _codeFixService;
private readonly ICodeRefactoringService _codeRefactoringService;
private readonly IGlobalOptionService _globalOptions;

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CodeActionResolveHandler(
CodeActionsCache codeActionsCache,
ICodeFixService codeFixService,
ICodeRefactoringService codeRefactoringService,
IGlobalOptionService globalOptions)
{
_codeActionsCache = codeActionsCache;
_codeFixService = codeFixService;
_codeRefactoringService = codeRefactoringService;
_globalOptions = globalOptions;
Expand All @@ -68,8 +70,9 @@ public CodeActionResolveHandler(

var options = _globalOptions.GetCodeActionOptionsProvider();

var codeActionsCache = context.GetRequiredLspService<CodeActionsCache>();
dibarbet marked this conversation as resolved.
Show resolved Hide resolved
var codeActions = await CodeActionHelpers.GetCodeActionsAsync(
_codeActionsCache,
codeActionsCache,
document,
data.Range,
options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
// 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.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer.Handler.Completion;
using Microsoft.CodeAnalysis.UnifiedSuggestions;
using Roslyn.Utilities;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
Expand All @@ -17,7 +21,7 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler.CodeActions
/// Caches suggested action sets between calls to <see cref="CodeActionsHandler"/> and
/// <see cref="CodeActionResolveHandler"/>.
/// </summary>
internal class CodeActionsCache
internal class CodeActionsCache : ILspService
{
/// <summary>
/// Ensures we aren't making concurrent modifications to the list of cached items.
Expand Down
Loading