Skip to content

Commit

Permalink
Add feature flag to allow VS to use the LSP based editor
Browse files Browse the repository at this point in the history
  • Loading branch information
dibarbet committed Dec 16, 2020
1 parent cd142e9 commit a4d4605
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Notification;
using Roslyn.Utilities;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;

namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename
{
Expand Down Expand Up @@ -108,7 +109,8 @@ private static bool CanRename(RenameCommandArgs args)
{
return args.SubjectBuffer.TryGetWorkspace(out var workspace) &&
workspace.CanApplyChange(ApplyChangesKind.ChangeDocument) &&
args.SubjectBuffer.SupportsRename();
args.SubjectBuffer.SupportsRename() &&
!workspace.Services.GetService<IWorkspaceContextService>().IsInLspEditorContext();
}

private static void ShowErrorDialog(Workspace workspace, string message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ public bool TryGetTelemetryId(out Guid telemetryId)
return null;
}

if (range.Snapshot.TextBuffer.IsInLspEditorContext())
{
return null;
}

if (_workspaceStatusService != null)
{
using (operationContext?.AddScope(allowCancellation: true, description: EditorFeaturesWpfResources.Gathering_Suggestions_Waiting_for_the_solution_to_fully_load))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public static async Task ProduceTagsAsync(
IClassificationService classificationService,
ClassificationTypeMap typeMap)
{
if (spanToTag.SnapshotSpan.Snapshot.TextBuffer.IsInLspEditorContext())
{
return;
}

var document = spanToTag.Document;
if (document == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.Options;
Expand All @@ -27,6 +28,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.LanguageClient
[Export(typeof(AlwaysActivateInProcLanguageClient))]
internal class AlwaysActivateInProcLanguageClient : AbstractInProcLanguageClient
{
private readonly DefaultCapabilitiesProvider _defaultCapabilitiesProvider;
private readonly IGlobalOptionService _globalOptionService;

[ImportingConstructor]
Expand All @@ -36,27 +38,37 @@ public AlwaysActivateInProcLanguageClient(
LanguageServerProtocol languageServerProtocol,
VisualStudioWorkspace workspace,
IAsynchronousOperationListenerProvider listenerProvider,
ILspSolutionProvider solutionProvider)
ILspSolutionProvider solutionProvider,
DefaultCapabilitiesProvider defaultCapabilitiesProvider)
: base(languageServerProtocol, workspace, diagnosticService: null, listenerProvider, solutionProvider, diagnosticsClientName: null)
{
_globalOptionService = globalOptionService;
_defaultCapabilitiesProvider = defaultCapabilitiesProvider;
}

public override string Name
=> ServicesVSResources.CSharp_Visual_Basic_Language_Server_Client;

protected internal override VSServerCapabilities GetCapabilities()
=> new VSServerCapabilities
{
var serverCapabilities = new VSServerCapabilities();

// If the LSP editor feature flag is enabled advertise support for LSP features here so they are available locally and remote.
if (Workspace.Services.GetRequiredService<IExperimentationService>().IsExperimentEnabled(VisualStudioWorkspaceContextService.LspEditorFeatureFlagName))
{
serverCapabilities = _defaultCapabilitiesProvider.GetCapabilities();
}

serverCapabilities.TextDocumentSync = new TextDocumentSyncOptions
{
TextDocumentSync = new TextDocumentSyncOptions
{
Change = TextDocumentSyncKind.Incremental,
OpenClose = true,
},
SupportsDiagnosticRequests = this.Workspace.IsPullDiagnostics(InternalDiagnosticsOptions.NormalDiagnosticMode),
// This flag ensures that ctrl+, search locally uses the old editor APIs so that only ctrl+Q search is powered via LSP.
DisableGoToWorkspaceSymbols = true,
WorkspaceSymbolProvider = true,
Change = TextDocumentSyncKind.Incremental,
OpenClose = true,
};
serverCapabilities.SupportsDiagnosticRequests = this.Workspace.IsPullDiagnostics(InternalDiagnosticsOptions.NormalDiagnosticMode);
serverCapabilities.DisableGoToWorkspaceSymbols = true;
serverCapabilities.WorkspaceSymbolProvider = true;

return serverCapabilities;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.Shared.TestHooks;
Expand Down Expand Up @@ -42,6 +43,17 @@ public LiveShareInProcLanguageClient(
public override string Name => ServicesVSResources.Live_Share_CSharp_Visual_Basic_Language_Server_Client;

protected internal override VSServerCapabilities GetCapabilities()
=> _defaultCapabilitiesProvider.GetCapabilities();
{
var experimentationService = Workspace.Services.GetRequiredService<IExperimentationService>();
var isLspEditorEnabled = experimentationService.IsExperimentEnabled(VisualStudioWorkspaceContextService.LspEditorFeatureFlagName);
// If the preview feature flag to turn on the LSP editor in local scenarios is on, advertise no capabilities for this Live Share
// LSP server as LSP requests will be serviced by the AlwaysActiveInProcLanguageClient in both local and remote scenarios.
if (isLspEditorEnabled)
{
return new VSServerCapabilities();
}

return _defaultCapabilitiesProvider.GetCapabilities();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

using System;
using System.Composition;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.Shell;

Expand All @@ -13,14 +15,23 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation
[ExportWorkspaceService(typeof(IWorkspaceContextService), ServiceLayer.Host), Shared]
internal class VisualStudioWorkspaceContextService : IWorkspaceContextService
{
/// <summary>
/// Roslyn LSP feature flag name, as defined in the PackageRegistraion.pkgdef
/// by everything following '$RootKey$\FeatureFlags\' and '\' replaced by '.'
/// </summary>
public const string LspEditorFeatureFlagName = "Roslyn.LSP.Editor";

// UI context defined by Live Share when connected as a guest in a Live Share session
// https://devdiv.visualstudio.com/DevDiv/_git/Cascade?path=%2Fsrc%2FVS%2FContracts%2FGuidList.cs&version=GBmaster&line=32&lineEnd=33&lineStartColumn=1&lineEndColumn=1&lineStyle=plain&_a=contents
private static readonly Guid LiveShareGuestUIContextGuid = Guid.Parse("fd93f3eb-60da-49cd-af15-acda729e357e");

private readonly Workspace _workspace;

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VisualStudioWorkspaceContextService()
public VisualStudioWorkspaceContextService(VisualStudioWorkspace vsWorkspace)
{
_workspace = vsWorkspace;
}

public bool IsCloudEnvironmentClient()
Expand All @@ -31,7 +42,9 @@ public bool IsCloudEnvironmentClient()

public bool IsInLspEditorContext()
{
return IsLiveShareGuest() || IsCloudEnvironmentClient();
var featureFlagService = _workspace.Services.GetRequiredService<IExperimentationService>();
var isInLspContext = IsLiveShareGuest() || IsCloudEnvironmentClient() || featureFlagService.IsExperimentEnabled(LspEditorFeatureFlagName);
return isInLspContext;
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/VisualStudio/Core/Def/PackageRegistration.pkgdef
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@
"CS"="CA719A03-D55C-48F9-85DE-D934346E7F70"
"VB"="EEC3DF0D-6D3F-4544-ABF9-8E26E6A90275"

[$RootKey$\FeatureFlags\Roslyn\LSP\Editor]
"Description"="Enables the LSP powered C#/VB editing experience outside of CodeSpaces."
"Value"=dword:00000000
"Title"="Enable experimental C#/VB editor (requires restart)"
"PreviewPaneChannels"="Preview,int.main"

0 comments on commit a4d4605

Please sign in to comment.