Skip to content

Commit

Permalink
Merge pull request #71416 from davidwengier/DoLessIfCohostIsOff
Browse files Browse the repository at this point in the history
Don't start the cohost server at all if Razor doesn't want to
  • Loading branch information
davidwengier authored Jan 3, 2024
2 parents d893498 + 574ff33 commit 80310d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected virtual void Activate_OffUIThread()
/// Signals that the extension has been loaded. The server can be started immediately, or wait for user action to start.
/// To start the server, invoke the <see cref="StartAsync"/> event;
/// </summary>
public async Task OnLoadedAsync()
public virtual async Task OnLoadedAsync()
{
try
{
Expand Down
19 changes: 11 additions & 8 deletions src/Tools/ExternalAccess/Razor/Cohost/RazorCohostLanguageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Implementation.LanguageClient;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
Expand Down Expand Up @@ -42,18 +43,20 @@ internal sealed class RazorCohostLanguageClient(

public override object? CustomMessageTarget => razorCustomMessageTarget;

public override ServerCapabilities GetCapabilities(ClientCapabilities clientCapabilities)
public override Task OnLoadedAsync()
{
if (razorCohostLanguageClientActivationService?.ShouldActivateCohostServer() != true)
{
// A default return would still opt us in to TextDocumentSync for open files, but even that's
// wasteful if we don't want to handle anything, as we'd track document content.
return new()
{
TextDocumentSync = new TextDocumentSyncOptions { OpenClose = false, Change = TextDocumentSyncKind.None, Save = false, WillSave = false, WillSaveWaitUntil = false }
};
// By not calling the base implementation, we avoid firing the StartAsync event, which means
// the platform will never trigger the creation of an instance of the language server.
return Task.CompletedTask;
}

return base.OnLoadedAsync();
}

public override ServerCapabilities GetCapabilities(ClientCapabilities clientCapabilities)
{
Contract.ThrowIfNull(razorCapabilitiesProvider);

// We use a string to pass capabilities to/from Razor to avoid version issues with the Protocol DLL
Expand All @@ -76,7 +79,7 @@ public override ServerCapabilities GetCapabilities(ClientCapabilities clientCapa
/// <summary>
/// If the cohost server is expected to activate then any failures are catastrophic as no razor features will work.
/// </summary>
public override bool ShowNotificationOnInitializeFailed => razorCohostLanguageClientActivationService?.ShouldActivateCohostServer() == true;
public override bool ShowNotificationOnInitializeFailed => true;

public override WellKnownLspServerKinds ServerKind => WellKnownLspServerKinds.RazorCohostServer;
}

0 comments on commit 80310d6

Please sign in to comment.