Skip to content

Commit

Permalink
Merge pull request #65898 from dibarbet/fix_xaml_lsp
Browse files Browse the repository at this point in the history
Fix XAML LSP by using a queue provider instead of subclassing
  • Loading branch information
dibarbet authored Dec 9, 2022
2 parents 8c2f046 + 61bb1b9 commit 1100e56
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 System.Text;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.CommonLanguageServerProtocol.Framework;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript;

[ExportStatelessLspService(typeof(IRequestExecutionQueueProvider<RequestContext>), ProtocolConstants.TypeScriptLanguageContract), Shared]
internal sealed class VSTypeScriptRequestExecutionQueueProvider : IRequestExecutionQueueProvider<RequestContext>
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, true)]
public VSTypeScriptRequestExecutionQueueProvider()
{
}

public IRequestExecutionQueue<RequestContext> CreateRequestExecutionQueue(AbstractLanguageServer<RequestContext> languageServer, ILspLogger logger, IHandlerProvider handlerProvider)
{
var queue = new RoslynRequestExecutionQueue(languageServer, logger, handlerProvider);
queue.Start();
return queue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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 Microsoft.CommonLanguageServerProtocol.Framework;

namespace Microsoft.CodeAnalysis.LanguageServer;

internal interface IRequestExecutionQueueProvider<RequestContext> : ILspService
{
IRequestExecutionQueue<RequestContext> CreateRequestExecutionQueue(AbstractLanguageServer<RequestContext> languageServer, ILspLogger logger, IHandlerProvider handlerProvider);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.Handler;
using Microsoft.CommonLanguageServerProtocol.Framework;

namespace Microsoft.CodeAnalysis.LanguageServer;

[ExportCSharpVisualBasicStatelessLspService(typeof(IRequestExecutionQueueProvider<RequestContext>)), Shared]
internal sealed class RequestExecutionQueueProvider : IRequestExecutionQueueProvider<RequestContext>
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, true)]
public RequestExecutionQueueProvider()
{
}

public IRequestExecutionQueue<RequestContext> CreateRequestExecutionQueue(AbstractLanguageServer<RequestContext> languageServer, ILspLogger logger, IHandlerProvider handlerProvider)
{
var queue = new RoslynRequestExecutionQueue(languageServer, logger, handlerProvider);
queue.Start();
return queue;
}
}
9 changes: 3 additions & 6 deletions src/Features/LanguageServer/Protocol/RoslynLanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Microsoft.CodeAnalysis.LanguageServer
{
internal class RoslynLanguageServer : AbstractLanguageServer<RequestContext>, IClientCapabilitiesProvider
internal sealed class RoslynLanguageServer : AbstractLanguageServer<RequestContext>, IClientCapabilitiesProvider
{
private readonly AbstractLspServiceProvider _lspServiceProvider;
private readonly ImmutableDictionary<Type, ImmutableArray<Func<ILspServices, object>>> _baseServices;
Expand Down Expand Up @@ -49,11 +49,8 @@ protected override ILspServices ConstructLspServices()

protected override IRequestExecutionQueue<RequestContext> ConstructRequestExecutionQueue()
{
var handlerProvider = GetHandlerProvider();
var queue = new RoslynRequestExecutionQueue(this, _logger, handlerProvider);

queue.Start();
return queue;
var provider = GetLspServices().GetRequiredService<IRequestExecutionQueueProvider<RequestContext>>();
return provider.CreateRequestExecutionQueue(this, _logger, GetHandlerProvider());
}

private ImmutableDictionary<Type, ImmutableArray<Func<ILspServices, object>>> GetBaseServices(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,16 @@ namespace Microsoft.VisualStudio.LanguageServices.Xaml
[Export(typeof(ILanguageClient))]
internal class XamlInProcLanguageClient : AbstractInProcLanguageClient
{
private readonly XamlProjectService _projectService;
private readonly IXamlLanguageServerFeedbackService? _feedbackService;

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, true)]
public XamlInProcLanguageClient(
XamlLspServiceProvider lspServiceProvider,
IGlobalOptionService globalOptions,
ILspServiceLoggerFactory lspLoggerFactory,
IThreadingContext threadingContext,
ExportProvider exportProvider,
XamlProjectService projectService,
[Import(AllowDefault = true)] IXamlLanguageServerFeedbackService? feedbackService)
ExportProvider exportProvider)
: base(lspServiceProvider, globalOptions, lspLoggerFactory, threadingContext, exportProvider)
{
_projectService = projectService;
_feedbackService = feedbackService;
}

protected override ImmutableArray<string> SupportedLanguages => ImmutableArray.Create(StringConstants.XamlLanguageName);
Expand All @@ -64,16 +57,6 @@ public override ServerCapabilities GetCapabilities(ClientCapabilities clientCapa
return isLspExperimentEnabled ? XamlCapabilities.Current : XamlCapabilities.None;
}

public override AbstractLanguageServer<RequestContext> Create(
JsonRpc jsonRpc,
ICapabilitiesProvider capabilitiesProvider,
WellKnownLspServerKinds serverKind,
ILspServiceLogger logger,
HostServices hostServices)
{
return new XamlLanguageServer(LspServiceProvider, jsonRpc, capabilitiesProvider, logger, SupportedLanguages, serverKind, hostServices, _projectService, _feedbackService);
}

/// <summary>
/// Failures are only catastrophic when this server is providing intellisense features.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.CommonLanguageServerProtocol.Framework;
Expand All @@ -17,29 +19,24 @@
using StreamJsonRpc;

namespace Microsoft.VisualStudio.LanguageServices.Xaml.Implementation.LanguageServer;
internal class XamlLanguageServer : RoslynLanguageServer

[ExportStatelessXamlLspService(typeof(IRequestExecutionQueueProvider<RequestContext>)), Shared]
internal sealed class XamlRequestExecutionQueueProvider : IRequestExecutionQueueProvider<RequestContext>
{
private readonly XamlProjectService _projectService;
private readonly IXamlLanguageServerFeedbackService? _feedbackService;

public XamlLanguageServer(
AbstractLspServiceProvider lspServiceProvider,
JsonRpc jsonRpc,
ICapabilitiesProvider capabilitiesProvider,
ILspServiceLogger logger,
ImmutableArray<string> supportedLanguages,
WellKnownLspServerKinds serverKind,
HostServices hostServices,
XamlProjectService projectService,
IXamlLanguageServerFeedbackService? feedbackService) : base(lspServiceProvider, jsonRpc, capabilitiesProvider, logger, hostServices, supportedLanguages, serverKind)
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, true)]
public XamlRequestExecutionQueueProvider(XamlProjectService projectService, IXamlLanguageServerFeedbackService? feedbackService)
{
_projectService = projectService;
_feedbackService = feedbackService;
}

protected override IRequestExecutionQueue<RequestContext> ConstructRequestExecutionQueue()
public IRequestExecutionQueue<RequestContext> CreateRequestExecutionQueue(AbstractLanguageServer<RequestContext> languageServer, ILspLogger logger, IHandlerProvider handlerProvider)
{
var queue = new XamlRequestExecutionQueue(_projectService, _feedbackService, this, _logger, GetHandlerProvider());
var queue = new XamlRequestExecutionQueue(_projectService, _feedbackService, languageServer, logger, handlerProvider);
queue.Start();
return queue;
}
Expand Down

0 comments on commit 1100e56

Please sign in to comment.