Skip to content

Commit

Permalink
Add support for exporting services that are created for each server
Browse files Browse the repository at this point in the history
instance.
  • Loading branch information
dibarbet committed May 13, 2022
1 parent 4ca1035 commit 9efe740
Show file tree
Hide file tree
Showing 129 changed files with 1,710 additions and 1,428 deletions.
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,42 @@
// 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(RequestDispatcher), ProtocolConstants.TypeScriptLanguageContract), Shared]
internal class VSTypeScriptRequestDispatcherFactory : RequestDispatcherFactory
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VSTypeScriptRequestDispatcherFactory()
{
}
}

[ExportLspServiceFactory(typeof(LspWorkspaceManager), ProtocolConstants.TypeScriptLanguageContract), Shared]
internal class VSTypeScriptLspWorkspaceManagerFactory : LspWorkspaceManagerFactory
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VSTypeScriptLspWorkspaceManagerFactory(LspWorkspaceRegistrationService lspWorkspaceRegistrationService) : base(lspWorkspaceRegistrationService)
{
}
}

[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 @@ -7,23 +7,17 @@
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
[Export, Shared]
internal class VSTypeScriptLspServiceProvider : AbstractLspServiceProvider
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VSTypeScriptRequestDispatcherFactory(
[ImportMany(ProtocolConstants.TypeScriptLanguageContract)] IEnumerable<Lazy<IRequestHandlerProvider, RequestHandlerProviderMetadataView>> requestHandlerProviders) : base(requestHandlerProviders)
public VSTypeScriptLspServiceProvider(
[ImportMany(ProtocolConstants.TypeScriptLanguageContract)] IEnumerable<Lazy<ILspService, LspServiceMetadataView>> lspServices,
[ImportMany(ProtocolConstants.TypeScriptLanguageContract)] IEnumerable<Lazy<ILspServiceFactory, LspServiceMetadataView>> lspServiceFactories) : base(lspServices, lspServiceFactories)
{
}

public override RequestDispatcher CreateRequestDispatcher(WellKnownLspServerKinds serverKind)
{
return base.CreateRequestDispatcher(serverKind);
}
}
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,
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 @@ -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,
RoslynLspServiceProvider 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>
[ExportRoslynStatelessLspService(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>();
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,22 +2,38 @@
// 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;

namespace Microsoft.CodeAnalysis.LanguageServer.Handler.CodeActions
{
[ExportRoslynLspServiceFactory(typeof(CodeActionsCache)), Shared]
internal class CodeActionsCacheFactory : ILspServiceFactory
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CodeActionsCacheFactory()
{
}

public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind) => new CodeActionsCache();
}

/// <summary>
/// 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

0 comments on commit 9efe740

Please sign in to comment.